-
-
Notifications
You must be signed in to change notification settings - Fork 884
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ toolchain("gcc" .. suffix) | |
| end) | ||
|
|
||
| on_load(function (toolchain) | ||
| import("core.base.option") | ||
|
|
||
| -- add march flags | ||
| local march | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. The |
||
|
|
||
| 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() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 theclangtoolchain 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.