diff options
| author | ruki <[email protected]> | 2026-03-07 23:10:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-07 23:10:56 +0800 |
| commit | 31c6941b7ea41f1d3888db2fc2ee07a6cd948499 (patch) | |
| tree | be379aac619943e3b6ddf0eef76e736c6a7432f1 /xmake/modules | |
| parent | 6f71ecb6dda0eff8db9089c475e4e549c0db1dec (diff) | |
| parent | cb4ac4367a20be40109185f942cbf82865351c6d (diff) | |
Merge pull request #7383 from xmake-io/zig
split zig toolchain to zig/zigcc
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index f694c23c9..c2840a591 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -604,6 +604,68 @@ function get_sanitizer_flags(target, opt) return result end +-- get zig target +function get_zig_target(toolchain) + local zig_version = toolchain:config("zig_version") + + -- get target from cross only for cross-compilation + -- @see https://github.com/xmake-io/xmake/issues/7180 + local target + if not target and toolchain:is_cross() then + target = toolchain:cross() + end + + -- get target from arch + if not target then + local arch + if toolchain:is_arch("arm64", "arm64-v8a") then + arch = "aarch64" + elseif toolchain:is_arch("arm", "armv7") then + arch = "arm" + elseif toolchain:is_arch("i386", "x86") then + if zig_version and semver.compare(zig_version, "0.11") >= 0 then + arch = "x86" + else + arch = "i386" + end + elseif toolchain:is_arch("riscv64") then + arch = "riscv64" + elseif toolchain:is_arch("loong64") then + arch = "loongarch64" + elseif toolchain:is_arch("mips.*") then + arch = toolchain:arch() + elseif toolchain:is_arch("ppc64") then + arch = "powerpc64" + elseif toolchain:is_arch("ppc") then + arch = "powerpc" + elseif toolchain:is_arch("s390x") then + arch = "s390x" + else + arch = "x86_64" + end + + if toolchain:is_plat("cross") then + -- xmake f -p cross --toolchain=zig --cross=mips64el-linux-gnuabi64 + elseif toolchain:is_plat("macosx") then + --@see https://github.com/ziglang/zig/issues/14226 + target = arch .. "-macos-none" + elseif toolchain:is_plat("linux") then + if arch == "arm" then + target = "arm-linux-gnueabi" + elseif arch == "mips64" or arch == "mips64el" then + target = arch .. "-linux-gnuabi64" + else + target = arch .. "-linux-gnu" + end + elseif toolchain:is_plat("windows") then + target = arch .. "-windows-msvc" + elseif toolchain:is_plat("mingw") then + target = arch .. "-windows-gnu" + end + end + return target +end + -- check if the file is a c++ header file extension function is_cxx_headerext(extension) -- prioritize .h* extensions to filter out most cases quickly |
