diff options
| author | ruki <[email protected]> | 2025-12-03 22:39:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-03 22:39:36 +0800 |
| commit | 4b24a3cb479df5ce3dd19eefa0c8ad0b794e5a4c (patch) | |
| tree | 33dcfaf1a96a914da5c2da9ef8363a915ea4eebc | |
| parent | 9a131d04c140ed7fdb2e7839ea14ac77b937dcb5 (diff) | |
improve flang
| -rw-r--r-- | xmake/modules/core/tools/flang.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_flang.lua | 4 | ||||
| -rw-r--r-- | xmake/toolchains/flang/xmake.lua | 35 |
3 files changed, 50 insertions, 9 deletions
diff --git a/xmake/modules/core/tools/flang.lua b/xmake/modules/core/tools/flang.lua index 2b0661e24..41e7643de 100644 --- a/xmake/modules/core/tools/flang.lua +++ b/xmake/modules/core/tools/flang.lua @@ -42,10 +42,28 @@ function init(self) self:set("mapflags", { -- visibility flags (not supported by Fortran) - ["-fvisibility=.*"] = "" + ["-fvisibility=.*"] = "", + -- strip flags (not supported by flang, use nf_strip instead) + ["^-s$"] = "" }) end +-- make the strip flag +-- flang doesn't support -s directly, use -Wl,-s for linker +function nf_strip(self, level) + local maps = { + debug = "-Wl,-S" + , all = "-Wl,-s" + } + if self:is_plat("macosx", "iphoneos", "watchos", "appletvos", "applexros") then + maps.all = {"-Wl,-x", "-Wl,-dead_strip"} + elseif self:is_plat("windows") then + -- flang doesn't support strip on windows + maps = {} + end + return maps[level] +end + -- make the symbol flag -- Fortran doesn't support visibility flags, only debug symbols function nf_symbol(self, level) diff --git a/xmake/modules/detect/tools/find_flang.lua b/xmake/modules/detect/tools/find_flang.lua index 2f29b2952..da21f1490 100644 --- a/xmake/modules/detect/tools/find_flang.lua +++ b/xmake/modules/detect/tools/find_flang.lua @@ -42,6 +42,10 @@ function main(opt) -- find program local program = find_program(opt.program or "flang", opt) + if not program and is_host("linux") then + -- on Linux, flang might be named as flang-new + program = find_program("flang-new", opt) + end -- find program version local version = nil diff --git a/xmake/toolchains/flang/xmake.lua b/xmake/toolchains/flang/xmake.lua index 72eb45258..c74b34bdf 100644 --- a/xmake/toolchains/flang/xmake.lua +++ b/xmake/toolchains/flang/xmake.lua @@ -41,16 +41,35 @@ toolchain("flang") -- on load on_load(function (toolchain) - local march - if toolchain:is_arch("x86_64", "x64", "arm64") then - march = "-m64" + -- flang doesn't support -m64/-m32, use --target instead (especially on Linux) + local target + if toolchain:is_arch("x86_64", "x64") then + target = "x86_64" elseif toolchain:is_arch("i386", "x86", "i686") then - march = "-m32" + target = "i686" + elseif toolchain:is_arch("arm64", "aarch64") then + target = "aarch64" + elseif toolchain:is_arch("arm") then + target = "armv7" end - if march then - toolchain:add("fcflags", march) - toolchain:add("fcshflags", march) - toolchain:add("fcldflags", march) + + if target then + -- add target suffix based on platform + if toolchain:is_plat("linux") then + target = target .. "-linux-gnu" + elseif toolchain:is_plat("windows") then + target = target .. "-windows-msvc" + elseif toolchain:is_plat("mingw") then + target = target .. "-w64-windows-gnu" + end + + -- only add --target on platforms that need it (Linux, Windows) + -- macOS flang may work without explicit target + if target and (toolchain:is_plat("linux") or toolchain:is_plat("windows", "mingw")) then + toolchain:add("fcflags", "--target=" .. target) + toolchain:add("fcshflags", "--target=" .. target) + toolchain:add("fcldflags", "--target=" .. target) + end end end) |
