diff options
| author | ruki <[email protected]> | 2023-09-20 15:57:02 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-20 15:57:02 +0800 |
| commit | 812e501ca76e6d6faab2a3b5161d9ce2550e6008 (patch) | |
| tree | 86834b162074e6edbc86e5cc6173090e53c0751f | |
| parent | ce47deadcac8a8fcd7456a0ecc1eca0d935a9ed9 (diff) | |
| parent | 7669723d2a718fa78da171b68561175eb7ce435f (diff) | |
Merge pull request #4221 from xmake-io/cargo
improve to install and find cargo packages #4214
| -rw-r--r-- | xmake/modules/package/manager/cargo/find_package.lua | 29 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cargo/install_package.lua | 22 |
2 files changed, 28 insertions, 23 deletions
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua index 58064d9a9..b75182cec 100644 --- a/xmake/modules/package/manager/cargo/find_package.lua +++ b/xmake/modules/package/manager/cargo/find_package.lua @@ -87,31 +87,14 @@ end function _get_names_of_libraries(name, opt) local configs = opt.configs or {} local names = hashset.new() - if configs.cargo_toml then - local cargo = assert(find_tool("cargo"), "cargo not found!") - local cargo_args = {"metadata", "--format-version", "1", "--manifest-path", configs.cargo_toml, "--color", "never"} - local target = check_target(opt.arch, true) and opt.arch or nil - if target then - table.insert(cargo_args, "--filter-platform") - table.insert(cargo_args, target) - end - if configs.features then - table.insert(cargo_args, "--features") - table.insert(cargo_args, table.concat(configs.features, ",")) - end - if configs.default_features == false then - table.insert(cargo_args, "--no-default-features") - end - - local output = os.iorunv(cargo.program, cargo_args) - local metadata = json.decode(output) + local metadata_file = path.join(opt.installdir, "metadata.txt") + if configs.cargo_toml and os.isfile(metadata_file) then + local fileinfo = io.load(metadata_file) + local metadata = json.decode(fileinfo.metadata) + local metadata_without_deps = json.decode(fileinfo.metadata_without_deps) - -- fetch the direct dependencies list regradless of the target platform - table.insert(cargo_args, "--no-deps") - output = os.iorunv(cargo.program, cargo_args) - local metadata_no_deps = json.decode(output) -- FIXME: should consider the case of multiple packages in a workspace! - local direct_deps = metadata_no_deps.packages[1].dependencies + local direct_deps = metadata_without_deps.packages[1].dependencies -- get the intersection of the direct dependencies and all dependencies for the target platform for _, dep in ipairs(direct_deps) do diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua index 9daa665cd..c7649ccde 100644 --- a/xmake/modules/package/manager/cargo/install_package.lua +++ b/xmake/modules/package/manager/cargo/install_package.lua @@ -143,4 +143,26 @@ target = "%s" else os.vcp(path.join(sourcedir, "target", opt.mode == "debug" and "debug" or "release", "deps"), path.join(installdir, "lib")) end + + -- install metadata + argv = {"metadata", "--format-version", "1", "--manifest-path", cargotoml, "--color", "never"} + if target then + table.insert(argv, "--filter-platform") + table.insert(argv, target) + end + if configs.features then + table.insert(argv, "--features") + table.insert(argv, table.concat(configs.features, ",")) + end + if configs.default_features == false then + table.insert(argv, "--no-default-features") + end + + local metadata = os.iorunv(cargo.program, argv, {curdir = sourcedir}) + + -- fetch the direct dependencies list regradless of the target platform + table.insert(argv, "--no-deps") + local metadata_without_deps = os.iorunv(cargo.program, argv, {curdir = sourcedir}) + + io.save(path.join(installdir, "metadata.txt"), {metadata = metadata, metadata_without_deps = metadata_without_deps}) end |
