diff options
| author | ruki <[email protected]> | 2024-05-29 20:04:12 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-29 20:04:12 +0800 |
| commit | 5767107d1e7f66288e9b7eebd4272ba443cbffa0 (patch) | |
| tree | 03148059821270bc7f183057a20829e427b1cc20 | |
| parent | baeddec39147f5143ef838a2798483cd3653bc04 (diff) | |
| parent | 627ba35bef243770009c5a5b57c980204a9ef1d4 (diff) | |
Merge pull request #5164 from xmake-io/rust
add target to rcflags
| -rw-r--r-- | xmake/modules/package/manager/cargo/install_package.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/rust/xmake.lua | 17 | ||||
| -rw-r--r-- | xmake/toolchains/rust/xmake.lua | 1 |
3 files changed, 25 insertions, 1 deletions
diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua index 7c9844c29..97fd1a07e 100644 --- a/xmake/modules/package/manager/cargo/install_package.lua +++ b/xmake/modules/package/manager/cargo/install_package.lua @@ -92,11 +92,17 @@ function main(name, opt) -- https://github.com/rust-lang/cargo/issues/10534#issuecomment-1087631050 local tomlfile = io.open(cargotoml, "a") tomlfile:print("") + tomlfile:print("[lib]") + tomlfile:print("crate-type = [\"staticlib\"]") + tomlfile:print("") tomlfile:print("[workspace]") tomlfile:print("") tomlfile:close() else local tomlfile = io.open(cargotoml, "w") + tomlfile:print("[lib]") + tomlfile:print("crate-type = [\"staticlib\"]") + tomlfile:print("") tomlfile:print("[package]") tomlfile:print("name = \"cargodeps\"") tomlfile:print("version = \"0.1.0\"") @@ -125,7 +131,7 @@ target = "%s" end -- generate main.rs - local file = io.open(path.join(sourcedir, "src", "main.rs"), "w") + local file = io.open(path.join(sourcedir, "src", "lib.rs"), "w") if configs.main == false then file:print("#![no_main]") end diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua index 2e9295cfd..63c194ced 100644 --- a/xmake/rules/rust/xmake.lua +++ b/xmake/rules/rust/xmake.lua @@ -61,6 +61,23 @@ rule("rust.build") -- set edition local edition = target:values("rust.edition") or "2018" target:add("rcflags", "--edition", edition, {force = true}) + + -- set abort panic for no_std + -- https://github.com/xmake-io/xmake/issues/4929 + local no_std = false + local sourcebatch = target:sourcebatches()["rust.build"] + if sourcebatch then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local content = io.readfile(sourcefile) + if content and content:find("#![no_std]", 1, true) then + no_std = true + break + end + end + end + if no_std then + target:add("rcflags", "-C panic=abort", {force = true}) + end end) on_build("build.target") diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua index 210e1b727..1b524ae20 100644 --- a/xmake/toolchains/rust/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -45,6 +45,7 @@ toolchain("rust") end end if arch and #arch:split("%-") > 1 then + toolchain:add("rcflags", "--target=" .. arch) toolchain:add("rcshflags", "--target=" .. arch) toolchain:add("rcldflags", "--target=" .. arch) else |
