diff options
| author | IMXEren <[email protected]> | 2025-07-06 03:48:09 +0530 |
|---|---|---|
| committer | IMXEren <[email protected]> | 2025-07-06 05:00:58 +0530 |
| commit | 207f0a10dc931ffc744a8e50eab00004c5d5da5e (patch) | |
| tree | 74a73d2a1e11823e0bc0db4aac8b4b2519e5ec46 | |
| parent | 8d08f0cc65c7d998265e247660ebf19bc1ba0caa (diff) | |
feat(template): add rust shared library template
- built using -C prefer-dynamic hence, requires libstd-*.[so|dll|dylib]
add DYLD_LIBRARY_PATH to search libstd
| -rw-r--r-- | xmake/templates/rust/shared/project/src/foo.rs | 4 | ||||
| -rw-r--r-- | xmake/templates/rust/shared/project/src/main.rs | 6 | ||||
| -rw-r--r-- | xmake/templates/rust/shared/project/xmake.lua | 18 | ||||
| -rw-r--r-- | xmake/templates/rust/shared/template.lua | 2 |
4 files changed, 30 insertions, 0 deletions
diff --git a/xmake/templates/rust/shared/project/src/foo.rs b/xmake/templates/rust/shared/project/src/foo.rs new file mode 100644 index 000000000..a3a3aa4a6 --- /dev/null +++ b/xmake/templates/rust/shared/project/src/foo.rs @@ -0,0 +1,4 @@ +pub fn add(a: i32, b: i32) -> i32 { + return a + b; +} + diff --git a/xmake/templates/rust/shared/project/src/main.rs b/xmake/templates/rust/shared/project/src/main.rs new file mode 100644 index 000000000..205d23da3 --- /dev/null +++ b/xmake/templates/rust/shared/project/src/main.rs @@ -0,0 +1,6 @@ +extern crate foo; + +fn main() { + println!("hello xmake!"); + println!("add: {}", foo::add(1, 1)); +} diff --git a/xmake/templates/rust/shared/project/xmake.lua b/xmake/templates/rust/shared/project/xmake.lua new file mode 100644 index 000000000..12b177466 --- /dev/null +++ b/xmake/templates/rust/shared/project/xmake.lua @@ -0,0 +1,18 @@ +target("foo") + set_kind("shared") + add_files("src/foo.rs") + +target("${TARGETNAME}_demo") + set_kind("binary") + add_deps("foo") + add_files("src/main.rs") + + --- Make sure libstd shared library is available + before_run(function (target) + local outdata, errdata = os.iorun("rustc --print=sysroot") + assert(not errdata or errdata == "", "failed to find rust sysroot:\n" .. errdata) + local libstd = path.join(outdata:trim(), "bin") + os.addenvs({PATH = libstd, LD_LIBRARY_PATH = libstd, DYLD_LIBRARY_PATH = libstd}) + end) + +${FAQ} diff --git a/xmake/templates/rust/shared/template.lua b/xmake/templates/rust/shared/template.lua new file mode 100644 index 000000000..d7ec5bae4 --- /dev/null +++ b/xmake/templates/rust/shared/template.lua @@ -0,0 +1,2 @@ +template("shared") + add_configfiles("xmake.lua") |
