Skip to content

Platforms that don't have "fat" multi-architecture binaries should place their runtime libraries in an arch-specific directory #63645

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

Open
finagolfin opened this issue Feb 14, 2023 · 7 comments
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. FreeBSD Platform: FreeBSD Linux Platform: Linux OpenBSD Platform: OpenBSD platform support standard library Area: Standard library umbrella swift 6.0 toolchain unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@finagolfin
Copy link
Member

Description
This is a long-standing issue where we cannot ship or link against the stdlib for different architectures in the same Swift resource directory, because the compiler places and adds a rpath to them in lib/swift/linux, not lib/swift/linux/x86_64 and lib/swift/linux/aarch64:

> find swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/lib_InternalSwiftStaticMirror.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Glibc.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Glibc.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Glibc.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Glibc.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_RegexParser.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_RegexParser.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_RegexParser.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_RegexParser.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so.65
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Concurrency.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Concurrency.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Concurrency.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Concurrency.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftSwiftOnoneSupport.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so.65.1
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/lib_InternalSwiftSyntaxParser.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so.65
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libFoundationNetworking.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Differentiation.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Differentiation.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Differentiation.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Differentiation.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libdispatch.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/RegexBuilder.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/RegexBuilder.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/RegexBuilder.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/RegexBuilder.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so.65.1
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswift_Differentiation.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Swift.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Swift.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Swift.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Swift.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswift_RegexParser.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_StringProcessing.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_StringProcessing.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_StringProcessing.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/_StringProcessing.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libFoundationXML.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libBlocksRuntime.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so.65
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libXCTest.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/lib_InternalSwiftScan.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so.65.1
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftDistributed.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftDispatch.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswift_Concurrency.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libFoundation.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftGlibc.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/SwiftOnoneSupport.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/SwiftOnoneSupport.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/SwiftOnoneSupport.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/SwiftOnoneSupport.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftRemoteMirror.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftRegexBuilder.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Distributed.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Distributed.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Distributed.swiftmodule/x86_64-unknown-linux-gnu.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/Distributed.swiftmodule/x86_64-unknown-linux-gnu.swiftinterface
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftCore.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswift_StringProcessing.so
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/Foundation.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/FoundationXML.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/FoundationXML.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/Foundation.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/Dispatch.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/Dispatch.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/glibc.modulemap
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/XCTest.swiftmodule
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/SwiftGlibc.h
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/FoundationNetworking.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/XCTest.swiftdoc
swift-5.7.3-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/FoundationNetworking.swiftmodule

@compnerd wrote about these issues when the problem was worse four years ago, and while some of that has since been fixed, this remaining issue of the runtime libraries location came up again last year.

Steps to reproduce

  1. Build the toolchain for linux x86_64 and install it.
  2. Build the toolchain for linux aarch64 and install it to the same directory (build-script currently does not support building two non-Darwin architectures at once, so it has to be run twice.).

Expected behavior
Both architectures' runtime libraries install fine. Instead, the latter will overwrite the former.

Environment

  • All Swift versions

Additional context
@compnerd fixed this for Windows already by installing the runtime libraries to arch-specific directories, and having the Swift driver look in those arch-specific directories instead when linking.

I've put together a similar pull for the Unix toolchain and it passes the compiler validation suite natively on Android, after updating some tests. I will submit it soon, once I get it to install the libraries properly when setting up the full toolchain, along with the needed modifications to the corelibs install.

@MaxDesiatov or @kateinoigakukun, what would you like to do for the wasm toolchain? I currently disable these changes in my pull for Darwin, which has fat libraries so doesn't need it, and WASI, because I don't know what that platform requires.

@finagolfin finagolfin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 14, 2023
@kateinoigakukun
Copy link
Member

@buttaface Thank you for working on this! It does not have a fat library format for WASI, so the same rule can be applied as well as for linux.

finagolfin added a commit to finagolfin/swift that referenced this issue Feb 20, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries like Darwin.

Resolves swiftlang#63645
finagolfin added a commit to finagolfin/swift-driver that referenced this issue Feb 20, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries
like Darwin. Also, add the new architecture-specific rpath to the resulting
swift-driver. This is the Swift translation of the Driver-specific changes of
swiftlang/swift#63782.

Resolves swiftlang/swift#63645
finagolfin added a commit to finagolfin/swift that referenced this issue Feb 23, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries like Darwin.

Resolves swiftlang#63645
finagolfin added a commit to finagolfin/swift that referenced this issue Mar 1, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries like Darwin.

