summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorw568w <[email protected]>2023-08-09 11:11:10 +0800
committerw568w <[email protected]>2023-08-09 11:11:10 +0800
commit75e74ab6f8c89bc4d82cd23b05416141ea6d28c4 (patch)
treeaa76331d206e70ef82aabcd30f7f44dc10883065 /xmake/modules
parentb156158b59dd2ed5cd825d6ac98b5222c75d19fd (diff)
parent3ba512001d7785b81e6f4e3b72ffbcf11973c3d7 (diff)
Merge branch 'rust' of github.com:w568w/xmake into rust
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/package/manager/cargo/find_package.lua27
1 files changed, 12 insertions, 15 deletions
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua
index 0dcb835bb..82d6f6bdb 100644
--- a/xmake/modules/package/manager/cargo/find_package.lua
+++ b/xmake/modules/package/manager/cargo/find_package.lua
@@ -83,24 +83,15 @@ function _get_libname(name)
return "lib" .. name:gsub("-", "_")
end
-function _get_package_from_deps(name, deps)
- for _, dep in ipairs(deps) do
- if dep.name == name then
- return dep
- end
- end
- return nil
-end
-
-- get the name set of libraries
-function _get_names_of_libraries(name, opt, configs)
+function _get_names_of_libraries(name, target, configs)
local names = hashset.new()
if configs.cargo_toml then
local cargo = assert(find_tool("cargo"), "cargo not found! Please ensure Rust has been installed")
local cargo_args = {"metadata", "--format-version", "1", "--manifest-path", configs.cargo_toml, "--color", "never"}
- if check_target(opt.arch, true) then
+ if check_target(target, true) then
table.insert(cargo_args, "--filter-platform")
- table.insert(cargo_args, opt.arch)
+ table.insert(cargo_args, target)
end
if configs.features then
table.insert(cargo_args, "--features")
@@ -112,7 +103,7 @@ function _get_names_of_libraries(name, opt, configs)
local output = os.iorunv(cargo.program, cargo_args)
local metadata = json.decode(output)
-
+
-- fetch the direct dependencies list regradless of the target platform
table.insert(cargo_args, "--no-deps")
output = os.iorunv(cargo.program, cargo_args)
@@ -122,7 +113,13 @@ function _get_names_of_libraries(name, opt, configs)
-- get the intersection of the direct dependencies and all dependencies for the target platform
for _, dep in ipairs(direct_deps) do
- local dep_metadata = _get_package_from_deps(dep.name, metadata.packages)
+ local dep_metadata
+ for _, pkg in ipairs(metadata.packages) do
+ if pkg.name == dep.name then
+ dep_metadata = pkg
+ break
+ end
+ end
if dep_metadata then
names:insert(_get_libname(dep.name))
end
@@ -145,7 +142,7 @@ function main(name, opt)
local configs = opt.configs or {}
-- get names of libraries
- local names = _get_names_of_libraries(name, opt, configs)
+ local names = _get_names_of_libraries(name, opt.arch, configs)
assert(not names:empty())
local frameworkdirs