diff options
| author | ruki <[email protected]> | 2026-02-02 09:35:24 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-02 09:35:24 +0800 |
| commit | a0249772f8e2960a741e6f51719605963d81032e (patch) | |
| tree | c47bba70fc9fc050cce94940d6d34817d3689a0d | |
| parent | d7bdbc99bcc5b64a3fa257c5835014f5d8878150 (diff) | |
| parent | 29fe0f24104d98653d2867926bd1263a304cd87c (diff) | |
Merge pull request #7280 from xmake-io/llvm
add target flags only 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/modules/private/utils/toolchain.lua | 10 | ||||
| -rw-r--r-- | xmake/toolchains/kotlin-native/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 3 |
5 files changed, 18 insertions, 10 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/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index b1a26b8da..bf24d3c73 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -168,10 +168,14 @@ function get_clang_target(toolchain) end -- get clang target flags +-- @see https://github.com/xmake-io/xmake/issues/7271 function get_clang_target_flags(toolchain) - local target = get_clang_target(toolchain) - if target then - return "--target=" .. target + local target + if toolchain:is_cross() or toolchain:is_plat("windows") then + target = get_clang_target(toolchain) + if target then + return "--target=" .. target + end end if toolchain:is_arch("x86_64", "x64") then return "-m64" 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/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 |
