-
Notifications
You must be signed in to change notification settings - Fork 160
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
CMake: Fixing cross-compiling Swift-Foundation #878
base: main
Are you sure you want to change the base?
Conversation
@swift-ci please test |
Sources/CMakeLists.txt
Outdated
CMAKE_ARGS | ||
-DCMAKE_BUILD_TYPE=Release | ||
-DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER} | ||
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> |
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 haven't seen the <INSTALL_DIR>
syntax before, out of curiosity, what does it mean?
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 is a special placeholder that will be filled in with the install path. This is documented in the ExternalProject
documentation IIRC.
04df903
to
2ee745d
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.
One minor comment, otherwise this looks good to me. Before merging, lets run a cross-repo CI test to get a full toolchain test going with this since this repo's CI doesn't test the cmake build yet
2ee745d
to
fbd845a
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.
Approved assuming cross-repo test comes back clean, thanks for updating this!
Looks like we need to make sure |
Except that was built for the machine we're building the toolchain for, not the machine we're building the toolchain on. We can, however, set |
Actually I got my wires crossed - in the toolchain build, swift-foundation should already receive |
fbd845a
to
dad5401
Compare
@swift-ci please test |
The macros must build for the local machine running the build, not the machine that Swift-Foundation will run on, in order for the build to be able to use the macros. To do this, the macro build must use ExternalProject, which treats the child project as an entirely independent project. One cannot introspect into the external project since it is configured at build time, rather than at configure time. This is what allows the external project to build for another platform. The expectation is that the calling project will pull the built products of the ExternalProject from the install location. EPs have an internal implicit install prefix where they can install stuff to without dirtying the building machine or installed products, so we can make use of that. In order for that to work, the products must actually get installed though, so we have to install the FoundationMacros, even when built as an executable. To support that, I've exposed an option to tell the macro build to build the macros as an executable. On the library side, I've exposed the Foundation macros as an interface library that only exposes the `-load-plugin-path` option needed for picking up the macro. Linking against this interface library will load the plugin as desired. This results in a build that - can use macros, even when cross-compiling. - does not install the macros into the installed library, only to the build directory.
dad5401
to
e39a63f
Compare
@swift-ci please test |
Is this really necessary? When cross-compiling this repo on the CI, you use a current freshly-built host toolchain from the same source, which already has these macros compiled and installed for the host. I haven't had any problem cross-compiling these new Foundation repos that way. What I'd like instead is an option to disable cross-compiling these macros too, which is only useful for cross-compiling the toolchain, but not for standalone SDKs. For example, I'm cross-compiling an Android SDK using Btw @etcwilde, there appears to be a problem with building for Swift with the current CMake 3.30.
However, something changed in the CMake source with 3.30 and it is now indiscriminately applying those C linker flags to all languages' shared libraries in mixed language CMake projects like this, breaking other languages like Swift. |
The macros must build for the local machine running the build, not the machine that Swift-Foundation will run on, in order for the build to be able to use the macros.
To do this, the macro build must use ExternalProject, which treats the child project as an entirely independent project. One cannot introspect into the external project since it is configured at build time, rather than at configure time. This is what allows the external project to build for another platform.
The expectation is that the calling project will pull the built products of the ExternalProject from the install location. EPs have an internal implicit install prefix where they can install stuff to without dirtying the building machine or installed products, so we can make use of that. In order for that to work, the products must actually get installed though, so we have to install the FoundationMacros, even when built as an executable. To support that, I've exposed an option to tell the macro build to build the macros as an executable.
On the library side, I've exposed the Foundation macros as an interface library that only exposes the
-load-plugin-path
option needed for picking up the macro. Linking against this interface library will load the plugin as desired.This results in a build that