swiftwasm / swift

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

Support WASILibc in SwiftPM's test runner #5551

Closed kateinoigakukun closed 4 months ago

kateinoigakukun commented 8 months ago

SwiftPM recently introduced a new test runner and it does not support WASILibc for now. https://github.com/apple/swift-package-manager/blob/dafbae563ff2fe827ac5d3285dae718d7c7fc6b4/Sources/Build/TestObservation.swift#L126-L135

kateinoigakukun commented 8 months ago

We need to unlock Data.write Foundation APIs, and also make O_CREAT available through WASILibc module.

/tmp/tmp.EY6vzcLx5z/.build/wasm32-unknown-wasi/debug/ExamplePackageTests.derived/runner.swift:31:31: error: value of type 'Data' has no member 'write'
                _ = try? data.write(to: URL(fileURLWithPath: self.testOutputPath))
                         ~~~~ ^~~~~
/tmp/tmp.EY6vzcLx5z/.build/wasm32-unknown-wasi/debug/ExamplePackageTests.derived/runner.swift:162:53: error: cannot find 'O_CREAT' in scope
            let fd = open(lockFile.path, O_WRONLY | O_CREAT | O_CLOEXEC, 0o666)
                                                    ^~~~~~~
/home/katei/ghq/work.katei.dev/swiftwasm-source/swift-wasm-DEVELOPMENT-SNAPSHOT-2023-10-31-a/usr/share/wasi-sysroot/include/__header_fcntl.h:13:9: note: macro 'O_CREAT' unavailable: structure not supported
#define O_CREAT (__WASI_OFLAGS_CREAT << 12)
        ^
/tmp/tmp.EY6vzcLx5z/.build/wasm32-unknown-wasi/debug/ExamplePackageTests.derived/runner.swift:396:42: error: value of type 'Bundle' has no member 'bundleIdentifier'
            bundleIdentifier: testBundle.bundleIdentifier,
                              ~~~~~~~~~~ ^~~~~~~~~~~~~~~~
kateinoigakukun commented 4 months ago

Resolved by https://github.com/swiftwasm/swiftwasm-build/pull/226 https://github.com/apple/swift-package-manager/pull/7341