summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-13 13:46:36 +0800
committerruki <[email protected]>2021-11-13 13:46:36 +0800
commit6b684d5cc448124c31a51fff71e4043667677a57 (patch)
tree8ea5f63bf177eaad1e1d00d4f8533ac6dcd61cc3
parent8907c57014dedbd68da377cb25a92096c0c713d8 (diff)
add frameworks for rust
-rw-r--r--tests/projects/rust/cxx_call_rust_library/xmake.lua1
-rw-r--r--xmake/languages/rust/xmake.lua14
-rw-r--r--xmake/modules/core/tools/rustc.lua9
-rw-r--r--xmake/modules/package/manager/cargo/find_package.lua6
-rw-r--r--xmake/rules/rust/xmake.lua1
-rw-r--r--xmake/rules/utils/inherit_links/inherit_links.lua12
6 files changed, 36 insertions, 7 deletions
diff --git a/tests/projects/rust/cxx_call_rust_library/xmake.lua b/tests/projects/rust/cxx_call_rust_library/xmake.lua
index 30d54cc02..cafd349ee 100644
--- a/tests/projects/rust/cxx_call_rust_library/xmake.lua
+++ b/tests/projects/rust/cxx_call_rust_library/xmake.lua
@@ -7,6 +7,7 @@ target("foo")
add_files("src/foo.rs")
set_values("rust.cratetype", "staticlib")
add_packages("cargo::cxx")
+ add_rcflags("--edition=2018")
target("test")
set_kind("binary")
diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua
index b07617a61..1335225e3 100644
--- a/xmake/languages/rust/xmake.lua
+++ b/xmake/languages/rust/xmake.lua
@@ -45,6 +45,9 @@ language("rust")
, "target.symbols"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
+ , "config.frameworks"
+ , "target.frameworks"
+ , "toolchain.frameworks"
, "config.links"
, "target.links"
, "toolchain.links"
@@ -60,6 +63,9 @@ language("rust")
, "target.symbols"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
+ , "config.frameworks"
+ , "target.frameworks"
+ , "toolchain.frameworks"
, "config.links"
, "target.links"
, "toolchain.links"
@@ -68,8 +74,14 @@ language("rust")
, "toolchain.syslinks"
}
, static = {
- "target.strip"
+ "config.linkdirs"
+ , "target.linkdirs"
+ , "target.strip"
, "target.symbols"
+ , "toolchain.linkdirs"
+ , "config.frameworks"
+ , "target.frameworks"
+ , "toolchain.frameworks"
}
}
diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua
index fa358e897..19588136a 100644
--- a/xmake/modules/core/tools/rustc.lua
+++ b/xmake/modules/core/tools/rustc.lua
@@ -65,6 +65,15 @@ function nf_syslink(self, lib)
return nf_link(self, lib)
end
+-- make the framework flag, crate module
+function nf_framework(self, framework)
+ local basename = path.basename(framework)
+ local cratename = basename:match("lib(.-)%-.-") or basename:match("lib(.-)")
+ if cratename then
+ return {"--extern", cratename .. "=" .. framework}
+ end
+end
+
-- make the rpathdir flag
function nf_rpathdir(self, dir)
dir = path.translate(dir)
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua
index 336b4243a..cc546704e 100644
--- a/xmake/modules/package/manager/cargo/find_package.lua
+++ b/xmake/modules/package/manager/cargo/find_package.lua
@@ -33,21 +33,25 @@ import("lib.detect.find_file")
--
function main(name, opt)
local linkdirs
+ local frameworks
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 {}
+ frameworks = frameworks or {}
table.insert(linkdirs, librarydir)
+ table.insert(frameworks, libraryfile)
break
end
end
local result
- if linkdirs then
+ if frameworks and linkdirs then
result = result or {}
result.libfiles = libfiles
result.linkdirs = linkdirs
+ result.frameworks = frameworks
result.version = opt.require_version
end
return result
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua
index e0952b72e..f371692e1 100644
--- a/xmake/rules/rust/xmake.lua
+++ b/xmake/rules/rust/xmake.lua
@@ -36,6 +36,7 @@ rule("rust.build")
if cratetype == "staticlib" then
assert(target:is_static(), "target(%s) must be static kind for cratetype(staticlib)!", target:name())
target:add("arflags", "--crate-type=staticlib")
+ target:data_set("inherit.links.exportlinks", false)
elseif cratetype == "cdylib" then
assert(target:is_shared(), "target(%s) must be shared kind for cratetype(cdylib)!", target:name())
target:add("shflags", "--crate-type=cdylib")
diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua
index 805f535d8..79c737503 100644
--- a/xmake/rules/utils/inherit_links/inherit_links.lua
+++ b/xmake/rules/utils/inherit_links/inherit_links.lua
@@ -80,11 +80,13 @@ function main(target)
-- @note we only export links for static target,
-- and we need pass `{public = true}` to add_packages/add_links/... to export it if want to export links for shared target
--
- if targetkind == "static" then
- for _, name in ipairs({"rpathdirs", "frameworkdirs", "frameworks", "linkdirs", "links", "syslinks"}) do
- local values = _get_values_from_target(target, name)
- if values and #values > 0 then
- target:add(name, values, {public = true})
+ if target:data("inherit.links.exportlinks") ~= false then
+ if targetkind == "static" then
+ for _, name in ipairs({"rpathdirs", "frameworkdirs", "frameworks", "linkdirs", "links", "syslinks"}) do
+ local values = _get_values_from_target(target, name)
+ if values and #values > 0 then
+ target:add(name, values, {public = true})
+ end
end
end
end