Skip to content

Commit

Permalink
Address more Wasm issues (#77)
Browse files Browse the repository at this point in the history
* Fix SwiftWasm Glibc import issue

SwiftWasm introduced its own WASI module awhile back, so we should
import that instead of Glibc to avoid potential issues.

* Fix WASI import

* wip

* fix

* wip
  • Loading branch information
stephencelis authored Mar 4, 2024
1 parent b13b1d1 commit 32f6057
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ jobs:
wasm:
name: Wasm
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { toolchain: wasm-5.7.1-RELEASE }

steps:
- uses: actions/checkout@v4
- run: echo "${{ matrix.toolchain }}" > .swift-version
- uses: swiftwasm/[email protected]
- uses: swiftwasm/[email protected]
with:
shell-action: swift build
shell-action: carton test

windows:
name: Windows
Expand Down
36 changes: 21 additions & 15 deletions Sources/XCTestDynamicOverlay/XCTFail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,20 @@ public struct XCTFailContext: Sendable {
}
}

#if os(Windows)
#if canImport(Glibc)
import Glibc

private func ResolveXCTFail() -> XCTFailType? {
var hXCTest = dlopen("libXCTest.so", RTLD_NOW)
if hXCTest == nil { hXCTest = dlopen(nil, RTLD_NOW) }

if let pXCTFail = dlsym(hXCTest, "$s6XCTest7XCTFail_4file4lineySS_s12StaticStringVSutF") {
return unsafeCastToXCTFailType(pXCTFail)
}

return nil
}
#elseif canImport(WinSDK)
import WinSDK

private func ResolveXCTFail() -> XCTFailType? {
Expand All @@ -180,22 +193,15 @@ public struct XCTFailContext: Sendable {

return nil
}
#else
#if os(WASI)
import WASI
#else
import Glibc
#endif
#elseif canImport(XCTest)
import XCTest

private func ResolveXCTFail() -> XCTFailType? {
var hXCTest = dlopen("libXCTest.so", RTLD_NOW)
if hXCTest == nil { hXCTest = dlopen(nil, RTLD_NOW) }

if let pXCTFail = dlsym(hXCTest, "$s6XCTest7XCTFail_4file4lineySS_s12StaticStringVSutF") {
return unsafeCastToXCTFailType(pXCTFail)
}

return nil
XCTFail
}
#else
private func ResolveXCTFail() -> XCTFailType? {
nil
}
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(Linux) && !os(Windows)
#if !os(Linux) && !os(WASI) && !os(Windows)
import Foundation
import XCTest
import XCTestDynamicOverlay
Expand Down
2 changes: 1 addition & 1 deletion Tests/XCTestDynamicOverlayTests/UnimplementedTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(Linux) && !os(Windows)
#if !os(Linux) && !os(WASI) && !os(Windows)
import XCTest

final class UnimplementedTests: XCTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/XCTestDynamicOverlayTests/XCTContextTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(Linux) && !os(Windows)
#if !os(Linux) && !os(WASI) && !os(Windows)
import XCTest
import XCTestDynamicOverlay

Expand Down

0 comments on commit 32f6057

Please sign in to comment.