-
Notifications
You must be signed in to change notification settings - Fork 175
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
FoundationMacros: use cross-compilation to build for host #714
Conversation
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.
Few nits, but otherwise LGTM.
@swift-ci please test |
@swift-ci please test |
1 similar comment
@swift-ci please test |
CC: @bnbarham there was a conversation on swiftlang/swift#75206 which seems to have converged around moving ahead with this change. |
@jmschonfeld @bnbarham - any idea if this is something we should be moving forward with? This is going to break the windows builds at least, but I want to ensure that we only are investing in this if we are going to move forward with this. |
I think I'm still a little fuzzy on the details for this, so just to lay it out to confirm: Currently we have: (builder platform = host building the toolchain, toolchain platform = host where the toolchain will be used, sdk platform = platform where things the toolchain builds will be run) Linux:
Windows: Macro does not build And with this PR, can you clarify what changes? In specific
I think I'm still unclear on those points and I want to make sure that we do not regress what Linux already has working in the process of getting it right on Windows (but I agree we need to make sure we get it right on Windows too) |
So the goal is to split where the SDK library that actually goes in the runtime environment and the macros that are only useful if you're compiling things against that library. What this PR does is, when building Swift-Foundation, build the macro for the platform that is doing the build, rather than what swift-foundation is being cross-compiled for. This is just like what we're doing for Swift-Testing (https://github.com/apple/swift-testing/blob/b19c9af0750e219fc972217af3f061b1b0b60897/Sources/CMakeLists.txt#L22-L30). It's still not perfect, but it's better because it means that we can use these macros in the build of swift-foundation. |
Just to clear up some of the confusion on what is happening today: Windows:
Note that this is identical to Linux where the macros are built for the platform that foundation is being built for (e.g. macOS). |
In the toolchain build or standalone? If the former, how are they being picked up at runtime? IIRC we only add toolchain search paths for the libraries, not executables. |
Ugh, wait, I mixed up two scenarios. The reason that it is building with the toolchain early swift-syntax is because I'm building locally with a reference to the toolchain build. That change is dependent on the other change that I have pending. The CI builds currently use SPM based builds in a docker container, so they are building their own copy of swift-syntax. For the toolchain distribution, we should be using the toolchain build of swift-syntax though to avoid bloat (the toolchain is already large enough that it prevents pre-installation on GHA agents). |
Sure, that should be the case here - we should be passing through |
I don't think that was wired up in the swift-corelibs-foundation build which is now re-cored to swift-foundation. We don't build swift-foundation on its own yet, so this particular path is more future direction and I don't think that we are setup to test it in CI. |
AFAIK it should be - when invoking the swift-corelibs-foundation build from both |
@etcwilde @compnerd ah thanks for clearing up a lot of those details, I think I understand the problem space better now. I think overall this approach sounds good, the only two points that I think we should address before merging this are:
|
For the installation, I don't think that we have a good way to detect when it is being built for a toolchain host. There is The plugin (DLL) approach is not really viable. The entire compiler codebase needs to be annotated with |
We currently use libraries for the stdlib plugins. The driver isn't setup to load executables from the toolchain at all, so if we did end up going down that route we'd need updates there. But I'm not sure I understand why we have to. Why does LLVM matter at all here? |
The plugin host needs to expose interfaces to the plugin (i.e. |
There's an interface, but it uses swift-syntax APIs and they are in SwiftSyntax.dll. Just to re-iterate, the stdlib macro plugins are both libraries today and as far as I'm aware they don't have any issues. This seems like an identical case to me. |
Added additional changes to make this also work for the android swift-foundation building from build.ps1 windows host: |
8a9c602
to
6c3ffcb
Compare
6c3ffcb
to
890309d
Compare
Sources/CMakeLists.txt
Outdated
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros.dll#ExpressionMacro") | ||
else() | ||
set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros#PredicateMacro") | ||
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros#ExpressionMacro") |
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.
I think I'm still confused on what the intention of these settings are? Are they supposed to be paths that we provide as -plugin-path
to the FoundationEssentials build? If so, I think I'd expect them to be in the library directory on non-windows and also look like libFoundationMacros.so
rather than FoundationMacros#ExpressionMacro
.
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.
Yes, this was the expected parameter for the macro. Although, after the discussion with @rintaro yesterday, I don't think it matters. Once we have the custom option for the macro, this will no longer be needed.
Sources/CMakeLists.txt
Outdated
if(CMAKE_HOST_WIN32) | ||
set(_FoundationMacrosSwiftFlags "-use-ld=lld") | ||
endif() | ||
ExternalProject_Add(FoundationMacros |
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.
Just to clarify with this approach, I know that the build script will need to invoke the macro build separately. Is the goal that it needs to invoke the macro build once for the current host (and pass that path to the swift-foundation build to use when building itself) and once for each target host (and that it will actually install instead of just building)? In FoundationEssentials/CMakeLists.txt
we have a FoundationEssentials
--> FoundationMacros
dependency added on non-Windows, I think we'll need to adjust that accordingly if there's no longer a target built in this same project
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.
Yes, the idea is that we would need at least two builds:
- build: for use by the compiler building swift-foundation (not installed)
- host: for distribution only
The path to the build build of the macros would be passed in as a parameter for the build as we discussed.
890309d
to
ed0dd0f
Compare
Use `ExternalProject` to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments. Co-authored-by: Alex Lorenz <[email protected]>
ed0dd0f
to
52a0ee3
Compare
@swift-ci please test |
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 LGTM now - approved to merge, but let's try to merge it with both of our swiftlang/swift changes and your swift-installer-script change just so that everything switches to the new build style at once
) Use `ExternalProject` to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments. Co-authored-by: Alex Lorenz <[email protected]>
Use `ExternalProject` to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments. Co-authored-by: Alex Lorenz <[email protected]>
) Use `ExternalProject` to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments. Co-authored-by: Alex Lorenz <[email protected]>
Use
ExternalProject
to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments.