diff options
| author | ruki <[email protected]> | 2021-01-28 00:35:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-01-28 00:35:58 +0800 |
| commit | a1728044cfcdd69080fc34c7e51d1cc4917e25a1 (patch) | |
| tree | b439bbba87c3846fc282b76e449e9f2a690f11a4 | |
| parent | 5edaf8c5ea6e68475c6050dc65bf86152ed66d72 (diff) | |
improve zig to cross-compilation
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 33 |
2 files changed, 32 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e8e9f6af..72f098470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features * [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-766481512): Support `zig cc` and `zig c++` as c/c++ compiler +* [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-768193083): Support zig cross-compilation * [#1177](https://github.com/xmake-io/xmake/issues/1177): Improve to detect terminal and color codes ## v2.5.1 @@ -910,6 +911,7 @@ ### 新特性 * [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-766481512): 支持 `zig cc` 和 `zig c++` 作为 c/c++ 编译器 +* [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-768193083): 支持使用 zig 进行交叉编译 * [#1177](https://github.com/xmake-io/xmake/issues/1177): 改进终端和 color codes 探测 ## v2.5.1 diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua index fc83710a7..d2aee0880 100644 --- a/xmake/toolchains/zig/xmake.lua +++ b/xmake/toolchains/zig/xmake.lua @@ -28,6 +28,12 @@ toolchain("zig") -- mark as standalone toolchain set_kind("standalone") + -- on check + on_check(function (toolchain) + -- only for overriding cross.on_check, because we will use `-p cross --cross=xxx` + return true + end) + -- on load on_load(function (toolchain) @@ -44,20 +50,41 @@ toolchain("zig") toolchain:set("toolset", "zcsh", "$(env ZC)", zig) -- init arch - if toolchain:is_arch("arm64") then + 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 arch = "i386" + elseif toolchain:is_arch("riscv64") then + arch = "riscv64" + 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 - if toolchain:is_plat("macosx") then + if toolchain:is_plat("cross") then + -- xmake f -p cross --toolchain=zig --cross=mips64el-linux-gnuabi64 + target = toolchain:cross() + elseif toolchain:is_plat("macosx") then target = arch .. "-macos-gnu" elseif toolchain:is_plat("linux") then - target = arch .. "-linux-gnu" + 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 |
