Skip to content

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

Open
@xtremekforever

Description

@xtremekforever

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions