Skip to content

C++ code fails to find libc++ headers using the WebAssembly Swift SDK #8465

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

Closed
1 task done
jakepetroules opened this issue Apr 8, 2025 · 3 comments · Fixed by #8468
Closed
1 task done

C++ code fails to find libc++ headers using the WebAssembly Swift SDK #8465

jakepetroules opened this issue Apr 8, 2025 · 3 comments · Fixed by #8468
Labels

Comments

@jakepetroules
Copy link
Contributor

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

Builds will fail to find standard C++ headers when using a WebAssembly Swift SDK.

This is due to the following code in SwiftPM passing a hardcoded sysroot (using --sysroot) for WASM triples:

/// Returns a default Swift SDK of a given target environment.
public static func defaultSwiftSDK(
    for targetTriple: Triple,
    hostSDK: SwiftSDK,
    environment: Environment = .current
) -> SwiftSDK? {
    if targetTriple.isWASI() {
        let wasiSysroot = hostSDK.toolset.rootPaths.first?
            .parentDirectory // usr
            .appending(components: "share", "wasi-sysroot")
        return SwiftSDK(
            targetTriple: targetTriple,
            toolset: hostSDK.toolset,
            pathsConfiguration: .init(sdkRootPath: wasiSysroot)
        )
    }

On my system, that expands to:

$HOME/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/share/wasi-sysroot

which does not exist. The actual path should be:

$HOME/Library/org.swift.swiftpm/swift-sdks/swift-wasm-6.1-RELEASE-wasm32-unknown-wasi.artifactbundle/6.1-RELEASE-wasm32-unknown-wasi/wasm32-unknown-wasi

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

  • git clone https://github.com/swiftlang/swift-build
  • cd swift-build
  • swift build --triple wasm32-unknown-wasi --swift-sdk swift-wasm-6.1-RELEASE-wasm32-unknown-wasi

Swift Package Manager version/commit hash

6.1-RELEASE

Swift & OS version (output of swift --version ; uname -a)

Apple Swift version 6.1 (swift-6.1-RELEASE)
Target: arm64-apple-macosx15.0

@jakepetroules
Copy link
Contributor Author

It looks like this "defaultSwiftSDK" function is actually behaving as a sort of override. Should the WASI branch in there simply be removed? @MaxDesiatov, I'm assuming you have the most knowledge in this area.

@MaxDesiatov
Copy link
Contributor

cc @kateinoigakukun

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Apr 8, 2025

So I think this issue can be split into two issues:

  1. --swift-sdk option is ignored when --triple is specified per --swift-sdk option cannot uniquely select a Swift SDK #7973
  2. Since we dropped support for Wasm "toolchain" (not Swift SDK for Wasm), the targetTriple.isWASI() branch no longer makes sense.

@jakepetroules jakepetroules linked a pull request Apr 9, 2025 that will close this issue
MaxDesiatov pushed a commit that referenced this issue Apr 9, 2025
Remove hardcoded WASI sysroot path derivation just for wasi-sysroot embedded in toolchains

### Motivation:

The previous implementation assumed there is $TOOLCHAIN_ROOT/share/wasi-sysroot when `--triple wasm32-unknown-wasi` is passed, but this is no longer the case with the [deprecation of the Wasm toolchain installation](swiftwasm/swift#5604) in favor of Swift SDKs.

Due to this unnecessary branch, when `--triple wasm32-unknown-wasi` is passed together with `--swift-sdk`, `--swift-sdk` is just ignored: #8465

### Modifications:

This change removes the hardcoded path derivation for the WASI sysroot from the `SwiftSDK.deriveTargetSwiftSDK` method.

### Result:

When `--triple wasm32-unknown-wasi` is passed without `--swift-sdk`, no user visible change and they will keep getting the following:
```
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: warning: libc not found for 'wasm32-unknown-wasi'; C stdlib may be unavailable
<unknown>:0: error: unable to load standard library for target 'wasm32-unknown-wasi'
```

When `--triple wasm32-unknown-wasi` is passed together with `--swift-sdk`, `--triple` is ignored and `--swift-sdk` is respected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants