diff options
| author | ruki <[email protected]> | 2021-11-10 23:05:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-11-10 23:05:38 +0800 |
| commit | bc404bc6481de0c934aa5ff4523924688b72a2d4 (patch) | |
| tree | 13d21c0ca6bd6881ae110809e815d37665c4fd88 /xmake/rules | |
| parent | b6ed301feb4b223a8c0faa9dd979a722b6e04555 (diff) | |
fix rpath for rust
Diffstat (limited to 'xmake/rules')
| -rw-r--r-- | xmake/rules/rust/xmake.lua | 17 | ||||
| -rw-r--r-- | xmake/rules/utils/inherit_links/inherit_links.lua | 16 |
2 files changed, 26 insertions, 7 deletions
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua index a8ccae429..b823ef753 100644 --- a/xmake/rules/rust/xmake.lua +++ b/xmake/rules/rust/xmake.lua @@ -21,6 +21,23 @@ -- define rule: rust.build rule("rust.build") set_sourcekinds("rc") + on_load(function (target) + if target:is_static() then + target:set("extension", ".rlib") + target:add("arflags", "--crate-type=lib") + elseif target:is_shared() then + target:add("shflags", "--crate-type=dylib") + -- fix cannot satisfy dependencies so `std` only shows up once + -- https://github.com/rust-lang/rust/issues/19680 + -- + -- but it will link dynamic @rpath/libstd-xxx.dylib, + -- so we can no longer modify and set other rpath paths + target:add("shflags", "-C prefer-dynamic") + 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 diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua index d5567b605..805f535d8 100644 --- a/xmake/rules/utils/inherit_links/inherit_links.lua +++ b/xmake/rules/utils/inherit_links/inherit_links.lua @@ -46,7 +46,6 @@ function _add_export_value(target, name, value) end end --- main entry function main(target) -- disable inherit.links for `add_deps()`? @@ -59,12 +58,15 @@ function main(target) if targetkind == "shared" or targetkind == "static" then local targetfile = target:targetfile() - -- we need move target link to head - _add_export_value(target, "links", target:linkname()) - local links = target:get("links", {rawref = true}) - if links and type(links) == "table" and #links > 1 then - table.insert(links, 1, links[#links]) - table.remove(links, #links) + -- rust maybe will disable inherit links, only inherit linkdirs + if target:data("inherit.links.deplink") ~= false then + -- we need move target link to head + _add_export_value(target, "links", target:linkname()) + local links = target:get("links", {rawref = true}) + if links and type(links) == "table" and #links > 1 then + table.insert(links, 1, links[#links]) + table.remove(links, #links) + end end _add_export_value(target, "linkdirs", path.directory(targetfile)) |
