swiftlang / swift-testing

A modern, expressive testing package for Swift
Apache License 2.0
1.81k stars 77 forks source link

WASI: Access to `EEXIST` through a stub getter function #800

Closed kateinoigakukun closed 3 weeks ago

kateinoigakukun commented 3 weeks ago

Build fix for WASI

Motivation:

Use of errno values in Swift without libc overlay is not supported with wasi-libc.

https://ci.swift.org/job/oss-swift-pr-test-crosscompile-wasm-ubuntu-20_04/1784/console

/home/build-user/swift-testing/Sources/Testing/Attachments/Test.Attachment.swift:249:61: error: cannot find 'EEXIST' in scope
247 |           result = preferredPath
248 |           break
249 |         } catch let error as CError where error.rawValue == EEXIST {
    |                                                             `- error: cannot find 'EEXIST' in scope
250 |           // Try again with a new suffix.
251 |           continue

Modifications:

This change introduces a new function swt_EEXIST to get the value of EEXIST because it is a complex macro in wasi-libc and cannot be imported directly into Swift.

Result:

WASI build will be repaired.

Checklist:

kateinoigakukun commented 3 weeks ago

@swift-ci test

grynspan commented 3 weeks ago

Fixes issue introduced in #796.

grynspan commented 3 weeks ago

@kateinoigakukun Seems like the Musl Swift overlay should (re)define these error codes so they're visible to Swift?

kateinoigakukun commented 3 weeks ago

@grynspan The complex errno code definitions exist only in wasi-libc, not in musl. And we already define these error codes in WASILibc overlay module but not used them here to follow the porting policy

grynspan commented 3 weeks ago

Fair enough. Just mentioning it in case it wasn't already handled and other projects could run into trouble. :)