Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

improve(toolchain): enhance gcc/clang support for cross-compilation#6899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
romeoxbm wants to merge1 commit intoxmake-io:dev
base:dev
Choose a base branch
Loading
fromromeoxbm:improve/gcc-clang-cross-support
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
improve(toolchain): enhance gcc/clang support for cross-compilation
The builtin gcc and clang toolchains did not handle cross-compilation correctly, as they were missing proper cross-prefix support. This patch updates their on_load functions to add the appropriate prefixing, aligning behavior with expected cross-compilation setups.
  • Loading branch information
@romeoxbm
romeoxbm committedOct 7, 2025
commit9966baf23bc953789e4bdb41d065d82abbcf2dd9
37 changes: 35 additions & 2 deletionsxmake/toolchains/clang/load.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,13 +51,46 @@ function _add_vsenv(toolchain, name, curenvs)
end

function main(toolchain, suffix)
import("core.base.option")
import("core.project.project")

if project.policy("build.optimization.lto") then
toolchain:set("toolset", "ar", "llvm-ar" .. suffix)
toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix)
end

local march
if toolchain:is_arch("x86_64", "x64", "arm64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86", "i686") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
if toolchain:is_plat("windows") then
toolchain:add("runtimes", "MT", "MTd", "MD", "MDd")
end

local host_arch = os.arch()
local target_arch = toolchain:arch()

if host_arch == target_arch then
-- Early exit: prevents further configuration of this toolchain
return
elseif option.get("verbose") then
cprint("${bright yellow}cross compiling from %s to %s", host_arch, target_arch)
end
Comment on lines +82 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

critical

This early return for native builds (host_arch == target_arch) is problematic. It causes the toolchain to skip crucial configuration steps that follow, such as setting up the Visual Studio environment for clang on Windows. This breaks native builds with theclang toolchain on Windows.

The logic should be restructured to only print a message for cross-compilation, without exiting early for native builds, allowing the subsequent configuration to always run.

    if host_arch ~= target_arch and option.get("verbose") then        cprint("${bright yellow}cross compiling from %s to %s", host_arch, target_arch)    end


local target
if toolchain:is_arch("x86_64", "x64") then
target = "x86_64"
march = "-m64"
elseif toolchain:is_arch("i386", "x86", "i686") then
target = "i686"
march = "-m32"
elseif toolchain:is_arch("arm64", "aarch64") then
target = "aarch64"
elseif toolchain:is_arch("arm") then
Expand Down
29 changes: 2 additions & 27 deletionsxmake/toolchains/clang/xmake.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,33 +58,8 @@ toolchain("clang" .. suffix)
end)

on_load(function (toolchain)
import("core.project.project")

if project.policy("build.optimization.lto") then
toolchain:set("toolset", "ar", "llvm-ar" .. suffix)
toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix)
end

local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
if march then
toolchain:add("cxflags", march)
toolchain:add("mxflags", march)
toolchain:add("asflags", march)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
if toolchain:is_plat("windows") then
toolchain:add("runtimes", "MT", "MTd", "MD", "MDd")
end
if toolchain:is_plat("windows", "mingw") then
local rootdir = path.join(path.directory(os.scriptdir()), "clang")
import("load", {rootdir = rootdir})(toolchain, suffix)
end
local rootdir = path.join(path.directory(os.scriptdir()), "clang")
import("load", {rootdir = rootdir})(toolchain, suffix)
end)
end
toolchain_clang()
31 changes: 31 additions & 0 deletionsxmake/toolchains/gcc/xmake.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,7 @@ toolchain("gcc" .. suffix)
end)

on_load(function (toolchain)
import("core.base.option")

-- add march flags
local march
Expand All@@ -62,6 +63,36 @@ toolchain("gcc" .. suffix)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end

local host_arch = os.arch()
local target_arch = toolchain:arch()

if host_arch == target_arch then
-- Early exit: prevents further configuration of this toolchain
return
elseif option.get("verbose") then
cprint("${bright yellow}cross compiling from %s to %s", host_arch, target_arch)
end
Comment on lines +70 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

For better readability and to make the logic more explicit, it's better to separate the early exit for native compilation from the verbose logging for cross-compilation. Theelseif here implicitly depends on the failure of the firstif condition, which can be slightly confusing to read.

        if host_arch == target_arch then            -- Early exit for native compilation, as the rest of the logic is for cross-compilation.            return        end        if option.get("verbose") then            cprint("${bright yellow}cross compiling from %s to %s", host_arch, target_arch)        end


local target
if toolchain:is_arch("x86_64", "x64") then
target = "x86_64"
elseif toolchain:is_arch("i386", "x86", "i686") then
target = "i686"
elseif toolchain:is_arch("arm64", "aarch64") then
target = "aarch64"
elseif toolchain:is_arch("arm") then
target = "armv7"
end

-- TODO: Add support for more platforms, such as mingw.
if target and toolchain:is_plat("linux") then
target = target .. "-linux-gnu-"
toolchain:set("toolset", "cc", target .. "gcc" .. suffix)
toolchain:set("toolset", "cxx", target .. "g++" .. suffix, "gcc" .. suffix)
toolchain:set("toolset", "ld", target .. "g++" .. suffix, "gcc" .. suffix)
toolchain:set("toolset", "sh", target .. "g++" .. suffix, "gcc" .. suffix)
end
end)
end
toolchain_gcc()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp