-
Notifications
You must be signed in to change notification settings - Fork 10.5k
build: enable handling of alpine-linux-musl triple #61376
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
@swift-ci please smoke test |
7b51100
to
32dac24
Compare
@swift-ci please smoke test |
the general fix makes sense. is a more elegant way to detect it than shelling out to clang? how does clang do it? |
AFAIU, clang implements distro-specific parsing of |
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.
Small nits, lets use vendor
instead of distro
so that it keeps with existing triple terminology. Otherwise, LGTM.
How great it would be if build-script could just take a triple instead of trying to magically munge something together.
sysroot_arch, abi = self.get_linux_abi(arch) | ||
return '{}-unknown-linux-{}'.format(sysroot_arch, abi) | ||
sysroot_arch, distro, abi = self.get_linux_abi(arch) | ||
return '{}-{}-linux-{}'.format(sysroot_arch, distro, abi) |
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 field being substituted is the "vendor". I agree with @etcwilde that we should stick to standard terminology here.
SuSe also depends on the vendor being proper IIRC. Keep in mind that this will make cross-compilation more complicated as the target triple is embedded into the serialised swiftmodule. Do we want to consider filtering this in the driver? That would allow us to use the same swiftmodule on different distributions but get the correct triple for the link phase.
It may be interesting to consider actually adding a new field into the swiftmodule to actually embed a different clang triple to the swift triple.
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 field being substituted is the "vendor". I agree with @etcwilde that we should stick to standard terminology here.
Thanks, that's updated now.
SuSe also depends on the vendor being proper IIRC. Keep in mind that this will make cross-compilation more complicated as the target triple is embedded into the serialised swiftmodule. Do we want to consider filtering this in the driver? That would allow us to use the same swiftmodule on different distributions but get the correct triple for the link phase.
It may be interesting to consider actually adding a new field into the swiftmodule to actually embed a different clang triple to the swift triple.
I don't have an informed opinion on this. Should I tag someone else to review this aspect of the change?
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 could have sworn that the name of the swift module helped in this regard. e.g. Blarpy.swiftmodule/x86_64-apple-macos.swiftmodule
vs Blarpy.swiftmodule/arm64-apple-macos.swiftmodule
are applied to their corresponding architectures on macOS. I haven't looked closely so take it with a grain of salt, but having the swiftmodule key'd on its full triple should work on Linux too. The build system probably needs to learn to do this on things that aren't just Apple platforms though.
@xymus, can you confirm that? Thanks.
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.
Having a different target triple should help to avoid loading incompatible swiftmodules in the case of different distributions. I wouldn't trust loading a swiftmodule built on a different distro as they could refer to things from the C world that are organized differently. That being said, I don't work much in the Linux side of things so I'd be interested to know if it's an accepted practice there.
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 default Linux toolchain distribution does not use the directory layout like Windows and macOS, so you lose that ability to differentiate. How much C code actually gets serialised into the object layout? The only case that I would actually be concerned about is if we are serialising opaque C structures (e.g. pthread_t
) somehow. The remainder of the differences I believe should be handled implicitly as the macros are contained within the C module, which is re-constructed through the modulemap. The current loading behavior I feel may be a bit confusing for users. We should definitely include a test case for that along with a reasonable error message if we intend to ship this as is.
32dac24
to
52593c5
Compare
@swift-ci please smoke test |
vendor = 'unknown' | ||
|
||
try: | ||
output = shell.capture(["clang", "--version"]) |
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 concerns me. This is dependent on the value of -D LLVM_DEFALT_TARGET_TRIPLE
passed when building clang. Worse yet, it simply invokes clang
without any guarantees on which clang is being invoked. So, if I were to build a clang and add it to my path even on alpine, this could give me unknown
as the vendor or any other literal.
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.
What would be a more reliable alternative to this invocation then, in your opinion?
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 would say that you should consider exposing this as a flag that can be explicitly specified, defaulting to processing /etc/*-release
, /etc/os-release
, and lsb_release -b
. The default would only work under a non-cross-compiling scenario of course, but that applies to most cases for the default. We could expose this as a completely generic --default-target
flag perhaps.
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 changed it to use -print-target-triple
, which reliably gives us the actual triple and that's the only output it produces, so we don't need to do any additional parsing.
52593c5
to
d3768b3
Compare
26c62b6
to
1e37999
Compare
5e1b11c
to
5db8cee
Compare
37c40ec
to
4181a4c
Compare
4181a4c
to
b62eb2a
Compare
b62eb2a
to
4ce56d3
Compare
Currently, when building LLVM/clang on Alpine Linux, CMake toolchain file specifies incorrect `<cpu_arch>-unknown-linux-musl` target, which makes the build immediately fail. Correct target that allows building on Alpine should be specified as `<cpu_arch>-alpine-linux-musl`, with `<cpu_arch>` replaced with respective CPU platform, e.g. `aarch64`.
4ce56d3
to
501a5da
Compare
@swift-ci test |
@swift-ci build toolchain |
Currently, when building LLVM/clang on Alpine Linux, CMake toolchain file specifies incorrect
<cpu_arch>-unknown-linux-musl
target, which makes the build immediately fail. Correct target that allows building on Alpine should be specified as<cpu_arch>-alpine-linux-musl
, with<cpu_arch>
replaced with respective CPU platform, e.g.aarch64
.