From 32f6057b7c642802fe39b93007cb687f80f2e535 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 4 Mar 2024 15:34:42 -0800 Subject: [PATCH] Address more Wasm issues (#77) * 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 --- .github/workflows/ci.yml | 10 ++---- Sources/XCTestDynamicOverlay/XCTFail.swift | 36 +++++++++++-------- .../GeneratePlaceholderTests.swift | 2 +- .../UnimplementedTests.swift | 2 +- .../XCTContextTests.swift | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fbff14e..56808df3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/swiftwasm-action@v5.7 + - uses: swiftwasm/swiftwasm-action@v5.9 with: - shell-action: swift build + shell-action: carton test windows: name: Windows diff --git a/Sources/XCTestDynamicOverlay/XCTFail.swift b/Sources/XCTestDynamicOverlay/XCTFail.swift index 4f68b4d5..e4602e6a 100644 --- a/Sources/XCTestDynamicOverlay/XCTFail.swift +++ b/Sources/XCTestDynamicOverlay/XCTFail.swift @@ -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? { @@ -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 diff --git a/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift b/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift index c42f373a..2dac2b0a 100644 --- a/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift +++ b/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift @@ -1,4 +1,4 @@ -#if !os(Linux) && !os(Windows) +#if !os(Linux) && !os(WASI) && !os(Windows) import Foundation import XCTest import XCTestDynamicOverlay diff --git a/Tests/XCTestDynamicOverlayTests/UnimplementedTests.swift b/Tests/XCTestDynamicOverlayTests/UnimplementedTests.swift index 546dfcfc..8c8b76a4 100644 --- a/Tests/XCTestDynamicOverlayTests/UnimplementedTests.swift +++ b/Tests/XCTestDynamicOverlayTests/UnimplementedTests.swift @@ -1,4 +1,4 @@ -#if !os(Linux) && !os(Windows) +#if !os(Linux) && !os(WASI) && !os(Windows) import XCTest final class UnimplementedTests: XCTestCase { diff --git a/Tests/XCTestDynamicOverlayTests/XCTContextTests.swift b/Tests/XCTestDynamicOverlayTests/XCTContextTests.swift index 610f200b..0ee2908d 100644 --- a/Tests/XCTestDynamicOverlayTests/XCTContextTests.swift +++ b/Tests/XCTestDynamicOverlayTests/XCTContextTests.swift @@ -1,4 +1,4 @@ -#if !os(Linux) && !os(Windows) +#if !os(Linux) && !os(WASI) && !os(Windows) import XCTest import XCTestDynamicOverlay