nfc(xcode) refactor xcode toolchain, improve it and use it in llvm toolchain when targeting a apple device#6977
Conversation
Summary of ChangesHello @Arthapz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a significant refactoring and enhancement of the Xcode toolchain integration within Xmake, specifically targeting Apple development environments. The core change involves centralizing the complex logic for configuring compiler and linker flags, along with SDK path detection, into a new, reusable module. This strategic consolidation aims to boost maintainability and robustness across all supported Apple platforms, encompassing iOS, tvOS, watchOS, xros, and macOS (with specialized support for Catalyst), while simultaneously standardizing the approach to Swift compiler interactions. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant and valuable refactoring of the Xcode toolchain logic. By centralizing platform-specific flag settings for Apple devices into a new load_platform.lua module, it greatly improves maintainability and reduces code duplication. The updated logic in the llvm toolchain to use this new module is also a good improvement. However, I've found a critical issue in the new load_platform.lua module that will cause Swift builds to fail. The way the -sdk flag is passed to the Swift compiler is incorrect. My review includes a code suggestion to fix this.
7493d33 to
2a86285
Compare
2a86285 to
f52a15b
Compare
xmake/rules/swift/xmake.lua
Outdated
| local mode = target:data("swift.interop") | ||
| local sc = target:tool("sc") | ||
| -- local sc = target:compiler("sc") | ||
| local sc = import("core.tool.compiler").load("sc") |
There was a problem hiding this comment.
why do not use target:compiler("sc")?
There was a problem hiding this comment.
same reason as #6967 (comment)
is it a bug ? should we fix it ?
There was a problem hiding this comment.
it works for me.
target("test")
set_kind("binary")
add_files("src/*.swift")
on_config(function (target)
local compinst = import("core.tool.compiler").load("sc")
local compinst2 = target:compiler("sc")
print(compinst:program())
print(compinst2:program())
end)ruki:test ruki$ xmake f -c
checking for platform ... macosx
checking for architecture ... x86_64
checking for Xcode directory ... /Applications/Xcode.app
checking for SDK version of Xcode for macosx (x86_64) ... 15.2
checking for Minimal target version of Xcode for macosx (x86_64) ... 15.2
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontendyou can debug here. target:compiler("sc") will get tool from target:tool().
import("core.tool.compiler").load("sc") will get tool from the global platform.
xmake/xmake/core/tool/compiler.lua
Lines 130 to 135 in 0fd0f4e
There was a problem hiding this comment.
we should get tool from target instance.
There was a problem hiding this comment.
the problem happen when there are multiple soucekind in the same target
-- get the target compiler
function _instance:compiler(sourcekind)
local compilerinst = self:_memcache():get("compiler")
if not compilerinst then
if not sourcekind then
os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as")
end
local instance, errors = compiler.load(sourcekind, self)
if not instance then
os.raise(errors)
end
compilerinst = instance
self:_memcache():set("compiler", compilerinst)
end
return compilerinst
endthe target only cache the first call to compiler(sourcekind) for all sourcekind, so if i do target:compiler("cxx") it will cache clang and when i call target:compiler("sc") it will return the cached clang
changing it to
-- get the target compiler
function _instance:compiler(sourcekind)
if not sourcekind then
os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as")
end
local compilerinst = self:_memcache():get("compiler_" .. sourcekind)
if not compilerinst then
local instance, errors = compiler.load(sourcekind, self)
if not instance then
os.raise(errors)
end
compilerinst = instance
self:_memcache():set("compiler_" .. sourcekind, compilerinst)
end
return compilerinst
endmake it work as it's now caching for each sourcekind, but i don't know what impact it have on the rest of XMake
see my last commit
8dd0739 to
1b2be30
Compare
1b2be30 to
6bb310b
Compare
this PR cleanup the xcode toolchain, reduce repetition and make it compatible with llvm toolchain on apple platforms