Skip to content

Commit

Permalink
Update WASM CI to run for wasi target (#37)
Browse files Browse the repository at this point in the history
* Update WASM CI to run for wasi target

* Fix swift-testing version

* Add test helper target

* Update warning as errors config

* Fix os(WASI) build issue
  • Loading branch information
Kyle-Ye authored Feb 18, 2024
1 parent ce294c1 commit 0313a7c
Show file tree
Hide file tree
Showing 28 changed files with 99 additions and 46 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
swift-version: ${{ matrix.swift_version }}
- name: build
run: |
swift build ${{ matrix.extra_params }}
swift build --triple wasm32-unknown-wasi ${{ matrix.extra_params }}
# Blocked by upstream support for WASM. See https://github.com/apple/swift-testing/issues/228
# - name: test
# run: |
# swift test
# swift test --triple wasm32-unknown-wasi ${{ matrix.extra_params }}
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "8f0376278186b6e24e8d7a07a560f3efaa2fef1d"
"revision" : "8cc89abc1fff74b387a083eab8ffa91f1b9fdca7"
}
},
{
Expand Down
68 changes: 47 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,63 @@
import Foundation
import PackageDescription

let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
guard let value = Context.environment[key] else {
return defaultValue
}
if value == "1" {
return true
} else if value == "0" {
return false
} else {
return defaultValue
}
}

let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"

// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"

var sharedSwiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
]

let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv)
if warningsAsErrorsCondition {
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
}

let openSwiftUITarget = Target.target(
name: "OpenSwiftUI",
dependencies: [
"OpenSwiftUIShims",
.target(name: "CoreServices", condition: .when(platforms: [.iOS])),
.product(name: "OpenGraphShims", package: "OpenGraph"),
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
]
swiftSettings: sharedSwiftSettings
)
let openSwiftUITestTarget = Target.testTarget(
name: "OpenSwiftUITests",
dependencies: [
"OpenSwiftUI",
],
exclude: ["README.md"]
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
)
let openSwiftUITempTestTarget = Target.testTarget(
name: "OpenSwiftUITempTests",
dependencies: [
"OpenSwiftUI",
],
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
)
let openSwiftUICompatibilityTestTarget = Target.testTarget(
name: "OpenSwiftUICompatibilityTests",
exclude: ["README.md"]
exclude: ["README.md"],
swiftSettings: sharedSwiftSettings
)

let package = Package(
Expand Down Expand Up @@ -64,19 +95,6 @@ let package = Package(
]
)

func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
return defaultValue
}
if value == "1" {
return true
} else if value == "0" {
return false
} else {
return defaultValue
}
}

#if os(macOS)
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
#else
Expand All @@ -98,6 +116,7 @@ extension Target {
if attributeGraphCondition {
openSwiftUITarget.addAGSettings()
openSwiftUITestTarget.addAGSettings()
openSwiftUITempTestTarget.addAGSettings()
openSwiftUICompatibilityTestTarget.addAGSettings()
}

Expand Down Expand Up @@ -139,12 +158,19 @@ if swiftLogCondition {
let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING", default: true)
if swiftTestingCondition {
package.dependencies.append(
.package(url: "https://github.com/apple/swift-testing", from: "0.3.0")
// Fix it to be 0.3.0 before we bump to Swift 5.10
.package(url: "https://github.com/apple/swift-testing", exact: "0.3.0")
)
openSwiftUITestTarget.dependencies.append(
.product(name: "Testing", package: "swift-testing")
)
package.targets.append(openSwiftUITestTarget)

openSwiftUITempTestTarget.dependencies.append(
.product(name: "Testing", package: "swift-testing")
)
package.targets.append(openSwiftUITempTestTarget)

openSwiftUICompatibilityTestTarget.dependencies.append(
.product(name: "Testing", package: "swift-testing")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ private func KitRendererCommon() -> Never {
#elseif os(macOS)
// FIXME
let code = NSApplicationMain(argc, argv)
#elseif os(Linux)
#else
let code: Int32 = 1
#endif
exit(code)
}

#if canImport(Darwin)
func currentAppName() -> String {
if let name = Bundle.main.localizedValue(for: "CFBundleDisplayName") {
return name
Expand All @@ -90,3 +91,4 @@ extension Bundle {
}
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Internal/Graph/TODO/_GraphInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct _GraphInputs {
var changedDebugProperties: _ViewDebug.Properties
var options: _GraphInputs.Options
// FIXME: Compile crash on Linux
#if !os(Linux)
#if canImport(Darwin)
var mergedInputs: Set<OGAttribute>
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Internal/Other/EnvironmentHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif os(WASI)
import WASILibc
#else
#error("Unsupported Platform")
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/_BenchmarkHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/UIElements/Font/TODO/Font.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/UIElements/Text/TODO/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Views/Animations/TODO/Animatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension Animatable where AnimatableData == EmptyAnimatableData {

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension Double: VectorArithmetic {

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Views/View/ViewTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Views/View/_IdentifiedViewProxy.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUIShims/include/LockedPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define OPENSWIFTUI_LOCK_INIT OS_UNFAIR_LOCK_INIT
#define OPENSWIFTUI_LOCK_LOCK(lock) os_unfair_lock_lock(lock)
#define OPENSWIFTUI_LOCK_UNLOCK(lock) os_unfair_lock_unlock(lock)
#elif OPENSWIFTUI_TARGET_OS_LINUX
#else
#define OPENSWIFTUI_LOCK_T int32_t
#include <stdint.h>
#include <unistd.h>
Expand Down
7 changes: 7 additions & 0 deletions Tests/OpenSwiftUITempTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## OpenSwiftUITempTests

A temporary test target to iterate new test case.

Remove this once the IDE support for swift-testing is provided.

Please do not commit any new files to this folder.
15 changes: 15 additions & 0 deletions Tests/OpenSwiftUITempTests/Scaffolding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Scaffolding.swift
//
//
// Created by Kyle on 2023/11/8.
//

import Testing
import XCTest

final class AllTests: XCTestCase {
func testAll() async {
await XCTestScaffold.runAllTests(hostedBy: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Testing
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down
2 changes: 1 addition & 1 deletion Tests/OpenSwiftUITests/_ViewDebugTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Testing
#if canImport(Darwin)
import CoreGraphics
#elseif os(Linux)
#else
import Foundation
#endif

Expand Down

0 comments on commit 0313a7c

Please sign in to comment.