Skip to content

Cross-compiling tests with 6.1 Swift SDK results in linking error when host toolchain is 6.0 #8388

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
xtremekforever opened this issue Mar 19, 2025 · 4 comments
Labels

Comments

@xtremekforever
Copy link

xtremekforever commented Mar 19, 2025

Description

This is a bit of a meta-issue that I've only seen when cross-compiling with a Swift SDK, but it's very interesting.

So, if I have a Swift SDK generated for a snapshot version of 6.1 (generated using the swift-sdk-generator), and try to compile the tests in a project that use the Testing module, I get an error about the object file not being able to be found. For example, I have a project that contains a single test and does import Testing at the top of it:

import Testing

@testable import swift_test_output

@Test func myTestFunctionReturns() {
    #expect(myTestFunction() == "a random string")
}

When I compile this with the Swift SDK, when my host toolchain is Swift 6.0.3, I get the following error:

$ swift build --swift-sdk 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_ubuntu_jammy_aarch64 --build-tests
Building for debugging...
error: Failed opening '~/swift-test-output/.build/aarch64-unknown-linux-gnu/debug/index/store/v5/units/mainTests.swift.o-1WQSNCFA94D5H': No such file or directory
[10/19] Wrapping AST for swift-test-output-tests for debugging
$ swift --version
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu

What's interesting is that this doesn't happen if I change my host toolchain to a 6.1 snapshot. For example:

$ swift --version
Swift version 6.1-dev (LLVM 08670c03fe16573, Swift 493744d5e4900b2)
Target: x86_64-unknown-linux-gnu
$ swift build --swift-sdk 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_ubuntu_jammy_aarch64 --build-tests
[1/1] Planning build
Building for debugging...
[20/20] Linking swift-test-outputPackageTests.xctest
Build complete! (4.65s)

So, it seems to be some kind of mismatch in how the object is compiled when the Testing module is involved. However, I am not sure why this happens.

Reproduction

  1. With a version of Swift 6.0 installed, checkout the swift-sdk-generator, and create a Swift SDK for a 6.1 snapshot like this: swift run swift-sdk-generator make-linux-sdk --swift-version 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a --swift-branch swift-6.1-branch --host-toolchain --target aarch64-unknown-linux-gnu
  2. Install it: swift sdk install /path/to/swift-sdk-generator/Bundles/6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_ubuntu_jammy_aarch64.artifactbundle
  3. Take a Swift 6.0 project that uses Swift Testing for unit tests. Compile it using the Swift SDK and pass --build-tests: swift build --swift-sdk 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a_ubuntu_jammy_aarch64 --build-tests
  4. Observe that the test files that do import Testing then show the error: <testFile>.swift.o-1WQSNCFA94D5H': No such file or directory

Expected behavior

I would expect that if you cross-compile a project with tests that use Swift Testing, that a difference in the Swift version installed on the host and the one inside of the toolchain would NOT cause an error. If the Swift SDK includes the host toolchain, that should be used to compile for the target instead of the one installed on the host itself.

Environment

Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Linux ella-linux 6.8.0-55-generic swiftlang/swift-testing#57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Additional information

Maybe this isn't an issue in the Testing module itself, but in swift-frontend or somewhere else up the chain. If so, please let me know where this belongs.

ALSO: This error does not occur if the project uses XCTest for unit tests and does not depend on Swift Testing.

@xtremekforever xtremekforever changed the title Cross-compiling tests with 6.1 Swift SDK results in linking error when host toolchain is 6.0.x Cross-compiling tests with 6.1 Swift SDK results in linking error when host toolchain is 6.0 Mar 19, 2025
@grynspan
Copy link
Contributor

Sending to the SwiftPM team as the reported error is not produced by Swift Testing.

In general, the Swift project does not guarantee any form of ABI stability on Linux, so building with one toolchain and running with another likely wouldn't work for various other reasons, especially if the toolchain used for building is newer than the one used for running.

@grynspan grynspan transferred this issue from swiftlang/swift-testing Mar 19, 2025
@dschaefer2
Copy link
Member

Weird that it's failing on the index store. But yes, mixing toolchain versions usually doesn't work, though with more obvious error messages.

@xtremekforever
Copy link
Author

Sending to the SwiftPM team as the reported error is not produced by Swift Testing.

In general, the Swift project does not guarantee any form of ABI stability on Linux, so building with one toolchain and running with another likely wouldn't work for various other reasons, especially if the toolchain used for building is newer than the one used for running.

Thanks, I wasn't sure if this was related to how Swift Testing is built or just SwiftPM itself. It only ever happens with Swift Testing, which was indicating to me that perhaps some part of Swift Testing that is in the host installed toolchain (essentially the one you are using to run the swift build command) is being used, instead of the one from inside the Swift SDK.

@xtremekforever
Copy link
Author

Weird that it's failing on the index store. But yes, mixing toolchain versions usually doesn't work, though with more obvious error messages.

Well the thing is it should be possible with a Swift SDK, because it includes the same version of Swift as what you are cross-compiling for. So in this Swift SDK it'll have:

  • Swift toolchain 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a for Linux x86_64
  • Swift toolchain 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a for Ubuntu Jammy AARCH64

And it should be using the Swift toolchain 6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a for Linux x86_64 to compile everything for Ubuntu Jammy AARCH64. So, this indicates a bug in perhaps SwiftPM, since it is somehow not using the full toolchain from the Swift SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants