diff options
| author | ruki <[email protected]> | 2026-01-31 00:55:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-01 16:53:34 +0800 |
| commit | a6ebbeecfd5d6ebe084ac5d3d45e1358e89110d3 (patch) | |
| tree | 7cee8633ccb6cf0b3183b7ac128c225d8e4ce407 | |
| parent | d7bdbc99bcc5b64a3fa257c5835014f5d8878150 (diff) | |
add target flags for cross-compilation
| -rw-r--r-- | xmake/core/platform/platform.lua | 4 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 8 | ||||
| -rw-r--r-- | xmake/toolchains/clang/load.lua | 18 | ||||
| -rw-r--r-- | xmake/toolchains/kotlin-native/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 18 | ||||
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 3 |
6 files changed, 31 insertions, 23 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 61fee4ec3..f5eb9ab94 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -204,8 +204,8 @@ function _instance:toolchains(opt) if not toolchain_inst then os.raise(errors) end - -- ignore cross toolchains for the host platform:w - if (self:is_host() and not toolchain_inst:is_cross()) or not self:is_host() then + -- ignore cross toolchains for the host platform + if (self:is_host() and not toolchain_inst:is_cross_toolchain()) or not self:is_host() then table.insert(toolchains, toolchain_inst) end end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 1da1634db..35be6b824 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -32,6 +32,7 @@ local option = require("base/option") local hashset = require("base/hashset") local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") +local is_cross = require("base/private/is_cross") local config = require("project/config") local memcache = require("cache/memcache") local localcache = require("cache/localcache") @@ -203,8 +204,13 @@ function _instance:formats() return self:info():get("formats") end --- is cross-compilation toolchain? +-- is cross-compilation? function _instance:is_cross() + return is_cross(self:plat(), self:arch()) or self:is_cross_toolchain() +end + +-- is cross-compilation toolchain? +function _instance:is_cross_toolchain() if self:kind() == "cross" then return true elseif self:kind() == "standalone" and (self:cross() or self:config("sdkdir") or self:info():get("sdkdir")) then diff --git a/xmake/toolchains/clang/load.lua b/xmake/toolchains/clang/load.lua index 4a12b31ce..79c43d85b 100644 --- a/xmake/toolchains/clang/load.lua +++ b/xmake/toolchains/clang/load.lua @@ -42,14 +42,16 @@ function main(toolchain, suffix) toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix) end - -- add target flags - local flags = toolchain_utils.get_clang_target_flags(toolchain) - if flags then - toolchain:add("cxflags", flags) - toolchain:add("mxflags", flags) - toolchain:add("asflags", flags) - toolchain:add("ldflags", flags) - toolchain:add("shflags", flags) + -- add target flags if it's cross-compilation + if toolchain:is_cross() then + local flags = toolchain_utils.get_clang_target_flags(toolchain) + if flags then + toolchain:add("cxflags", flags) + toolchain:add("mxflags", flags) + toolchain:add("asflags", flags) + toolchain:add("ldflags", flags) + toolchain:add("shflags", flags) + end end -- set llvm runtimes diff --git a/xmake/toolchains/kotlin-native/xmake.lua b/xmake/toolchains/kotlin-native/xmake.lua index 5e72b0ec1..7633af107 100644 --- a/xmake/toolchains/kotlin-native/xmake.lua +++ b/xmake/toolchains/kotlin-native/xmake.lua @@ -78,7 +78,6 @@ toolchain("kotlin-native") end) on_load(function (toolchain) - import("private.core.base.is_cross") -- bind runenvs for java local runenvs = toolchain:config("runenvs") @@ -91,7 +90,7 @@ toolchain("kotlin-native") -- kotlinc-native -list-targets local target_plat = toolchain:plat() local target_arch = toolchain:arch() - if target_plat and target_arch and is_cross(target_plat, target_arch) then + if target_plat and target_arch and toolchain:is_cross() then if target_plat == "macosx" then target_plat = "macos" elseif target_plat == "iphoneos" then diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index fb18f280f..deb615fee 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -57,14 +57,16 @@ toolchain("llvm") -- add llvm runenvs toolchain_utils.add_llvm_runenvs(toolchain) - -- add target flags - local flags = toolchain_utils.get_clang_target_flags(toolchain) - if flags then - toolchain:add("cxflags", flags) - toolchain:add("mxflags", flags) - toolchain:add("asflags", flags) - toolchain:add("ldflags", flags) - toolchain:add("shflags", flags) + -- add target flags if it's cross-compilation + if toolchain:is_cross() then + local flags = toolchain_utils.get_clang_target_flags(toolchain) + if flags then + toolchain:add("cxflags", flags) + toolchain:add("mxflags", flags) + toolchain:add("asflags", flags) + toolchain:add("ldflags", flags) + toolchain:add("shflags", flags) + end end -- add target flags for swift diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua index 72e4b943f..d1b2165e4 100644 --- a/xmake/toolchains/zig/xmake.lua +++ b/xmake/toolchains/zig/xmake.lua @@ -78,7 +78,6 @@ 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 @@ -110,7 +109,7 @@ toolchain("zig") -- 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 + if not target and toolchain:is_cross() then target = toolchain:cross() end |
