summaryrefslogtreecommitdiff
path: root/xmake/modules/detect/tools/rustc/has_flags.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-10 23:05:38 +0800
committerruki <[email protected]>2021-11-10 23:05:38 +0800
commitbc404bc6481de0c934aa5ff4523924688b72a2d4 (patch)
tree13d21c0ca6bd6881ae110809e815d37665c4fd88 /xmake/modules/detect/tools/rustc/has_flags.lua
parentb6ed301feb4b223a8c0faa9dd979a722b6e04555 (diff)
fix rpath for rust
Diffstat (limited to 'xmake/modules/detect/tools/rustc/has_flags.lua')
-rw-r--r--xmake/modules/detect/tools/rustc/has_flags.lua28
1 files changed, 21 insertions, 7 deletions
diff --git a/xmake/modules/detect/tools/rustc/has_flags.lua b/xmake/modules/detect/tools/rustc/has_flags.lua
index 904a3c85a..e1696e454 100644
--- a/xmake/modules/detect/tools/rustc/has_flags.lua
+++ b/xmake/modules/detect/tools/rustc/has_flags.lua
@@ -21,6 +21,16 @@
-- imports
import("core.cache.detectcache")
+-- is linker?
+function _islinker(flags, opt)
+ local flags_str = table.concat(flags, " ")
+ if flags_str:startswith("-C linkarg=") then
+ return true
+ end
+ local toolkind = opt.toolkind or ""
+ return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("ld") or toolkind:endswith("sh")
+end
+
-- try running
function _try_running(...)
@@ -64,7 +74,7 @@ function _check_from_arglist(flags, opt)
end
-- try running to check flags
-function _check_try_running(flags, opt)
+function _check_try_running(flags, opt, islinker)
-- make an stub source file
local sourcefile = path.join(os.tmpdir(), "detect", "rustc_has_flags.rs")
@@ -72,14 +82,15 @@ function _check_try_running(flags, opt)
io.writefile(sourcefile, "fn main() {\n}")
end
- -- check it
+ -- check flags for linker
+ if islinker then
+ return _try_running(opt.program, table.join("--crate-type=bin", flags, "-o", os.tmpfile(), sourcefile), opt)
+ end
+
+ -- check flags for compiler
local objectfile = os.tmpfile() .. ".o"
local ok, errors = _try_running(opt.program, table.join("--emit", "obj", flags, "-o", objectfile, sourcefile))
-
- -- remove files
os.tryrm(objectfile)
-
- -- ok?
return ok, errors
end
@@ -91,12 +102,15 @@ end
--
function main(flags, opt)
+ -- is linker?
+ local islinker = _islinker(flags, opt)
+
-- attempt to check it from the argument list
if _check_from_arglist(flags, opt) then
return true
end
-- try running to check it
- return _check_try_running(flags, opt)
+ return _check_try_running(flags, opt, islinker)
end