Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork888
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
base:dev
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
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
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 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. This early return for native builds ( 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. | ||
| 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 | ||
| 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() | ||
Uh oh!
There was an error while loading.Please reload this page.