Resolves swiftlang#63645
finagolfin added a commit to finagolfin/swift-driver that referenced this issue Mar 1, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries
like Darwin. Also, add the new architecture-specific rpath to the resulting
swift-driver. This is the Swift translation of the Driver-specific changes of
swiftlang/swift#63782.

Resolves swiftlang/swift#63645
finagolfin added a commit to finagolfin/swift-driver that referenced this issue Mar 6, 2023
…-specific directories

This is needed for all platforms that don't have multi-architecture libraries
like Darwin. Also, add the new architecture-specific rpath to the resulting
swift-driver and make it possible to cross-compile this repo for non-Darwin
platforms on Darwin.

The driver changes are the Swift translation of the Driver-specific changes of
swiftlang/swift#63782.

Resolves swiftlang/swift#63645
@finagolfin finagolfin added toolchain Linux Platform: Linux and removed triage needed This issue needs more specific labels labels Dec 8, 2024
@finagolfin
Copy link
Member Author

My linked pulls were rejected last year in favor of moving to full platform triples for the resource directory name instead, which nobody has yet implemented.

@AnthonyLatsis AnthonyLatsis added platform support unexpected behavior Bug: Unexpected behavior or incorrect output swift 6.0 labels Dec 8, 2024
@finagolfin finagolfin added standard library Area: Standard library umbrella Android Platform: Android FreeBSD Platform: FreeBSD OpenBSD Platform: OpenBSD labels Jan 16, 2025
@finagolfin
Copy link
Member Author

@etcwilde, can we move forward with this? Unfortunately, swiftlang/swift-driver#1667 hacked this back into the swift-driver again, over my objections, so that the upcoming Swift 6.1 toolchain also looks in <sdkRoot>/usr/lib/swift/<os>/<arch>/ for Swift runtime libraries if an -sdk is explicitly specified for Unix platforms, as it has to be when cross-compiling.

Compare what clang command the current 6.0.3 linux toolchain uses when linking with an -sdk:

> ./swift-6.0.3-RELEASE-fedora39/usr/bin/swiftc swift/test/Interpreter/hello_toplevel.swift -sdk swift-6.0.3-RELEASE-fedora39/ -Xclang-linker --sysroot=/ -v                                warning: Could not read SDKSettings.json for SDK at: /home/finagolfin/swift-6.0.3-RELEASE-fedora39
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu
/home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/bin/swift-frontend -frontend -c -primary-file swift/test/Interpreter/hello_toplevel.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -sdk /home/finagolfin/swift-6.0.3-RELEASE-fedora39 -color-diagnostics -empty-abi-descriptor -resource-dir /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/lib/swift -module-name hello_toplevel -plugin-path /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/lib/swift/host/plugins -plugin-path /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/local/lib/swift/host/plugins -o /tmp/TemporaryDirectory.PoXz3c/hello_toplevel-1.o
<unknown>:0: warning: libc not found for 'x86_64-unknown-linux-gnu'; C stdlib may be unavailable
/home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/bin/swift-autolink-extract /tmp/TemporaryDirectory.PoXz3c/hello_toplevel-1.o -o /tmp/TemporaryDirectory.PoXz3c/hello_toplevel-2.autolink
/home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/bin/clang -pie -Xlinker -rpath -Xlinker /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/lib/swift/linux /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/TemporaryDirectory.PoXz3c/hello_toplevel-1.o @/tmp/TemporaryDirectory.PoXz3c/hello_toplevel-2.autolink --sysroot /home/finagolfin/swift-6.0.3-RELEASE-fedora39 -L /home/finagolfin/swift-6.0.3-RELEASE-fedora39/usr/lib/swift/linux -lswiftCore --target=x86_64-unknown-linux-gnu -v --sysroot=/ -o hello_toplevel

to the slightly different clang flags with Swift 6.1:

> ./swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/bin/swiftc swift/test/Interpreter/hello_toplevel.swift -sdk swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/ -Xclang-linker --sysroot=/ -v
Swift version 6.1-dev (LLVM 3a45ba43180a40a, Swift d415967adc4eb7b)
Target: x86_64-unknown-linux-gnu
/home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/bin/swift-frontend -frontend -c -primary-file swift/test/Interpreter/hello_toplevel.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -sdk swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39 -color-diagnostics -empty-abi-descriptor -resource-dir /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift -module-name hello_toplevel -in-process-plugin-server-path /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/host/plugins -plugin-path /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/local/lib/swift/host/plugins -o /tmp/TemporaryDirectory.2bYVhp/hello_toplevel-1.o
<unknown>:0: warning: libc not found for 'x86_64-unknown-linux-gnu'; C stdlib may be unavailable
/home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/bin/swift-autolink-extract /tmp/TemporaryDirectory.2bYVhp/hello_toplevel-1.o -o /tmp/TemporaryDirectory.2bYVhp/hello_toplevel-2.autolink
/home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/bin/clang -pie -Xlinker --build-id -Xlinker -rpath -Xlinker /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux -L /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux -L /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux/x86_64 -L swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux -L swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux/x86_64 swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/TemporaryDirectory.2bYVhp/hello_toplevel-1.o @/tmp/TemporaryDirectory.2bYVhp/hello_toplevel-2.autolink --sysroot swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39 -L /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux -lswiftCore --target=x86_64-unknown-linux-gnu -v --sysroot=/ -o hello_toplevel

