swiftlang / swift-sdk-generator

Generate Swift SDKs for cross-compilation
Apache License 2.0
182 stars 15 forks source link

generator/linux: Use `swiftResourcesPath` to find framework headers #139

Closed euanh closed 3 weeks ago

euanh commented 3 weeks ago

Building with a Swift 6.0 SDK fails because the new _FoundationCShims framework headers can't be found:

<unknown>:0: error: missing required module '_FoundationCShims'

The necessary files are present in $PLATFORM.sdk/usr/lib/swift, but are not part of the list which is copied to $PLATFORM.sdk/usr/include. The Static Linux SDK and WASM SDK generator don't copy these files into /usr/include; instead they set the swiftResourcesPath and swiftStaticResourcesPath fields in swift-sdk.json, which causes the build system to look in those paths for framework headers.

We can do the same for Linux SDKs, however we must stop copying the files to /usr/include, otherwise the build will fail because the framework header definitions are duplicated:

error: redefinition of module 'DispatchIntrospection'
 6 | }
 7 |
 8 | module DispatchIntrospection [system] [extern_c] {
   |        `- error: redefinition of module 'DispatchIntrospection'
 9 |    header "introspection.h"
10 |    export *

Partial fix for #138

euanh commented 3 weeks ago

@swift-ci test

euanh commented 3 weeks ago

How hard would it be to add a test for this to our test suite?

The EndToEnd test would already catch it if it was run with Swift 6.0, but we currently only run tests in CI on macOS:

https://github.com/swiftlang/swift-sdk-generator/blob/ea3e8245233856cfc22901fa6f9c28101ace5e54/Utilities/test.sh#L16C1-L20C3

...but the EndToEnd tests are skipped on macOS 😞:

https://github.com/swiftlang/swift-sdk-generator/blob/ea3e8245233856cfc22901fa6f9c28101ace5e54/Tests/SwiftSDKGeneratorTests/EndToEndTests.swift#L40

MaxDesiatov commented 3 weeks ago

I see, I'll try look into running tests on Linux then at some point.

euanh commented 3 weeks ago

I see, I'll try look into running tests on Linux then at some point.

I have another PR in progress to fix an ld-linux.so problem; after that I might have some time to spend on the CI. We should think about adopting the GitHub actions CI (https://github.com/swiftlang/github-workflows). For example: https://github.com/apple/swift-container-plugin/blob/main/.github/workflows/pull_request.yml

euanh commented 3 weeks ago

The EndToEnd test would already catch it if it was run with Swift 6.0

I think this would need a matrix job to set --swift-version 6.0-RELEASE (and other options). I don't think just building on Swift 6.0 is enough.