summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-13 13:52:57 +0800
committerruki <[email protected]>2021-11-13 13:52:57 +0800
commit80326fdfb7fa838d3dc79aa24c9dcc01519b173b (patch)
tree0c2461c8dc9ec446af28274983e11fe508cef200
parent6b684d5cc448124c31a51fff71e4043667677a57 (diff)
add edition for rust
-rw-r--r--tests/projects/rust/cxx_call_rust_library/xmake.lua1
-rw-r--r--xmake/languages/rust/xmake.lua9
-rw-r--r--xmake/modules/core/tools/rustc.lua5
-rw-r--r--xmake/modules/package/manager/cargo/find_package.lua10
-rw-r--r--xmake/rules/rust/xmake.lua5
5 files changed, 24 insertions, 6 deletions
diff --git a/tests/projects/rust/cxx_call_rust_library/xmake.lua b/tests/projects/rust/cxx_call_rust_library/xmake.lua
index cafd349ee..30d54cc02 100644
--- a/tests/projects/rust/cxx_call_rust_library/xmake.lua
+++ b/tests/projects/rust/cxx_call_rust_library/xmake.lua
@@ -7,7 +7,6 @@ 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 1335225e3..ea71910b7 100644
--- a/xmake/languages/rust/xmake.lua
+++ b/xmake/languages/rust/xmake.lua
@@ -39,11 +39,14 @@ language("rust")
}
, binary = {
"config.linkdirs"
+ , "config.frameworkdirs"
, "target.linkdirs"
+ , "target.frameworkdirs"
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
, "toolchain.linkdirs"
+ , "toolchain.frameworkdirs"
, "toolchain.rpathdirs"
, "config.frameworks"
, "target.frameworks"
@@ -57,11 +60,14 @@ language("rust")
}
, shared = {
"config.linkdirs"
+ , "config.frameworkdirs"
, "target.linkdirs"
+ , "target.frameworkdirs"
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
, "toolchain.linkdirs"
+ , "toolchain.frameworkdirs"
, "toolchain.rpathdirs"
, "config.frameworks"
, "target.frameworks"
@@ -75,10 +81,13 @@ language("rust")
}
, static = {
"config.linkdirs"
+ , "config.frameworkdirs"
, "target.linkdirs"
+ , "target.frameworkdirs"
, "target.strip"
, "target.symbols"
, "toolchain.linkdirs"
+ , "toolchain.frameworkdirs"
, "config.frameworks"
, "target.frameworks"
, "toolchain.frameworks"
diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua
index 19588136a..ab41620cd 100644
--- a/xmake/modules/core/tools/rustc.lua
+++ b/xmake/modules/core/tools/rustc.lua
@@ -65,6 +65,11 @@ function nf_syslink(self, lib)
return nf_link(self, lib)
end
+-- make the frameworkdir flag, crate module dependency directories
+function nf_frameworkdir(self, frameworkdir)
+ return {"-L", "dependency=" .. frameworkdir}
+end
+
-- make the framework flag, crate module
function nf_framework(self, framework)
local basename = path.basename(framework)
diff --git a/xmake/modules/package/manager/cargo/find_package.lua b/xmake/modules/package/manager/cargo/find_package.lua
index cc546704e..7fd151d5c 100644
--- a/xmake/modules/package/manager/cargo/find_package.lua
+++ b/xmake/modules/package/manager/cargo/find_package.lua
@@ -32,25 +32,25 @@ 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 frameworkdirs
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 {}
+ frameworkdirs = frameworkdirs or {}
frameworks = frameworks or {}
- table.insert(linkdirs, librarydir)
+ table.insert(frameworkdirs, librarydir)
table.insert(frameworks, libraryfile)
break
end
end
local result
- if frameworks and linkdirs then
+ if frameworks and frameworkdirs then
result = result or {}
result.libfiles = libfiles
- result.linkdirs = linkdirs
+ result.frameworkdirs = frameworkdirs
result.frameworks = frameworks
result.version = opt.require_version
end
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua
index f371692e1..e31e2f046 100644
--- a/xmake/rules/rust/xmake.lua
+++ b/xmake/rules/rust/xmake.lua
@@ -32,6 +32,7 @@ rule("rust.cxxbridge")
rule("rust.build")
set_sourcekinds("rc")
on_load(function (target)
+ -- set cratetype
local cratetype = target:values("rust.cratetype")
if cratetype == "staticlib" then
assert(target:is_static(), "target(%s) must be static kind for cratetype(staticlib)!", target:name())
@@ -56,6 +57,10 @@ rule("rust.build")
elseif target:is_binary() then
target:add("ldflags", "--crate-type=bin")
end
+
+ -- set edition
+ local edition = target:values("rust.edition") or "2018"
+ target:add("rcflags", "--edition", edition, {force = true})
end)
on_build("build.target")