Specifically, the latter has a -L /home/finagolfin/swift-6.1-DEVELOPMENT-SNAPSHOT-2024-12-04-a-fedora39/usr/lib/swift/linux/x86_64 which the current 6.0.3 toolchain doesn't, which allows placing the Swift runtime libraries in that arch-specific directory instead. This was added because the BC devs are building multi-arch Android SDKs where they place the Swift runtime libraries in <sdkRoot>/usr/lib/swift/android/{aarch64,x86_64,...}, which you blocked when I submitted several toolchain pulls to implement that a year prior to that. Now, it's two years later and nobody has implemented your triple approach, while devs are trying to sneak this much smaller version of my approach back into swift-driver.

Evan, can you provide some direction here: have you changed your mind and now agree with putting the Swift runtime libraries for Unix and Windows in <sdkRoot>/usr/lib/swift/<os>/<arch>/? If so, we should implement it properly, as I tried to do with that series of linked toolchain pulls a couple years ago, not just hack it into the swift-driver in one place like Swift 6.1 currently does.

@weliveindetail
Copy link
Member

@finagolfin Clang runtime libs follow the new style with full target triples in the Windows toolchain. And swift-driver considers that now swiftlang/swift-driver@a9bf9bb Maybe it motivates progress for swift runtime libs?

@finagolfin
Copy link
Member Author

@finagolfin Clang runtime libs follow the new style with full target triples in the Windows toolchain

Yeah, I noticed that.

Maybe it motivates progress for swift runtime libs?

Actually implementing it in the toolchain is fairly easy, as you can see with the small changes in my linked pulls.

The main difficulty is in deciding precisely what triple to use for each platform version. For example, Swift for Android currently does not use the API version in the module triples and we get away with it because Swift provides no API versioning for Android, #76671, but once we do, would we need to start versioning the Swift modules too? I don't know and that's before getting into FreeBSD and the static Musl linux SDK and all the other targets out there.

@weliveindetail
Copy link
Member

we get away with it because Swift provides no API versioning for Android, #76671, but once we do, would we need to start versioning the Swift modules too?

No API versioning means that each toolchain version can only target one specific platform version right? (Or a range with stable ABI.) That has a lot of downsides, but it used to be ok in the past, because platforms either kept their ABIs stable('ish) or rebuilt the world for each release. If this is supposed to change, then yes, version everything that isn't ABI-stable = everything that doesn't get away with a fixed C interface = almost everything :) If Swift is serious about ABI resilience, then it might be able to avoid this versioning? I have no idea though to which extend that is reliable today.

@finagolfin
Copy link
Member Author

No API versioning means that each toolchain version can only target one specific platform version right? (Or a range with stable ABI.)

Replacing "each toolchain version" with "each SDK," as you well know we can ship multiple platform SDKs with a single toolchain, yes, that is mostly correct. There is an exception though in that if you pass in a versioned triple, the Swift compiler will pass that Android API version back to the C platform headers, so ClangImporter will give you the versioned C APIs you asked for. However, once you have to write Swift code that conditionally compiles or runs based on the Android API version, that is not possible, hence the linked issue.

If Swift is serious about ABI resilience, then it might be able to avoid this versioning?

Swift is only ABI-stable on Darwin platforms, nowhere else. However, this is a larger issue, as a platform can be ABI-stable and still add new APIs in later versions, so such versioning lets you use new APIs.

Anyway, getting back to the broader issue of using platform triples to fix this issue, this is an internal compiler directory that should mostly only ever be accessed by the compiler directly, so we can always make mistakes and change this solution later. However, some thought should go into how we do it the first time, as there will always be some external scripts and other tooling that will break every time we make a change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. FreeBSD Platform: FreeBSD Linux Platform: Linux OpenBSD Platform: OpenBSD platform support standard library Area: Standard library umbrella swift 6.0 toolchain unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
4 participants