summaryrefslogtreecommitdiff
path: root/xmake/modules/package/manager
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-08 23:46:13 +0800
committerruki <[email protected]>2023-08-08 23:46:13 +0800
commit1494182a09187cf49edc9a19badc3be287e8a327 (patch)
tree813eca4bc9baf33b3f305cce48c408612c4784e1 /xmake/modules/package/manager
parent75e7ddd9d604fc4c762dbc0e187c4a0d0ae231cc (diff)
improve rust deps to support cross build
Diffstat (limited to 'xmake/modules/package/manager')
-rw-r--r--xmake/modules/package/manager/cargo/configurations.lua9
-rw-r--r--xmake/modules/package/manager/cargo/install_package.lua42
2 files changed, 42 insertions, 9 deletions
diff --git a/xmake/modules/package/manager/cargo/configurations.lua b/xmake/modules/package/manager/cargo/configurations.lua
index 9a8b7f89f..a233e7ccf 100644
--- a/xmake/modules/package/manager/cargo/configurations.lua
+++ b/xmake/modules/package/manager/cargo/configurations.lua
@@ -22,8 +22,11 @@
function main()
return
{
- features = {description = "set the features of dependency."},
- default_features = {description = "enables or disables any defaults provided by the dependency.", default = true},
- cargo_toml = {description = "set Cargo.toml file path"}
+ features = {description = "Set the features of dependency."},
+ default_features = {description = "Enable or disable any defaults provided by the dependency.", default = true},
+ std = {description = "Enable or disable std module."},
+ main = {description = "Enable or disable main entry function."},
+ build_target = {description = "Set build target. e.g. aarch64-unknown-none"},
+ cargo_toml = {description = "Set Cargo.toml file path"}
}
end
diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua
index 23955b1cc..5bc28498b 100644
--- a/xmake/modules/package/manager/cargo/install_package.lua
+++ b/xmake/modules/package/manager/cargo/install_package.lua
@@ -86,12 +86,38 @@ function main(name, opt)
tomlfile:close()
end
+ -- generate .cargo/config.toml
+ local configtoml = path.join(sourcedir, ".cargo", "config.toml")
+ if configs.build_target then
+ io.writefile(configtoml, format([[
+[build]
+target = "%s"
+]], configs.build_target))
+ end
+
-- generate main.rs
- io.writefile(path.join(sourcedir, "src", "main.rs"), [[
-fn main() {
- println!("Hello, world!");
-}
- ]])
+ local file = io.open(path.join(sourcedir, "src", "main.rs"), "w")
+ if configs.main == false then
+ file:print("#![no_main]")
+ end
+ if configs.std == false then
+ file:print("#![no_std]")
+ end
+ if configs.main == false then
+ file:print([[
+ use core::panic::PanicInfo;
+
+ #[panic_handler]
+ fn panic(_panic: &PanicInfo<'_>) -> ! {
+ loop {}
+ }]])
+ else
+ file:print([[
+ fn main() {
+ println!("Hello, world!");
+ }]])
+ end
+ file:close()
-- do build
local argv = {"build"}
@@ -106,5 +132,9 @@ fn main() {
-- do install
local installdir = opt.installdir
os.tryrm(path.join(installdir, "lib"))
- os.vcp(path.join(sourcedir, "target", opt.mode == "debug" and "debug" or "release", "deps"), path.join(installdir, "lib"))
+ if configs.build_target then
+ os.vcp(path.join(sourcedir, "target", configs.build_target, opt.mode == "debug" and "debug" or "release", "deps"), path.join(installdir, "lib"))
+ else
+ os.vcp(path.join(sourcedir, "target", opt.mode == "debug" and "debug" or "release", "deps"), path.join(installdir, "lib"))
+ end
end