summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-13 13:23:21 +0800
committerruki <[email protected]>2021-11-13 13:23:21 +0800
commit8907c57014dedbd68da377cb25a92096c0c713d8 (patch)
tree07394e7ab879c840203343fc0914163463c258d8
parentdaef54e8a91ae742e18057756fcaa7548bc83930 (diff)
add find_package for cargo
-rw-r--r--tests/projects/rust/cargo_deps/src/main.rs1
-rw-r--r--tests/projects/rust/cxx_call_rust_library/xmake.lua3
-rw-r--r--xmake/modules/package/manager/cargo/find_package.lua19
3 files changed, 23 insertions, 0 deletions
diff --git a/tests/projects/rust/cargo_deps/src/main.rs b/tests/projects/rust/cargo_deps/src/main.rs
index 92a120ec9..f1ec987bf 100644
--- a/tests/projects/rust/cargo_deps/src/main.rs
+++ b/tests/projects/rust/cargo_deps/src/main.rs
@@ -8,4 +8,5 @@ fn main() {
assert_eq!(encode(a), b);
assert_eq!(a, &decode(b).unwrap()[..]);
+ println!("{}", encode(a));
}
diff --git a/tests/projects/rust/cxx_call_rust_library/xmake.lua b/tests/projects/rust/cxx_call_rust_library/xmake.lua
index fb3a48171..30d54cc02 100644
--- a/tests/projects/rust/cxx_call_rust_library/xmake.lua
+++ b/tests/projects/rust/cxx_call_rust_library/xmake.lua
@@ -1,9 +1,12 @@
add_rules("mode.debug", "mode.release")
+add_requires("cargo::cxx 1.0")
+
target("foo")
set_kind("static")
add_files("src/foo.rs")
set_values("rust.cratetype", "staticlib")
+ add_packages("cargo::cxx")
target("test")
set_kind("binary")
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua
index 8ed72efec..336b4243a 100644
--- a/xmake/modules/package/manager/cargo/find_package.lua
+++ b/xmake/modules/package/manager/cargo/find_package.lua
@@ -32,4 +32,23 @@ import("lib.detect.find_file")
-- @param opt the options, e.g. {verbose = true, require_version = "1.12.x")
--
function main(name, opt)
+ local linkdirs
+ local librarydir = path.join(opt.installdir, "lib")
+ local libfiles = os.files(path.join(librarydir, "*.rlib"))
+ for _, libraryfile in ipairs(libfiles) do
+ local filename = path.filename(libraryfile)
+ if filename:startswith("lib" .. name .. "-") then
+ linkdirs = linkdirs or {}
+ table.insert(linkdirs, librarydir)
+ break
+ end
+ end
+ local result
+ if linkdirs then
+ result = result or {}
+ result.libfiles = libfiles
+ result.linkdirs = linkdirs
+ result.version = opt.require_version
+ end
+ return result
end