swiftwasm / swift

WebAssembly support for the Swift programming language
https://swiftwasm.org
1.28k stars 28 forks source link

Cannot import Foundation when using a host platform independent SDK #5579

Closed kkebo closed 2 months ago

kkebo commented 2 months ago

The latest Swift SDK for main snapshots has become host platform independent. However, it seems that it is no longer possible to build even a simple Swift package if it depends on the Foundation module.

$ swift --version
Swift version 6.0-dev (LLVM 01231f56c62f4c4, Swift abaa63821080b92)
Target: aarch64-unknown-linux-gnu
$ swift experimental-sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-14-a/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-14-a-wasm32-unknown-wasi.artifactbundle.zip
$ swift experimental-sdk list
DEVELOPMENT-SNAPSHOT-2024-04-14-a-wasm32-unknown-wasi
$ mkdir wasi-demo
$ cd wasi-demo
$ swift package init --type executable --name WASIDemo
Creating executable package: WASIDemo                                                                                                                                                   
Creating Package.swift                                                                                                                                                                  
Creating .gitignore                                                                                                                                                                     
Creating Sources/                                                                                                                                                                       
Creating Sources/main.swift
$ echo 'import Foundation' > Sources/main.swift
$ swift build --experimental-swift-sdk wasm32-unknown-wasi
Building for debugging...
...
error: link command failed with exit code 1 (use -v to see invocation)
wasm-ld: error: unable to find library -licui18n
wasm-ld: error: unable to find library -licuuc
wasm-ld: error: unable to find library -licudata
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[7/8] Linking WASIDemo.wasm

Environment:

$ uname -a
Linux Brown-rhinoceros-beetle 6.6.3-414.asahi.fc39.aarch64+16k #1 SMP PREEMPT_DYNAMIC Sun Mar 24 19:44:17 UTC 2024 aarch64 GNU/Linux
$ cat /etc/os-release
NAME="Fedora Linux Asahi Remix"
VERSION="39 (Thirty Nine)"
ID=fedora-asahi-remix
ID_LIKE=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
PRETTY_NAME="Fedora Linux Asahi Remix 39 (Thirty Nine)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora-asahi-remix:39"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedora-asahi-remix.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/"
SUPPORT_URL="https://discussion.fedoraproject.org/c/neighbors/asahi/asahi-help/94"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=39
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=39
kkebo commented 2 months ago

swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-13-a-wasm32-unknown-wasi.artifactbundle.zip was the same.

https://github.com/kkebo/swift-format/actions/runs/8679713190/job/23798959295?pr=31

kkebo commented 2 months ago

Previous Swift SDKs that were not host platform independent seem to have these libraries, but the new Swift SDKs do not seem to have them.

$ find ~/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-05-a-ubuntu20.04_aarch64.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-04-05-a-wasm/wasm32-unknown-wasi/swift.xctoolchain/ -name "*icu*"
/home/kebo/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-05-a-ubuntu20.04_aarch64.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-04-05-a-wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/libicui18n.a
/home/kebo/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-05-a-ubuntu20.04_aarch64.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-04-05-a-wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/libicudata.a
/home/kebo/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-05-a-ubuntu20.04_aarch64.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-04-05-a-wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift_static/wasi/libicuuc.a
$ find ~/.swiftpm/swift-sdks/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-14-a-wasm32-unknown-wasi.artifactbundle/DEVELOPMENT-SNAPSHOT-2024-04-14-a-wasm32-unknown-wasi/wasm32-unknown-wasi/swift.xctoolchain/ -name "*icu*"
kateinoigakukun commented 2 months ago

Thanks! I didn't notice that. https://github.com/swiftwasm/swiftwasm-build/commit/7c4a7c513eb512b0ad69517da4fc94f6d444d036 will hopefully fix this

kkebo commented 2 months ago

Thank you for fixing it so quickly! I'll give it a try when the next Swift SDK comes out.

kateinoigakukun commented 2 months ago

https://github.com/swiftwasm/swift/releases/tag/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-04-15-b will solve this

kkebo commented 2 months ago

I've confirmed that the issue has been resolved in DEVELOPMENT-SNAPSHOT-2024-04-15-b-wasm32-unknown-wasi.