diff options
Diffstat (limited to 'xmake/rules/rust/xmake.lua')
| -rw-r--r-- | xmake/rules/rust/xmake.lua | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua index b3599e43b..e0952b72e 100644 --- a/xmake/rules/rust/xmake.lua +++ b/xmake/rules/rust/xmake.lua @@ -22,15 +22,28 @@ -- @see https://cxx.rs/build/other.html rule("rust.cxxbridge") set_extensions(".rsx") + on_load(function (target) + if not target:get("languages") then + target:set("languages", "c++11") + end + end) before_buildcmd_file("build.cxxbridge") --- define rule: rust.build rule("rust.build") set_sourcekinds("rc") on_load(function (target) - if target:is_static() then + 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()) + target:add("arflags", "--crate-type=staticlib") + 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") + target:add("shflags", "-C prefer-dynamic") + elseif target:is_static() then target:set("extension", ".rlib") target:add("arflags", "--crate-type=lib") + target:data_set("inherit.links.deplink", false) elseif target:is_shared() then target:add("shflags", "--crate-type=dylib") -- fix cannot satisfy dependencies so `std` only shows up once @@ -42,15 +55,9 @@ rule("rust.build") elseif target:is_binary() then target:add("ldflags", "--crate-type=bin") end - target:data_set("inherit.links.deplink", false) end) on_build("build.target") --- define rule: rust rule("rust") - - -- add build rules add_deps("rust.build") - - -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") |
