summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-09 11:06:10 +0800
committerGitHub <[email protected]>2023-08-09 11:06:10 +0800
commit3ba512001d7785b81e6f4e3b72ffbcf11973c3d7 (patch)
treea1e48633e26d4b0259e32ec5d67d3447570a2129
parent0b82a790bad9538e09102afc31fc29c1e9bac826 (diff)
Update find_package.lua
-rw-r--r--xmake/modules/package/manager/cargo/find_package.lua33
1 files changed, 20 insertions, 13 deletions
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua
index b01ce53f2..801f266c6 100644
--- a/xmake/modules/package/manager/cargo/find_package.lua
+++ b/xmake/modules/package/manager/cargo/find_package.lua
@@ -83,14 +83,14 @@ function _get_libname(name)
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 opt.arch then
+ if target 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")
@@ -102,7 +102,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)
@@ -111,16 +111,14 @@ function _get_names_of_libraries(name, opt, configs)
local direct_deps = metadata_no_deps.packages[1].dependencies
-- get the intersection of the direct dependencies and all dependencies for the target platform
- local function _get_deps(name, deps)
- for _, dep in ipairs(deps) do
- if dep.name == name then
- return dep
+ for _, dep in ipairs(direct_deps) do
+ local dep_metadata
+ for _, pkg in ipairs(metadata.packages) do
+ if pkg.name == dep.name then
+ dep_metadata = pkg
+ break
end
end
- return nil
- end
- for _, dep in ipairs(direct_deps) do
- local dep_metadata = _get_deps(dep.name, metadata.packages)
if dep_metadata then
names:insert(_get_libname(dep.name))
end
@@ -142,8 +140,17 @@ function main(name, opt)
opt = opt or {}
local configs = opt.configs or {}
+ -- get target
+ -- e.g. x86_64-pc-windows-msvc, aarch64-unknown-none
+ -- @see https://github.com/xmake-io/xmake/issues/4049
+ local target
+ local arch = opt.arch
+ if arch and #arch:split("%-") > 1 then
+ target = arch
+ end
+
-- get names of libraries
- local names = _get_names_of_libraries(name, opt, configs)
+ local names = _get_names_of_libraries(name, target, configs)
assert(not names:empty())
local frameworkdirs