summaryrefslogtreecommitdiff
path: root/xmake/modules/detect/tools/rustc/has_flags.lua
diff options
context:
space:
mode:
authorÂngelo Andrade Cirino <[email protected]>2022-01-10 10:23:17 -0300
committerÂngelo Andrade Cirino <[email protected]>2022-01-10 10:23:17 -0300
commited0c0c5e0249aa966ea7061b30710abdd0b09d87 (patch)
tree2a51c869a3aea1a093ed569e749bdf0465634a6c /xmake/modules/detect/tools/rustc/has_flags.lua
parent885d00da8caf74aeed758d030b9a1b50d9078e1f (diff)
parent2431dd7e6142ff98b55741cfd4de4d2e69f4f8b5 (diff)
Merged from upstream/master
Diffstat (limited to 'xmake/modules/detect/tools/rustc/has_flags.lua')
-rw-r--r--xmake/modules/detect/tools/rustc/has_flags.lua30
1 files changed, 22 insertions, 8 deletions
diff --git a/xmake/modules/detect/tools/rustc/has_flags.lua b/xmake/modules/detect/tools/rustc/has_flags.lua
index e7c55a180..e1696e454 100644
--- a/xmake/modules/detect/tools/rustc/has_flags.lua
+++ b/xmake/modules/detect/tools/rustc/has_flags.lua
@@ -21,12 +21,22 @@
-- 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(...)
local argv = {...}
local errors = nil
- return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors
+ return try { function () os.runv(table.unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors
end
-- attempt to check it from the argument list
@@ -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