-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Refactored build-script-impl for cross-compiling support #2497
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
Conversation
13c2e34
to
1513d54
Compare
Diff is now more manageable |
SWIFT_HOST_VARIANT_ARCH="x86_64" | ||
;; | ||
linux-*) | ||
SWIFT_HOST_VARIANT="linux" | ||
SWIFT_HOST_VARIANT_SDK="LINUX" |
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.
Missing indentation?
The primary reason why I didn't use the Build/Host/Target terms is because it assumes one combination of the three, and does not work well with multi-target cross-compilers compilers, which Swift is. |
done | ||
|
||
if [[ "${CROSS_COMPILE_TOOLS_DEPLOYMENT_TARGETS}" ]] && [[ ! "${SKIP_MERGE_LIPO_CROSS_COMPILE_TOOLS}" ]] ; then | ||
echo "--- Merging and running lipo for ${CROSS_COMPILE_TOOLS_DEPLOYMENT_TARGETS[@]} ---" |
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.
Did you intentionally drop this part? It is important for our internal workflows. Is this handled somehow by the primary build steps now?
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, but looking at it more closely, I should have put it behind a switch for the iOS targets.
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.
The purpose of this step is to lipo together the cross-compiled compilers, and copy over the standard library, so that we would get a consistent installation layout ready to be deployed onto a target. This step is Darwin-specific, but other targets will need something similar.
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've added the lipo step back. The install process needed some adjustment to deal with it. Since it's a collection of multiple hosts, it gets placed in to a host-specific subdirectory "merged".
After reading the script more, I find the change to the plain "host/target" terms to be a readability loss. In the current script, I tried to use "stdlib-deployment-target" and "tools-deployment-target" to be extra clear about what is happening. |
@swift-ci Please test |
Some strange CI issues. Let's try again. @swift-ci Please test |
@karwa I just wanted to thank you and say that I deeply appreciate your work on the build system. |
Happy to help! |
8161717
to
af33777
Compare
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
;; | ||
linux-armv7) | ||
SWIFT_HOST_VARIANT_ARCH="armv7" | ||
llvm_host_triple="${SWIFT_HOST_VARIANT_ARCH}-linux-gnueabihf" |
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.
Please substitute SWIFT_HOST_VARIANT_ARCH
with armv7
for clarity.
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 wanted to emphasise that the LLVM and Swift triples should be exactly the same. I've had issues with an "armv7-linux" Swift triple and "arm-linux" LLVM triple, for example. There is probably a better way to do this, such as a single "triple" setting that gets passed to both LLVM and Swift (we can now set SWIFT_HOST_TRIPLE
explicitly when building, so that's an option)
That would probably be a good thing to do anyway. We have logic here to calculate the llvm_host_triple
for OSX/iOS targets, but they duplicate that in SwiftConfigureSDK.cmake
. The triples for the arm
architectures are duplicated in CMakeLists.txt
, and if we wanted to cross-compile hosts for other linux platforms, we'd have to have this triple logic in both places and they'd have to produce the exact same triples. We should do it in one place, and since both LLVM and Swift need it, it should be in the build script.
@karwa Thanks! The install tree looks a little funny, Swift does not seem to be installed into the toolchain:
|
swift will be inside the toolchain:
|
@karwa Sorry, I don't understand you... I built a toolchain and the file list I posted is what I got. Are you saying that you are working on a fix? |
No, I'm saying that swift is installed where it should be - inside the toolchain directory. The path you posted was in the install_destdir itself. This is the tree I got from |
Looks like this is the issue: DESTDIR="${host_install_destdir}" "${CMAKE}" --build "${build_dir}" -- ${INSTALL_TARGETS} Should it use |
Well, yes, that's the issue I'm pointing out. The tree I posted is what I got from build-toolchain, too. |
@swift-ci Please test |
No I'm still pretty sure this is right - the install prefix wasn't in the If you have an extra copy of swift, maybe it's left over from another build? |
Let's see if it reproduces in CI. |
But when we call the CMake action to install, we override the directory with
It is not an extra copy, it is the only copy. (And I'm always doing from-scratch builds, removing the |
I will also build another toolchain without this PR to check which commands were run before. |
@@ -1546,32 +1767,32 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_COMPILE_TOOLS_DEPLOYMENT_TARG | |||
|
|||
cmake_options=( | |||
"${cmake_options[@]}" | |||
-DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}" | |||
-DLLVM_CONFIG:PATH="$(build_directory_bin ${deployment_target} llvm)/llvm-config" | |||
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})" |
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 where we set the install prefix for swift. It's in CMakeCache.txt. Should be:
CMAKE_INSTALL_PREFIX:PATH=/Library/Developer/Toolchains/swift-LOCAL-2016-05-29-a.xctoolchain/usr
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 is exactly right, and it is what I'm seeing. So the issue is either somewhere else, or it is my local misconfiguration. See my other comment -- I'm running another build.
I finally see what you meant, sorry, I misunderstood you. I'm building again now. I can confirm that |
I just built the toolchains again on OS X and Linux, and everything matches up exactly! So it was a misconfiguration on my side, sorry for wasting your time, @karwa. |
@gribozavr Thank you so much for all your help and for reviewing it. Also to @rintaro and everybody else. |
I can't tell for sure, but it looks like this commit introduced Linux triples of the form "armv7-linux-gnueabihf" instead of "armv7-unknown-linux-gnueabihf", causing SR-3019. Was this intentional? |
@jrose nope. I picked that to be as close as possible to the GCC triple arm-linux-gnueabihf (but I don't think anybody uses armv6/7 on GCC). I wasn't aware that triples in LLVM needed a fourth component. |
They need three components, but the second component has to be a vendor. Are you sure the GCC triple is arm-linux-gnueabihf and not arm-unknown-linux-gnueabihf? |
Okay, I could have just checked for that, indeed it is. |
Yeah sorry, you're right that the second component should be "unknown" (rustc apparently uses that), but GCC seems to use an incorrect triple: http://packages.ubuntu.com/precise/devel/gcc-arm-linux-gnueabihf I've been having some issues with LLDB reloading images because of mismatching architectures. I'll investigate if this could be the reason for it... |
I doubt it is, but we should pull in a fix anyway. |
What's in this pull request?
In the current build-script-impl, we use the variable name "deployment_target" pretty loosely when talking about the Build, Host and Target of the products we're building. You can see this in places - like where the test phase iterates every STDLIB_DEPLOYMENT_TARGET (i.e. Target), before skipping those which are not, effectively, host platforms, so we're tripping up on all these types of "deployment targets" floating around.
I'm aware the build script is being rewritten in python. The rewrite is approaching the stage where it's going to be getting to some of the points I've addressed here (e.g. calculating stdlib targets), so I think it's a good idea if we get this done first, so the python implementation can consider it from the start.
This PR replaces uses of "deployment_target" with "host" when talking about a platform which will ultimately host a Swift compiler. The Build platform is implicitly a Host. It replaces uses of "deployment_target" with "stdlib_target" when talking about a platform for which the stdlib is to be built. This terminology is consistent with the actual swift/llvm build process:
llvm_host_triple
,SWIFT_HOST_VARIANT_*
and host-related flags get setset_build_options_for_host
instead ofset_deployment_target_options
, andSWIFT_STDLIB_TARGETS
calculation has been moved to a function -calculate_targets_for_host
.SWIFT_STDLIB_TARGETS
now gets recalculated for each host we build, as it should.LOCAL_HOST
(Build machine) productsNote: The diff is large because of things like moving the stdlib target calculation in to a function and relocating it to be close to the function which sets the host options. The actual changes are not that extreme, and really limited to some variable renaming, function encapsulation and moving.
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.
'deployment_target'
cross-compiling