diff options
| author | ruki <[email protected]> | 2026-01-27 23:03:00 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-27 23:03:00 +0800 |
| commit | e1d3f3555235dc41e530f563140850a3ee8b3e2b (patch) | |
| tree | 039771caa6c51ef879c4d9ec4f7e66c17feefd71 | |
| parent | a217ee2dc800dc9d3a022003f493c01fdebe745c (diff) | |
| parent | 763198516f386f54664e44ef45cbbbeabfc09708 (diff) | |
Merge pull request #7269 from luadebug/zig-cross
add target architecture validation for cross-compilation in zig toolchain
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua index e9d099782..72e4b943f 100644 --- a/xmake/toolchains/zig/xmake.lua +++ b/xmake/toolchains/zig/xmake.lua @@ -78,6 +78,7 @@ toolchain("zig") on_load(function (toolchain) import("core.base.semver") + import("private.core.base.is_cross") -- set toolset -- we patch target to `zig cc` to fix has_flags. see https://github.com/xmake-io/xmake/issues/955#issuecomment-766929692 @@ -106,36 +107,42 @@ toolchain("zig") toolchain:set("toolset", "zcld", zig) toolchain:set("toolset", "zcsh", zig) - -- init 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" + -- get target from cross only for cross-compilation + -- @see https://github.com/xmake-io/xmake/issues/7180 + local target + if not target and is_cross(toolchain:plat(), toolchain:arch()) 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 = "i386" + arch = "x86_64" 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 - -- init target - local target = toolchain:cross() - if target == nil then if toolchain:is_plat("cross") then -- xmake f -p cross --toolchain=zig --cross=mips64el-linux-gnuabi64 elseif toolchain:is_plat("macosx") then @@ -155,6 +162,8 @@ toolchain("zig") target = arch .. "-windows-gnu" end end + + -- set target flags if target then toolchain:add("asflags", "-target", target) toolchain:add("cxflags", "-target", target) |
