swiftwasm / swift

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

wasm lacks signal support #5592

Open Kyle-Ye opened 2 months ago

Kyle-Ye commented 2 months ago
In file included from /home/runner/work/xx/xx.h:51:
In file included from /opt/hostedtoolcache/swiftwasm/wasm-6.0-SNAPSHOT-2024-09-18-a/x86_64/usr/lib/swift/CoreFoundation/CoreFoundation.h:28:
/opt/hostedtoolcache/swiftwasm/wasm-6.0-SNAPSHOT-2024-09-18-a/x86_64/usr/share/wasi-sysroot/include/signal.h:2:2: error: "wasm lacks signal support; to enable minimal signal emulation, compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal"
    2 | #error "wasm lacks signal support; to enable minimal signal emulation, \
      |  ^
1 error generated.

I'm dropping support for Swift 5.10 for all supported platform in my package.

Since WASM does not have a corresponding release yet. I'm switching to the latest 6.0 snapshot wasm-6.0-SNAPSHOT-2024-09-18-a toolchain. And I hit with the above error.

Is there some extra param I can use to workaround it like https://github.com/swiftwasm/swift/issues/5563#issuecomment-1913533592?

Kyle-Ye commented 2 months ago

Solved by adding the them to my Package.swift

cSettings: [
...
+ .define("_WASI_EMULATED_SIGNAL", to: "1", .when(platforms: [.wasi]))
],
linkerSettings: [
...
+ .unsafeFlags(["wasi-emulated-signal"], .when(platforms: [.wasi])),
]
),

But then encounter other issue then. (Build and run test fine with normal Linux build)

eg.

# Host OS: Ubuntu 22.04 & swift sdk download the correct WASM SDK
swift build --triple wasm32-unknown-wasi
/toolchain/swift-6.0/usr/lib/swift/CoreFoundation/CoreFoundation.h:16:10: fatal error: 'sys/types.h' file not found
   16 | #include <sys/types.h>
# Host OS: Ubuntu 22.04 & swift sdk download the correct WASM SDK
swift build --swift-sdk 6.0-SNAPSHOT-2024-09-18-a-wasm32-unknown-wasi
warning: Could not read SDKSettings.json for SDK at: /home/kyle/.swiftpm/swift-sdks/swift-wasm-6.0-SNAPSHOT-2024-09-18-a-wasm32-unknown-wasi.artifactbundle/6.0-SNAPSHOT-2024-09-18-a-wasm32-unknown-wasi/wasm32-unknown-wasi/WASI.sdk
Swift version 6.0 (swift-6.0-RELEASE)
Target: wasm32-unknown-wasi
...

<unknown>:0: error: module compiled with Swift 6.0.2 cannot be imported by the Swift 6.0 compiler: xx

I guess I should wait for a final release 6.0 of WASM and test it again.

Kyle-Ye commented 1 week ago

Still encounter this after I tried the latest 6.0.2 release.

This will happen when I try to include the CoreFoundation header. It used to work on 5.x version.