diff --git a/lit.cfg b/lit.cfg index afb28f2..040c41a 100644 --- a/lit.cfg +++ b/lit.cfg @@ -123,7 +123,7 @@ else: # that's possible if lit_config.params.get("have-network"): config.available_features.add("have-network") - + ### # Get the package path. @@ -162,6 +162,10 @@ if swiftpm_srcdir is None: if os.path.exists(swiftpm_srcdir): config.available_features.add("have-swiftpm") config.substitutions.append( ('%{swiftpm_srcdir}', swiftpm_srcdir) ) + config.substitutions.append( + ('%{swift-sdk-generator_srcdir}', os.path.join(swiftpm_srcdir, "..", "swift-sdk-generator")) + ) + config.substitutions.append( ('%{swiftpm_homedir}', os.path.join(os.environ['HOME'], ".swiftpm", "swift-sdks")) ) # Use the default Swift src layout if Swift the benchmark suite path is not # provided as a param. @@ -263,11 +267,13 @@ if swiftpm_build is not None: config.substitutions.append( ('%{swift-build}', os.path.join(swiftpm_build, "swift-build")) ) config.substitutions.append( ('%{swift-test}', os.path.join(swiftpm_build, "swift-test")) ) config.substitutions.append( ('%{swift-run}', os.path.join(swiftpm_build, "swift-run")) ) + config.substitutions.append( ('%{swift-sdk}', os.path.join(swiftpm_build, "swift-sdk")) ) else: config.substitutions.append( ('%{swift-package}', swift_path + ' package') ) config.substitutions.append( ('%{swift-build}', swift_path + ' build') ) config.substitutions.append( ('%{swift-test}', swift_path + ' test') ) config.substitutions.append( ('%{swift-run}', swift_path + ' run') ) + config.substitutions.append( ('%{swift-sdk}', swift_path + ' sdk') ) ### diff --git a/wasm/Hello/.gitignore b/wasm/Hello/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/wasm/Hello/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/wasm/Hello/Package.swift b/wasm/Hello/Package.swift new file mode 100644 index 0000000..028c6ff --- /dev/null +++ b/wasm/Hello/Package.swift @@ -0,0 +1,11 @@ +// swift-tools-version: 6.2 +import PackageDescription + +let package = Package( + name: "Hello", + targets: [ + .executableTarget( + name: "Hello" + ), + ] +) diff --git a/wasm/Hello/Sources/Hello/Hello.swift b/wasm/Hello/Sources/Hello/Hello.swift new file mode 100644 index 0000000..805404e --- /dev/null +++ b/wasm/Hello/Sources/Hello/Hello.swift @@ -0,0 +1,9 @@ +import WASILibc + +@main +struct Hello { + static func main() { + print("Hello, world!") + puts("Hello from WASILibc!") + } +} diff --git a/wasm/Hello/Tests/HelloTests/HelloTests.swift b/wasm/Hello/Tests/HelloTests/HelloTests.swift new file mode 100644 index 0000000..02c32f5 --- /dev/null +++ b/wasm/Hello/Tests/HelloTests/HelloTests.swift @@ -0,0 +1,13 @@ +import Testing +import XCTest +@testable import Hello + +@Test func example() async throws { + #expect(Int("42") == 42) +} + +final class HelloTests: XCTestCase { + func testExample() throws { + XCTAssertEqual(Int("42") == 42) + } +} diff --git a/wasm/swiftpm.md b/wasm/swiftpm.md new file mode 100644 index 0000000..b66de24 --- /dev/null +++ b/wasm/swiftpm.md @@ -0,0 +1,53 @@ +# SwiftPM checks for Wasm Swift SDKs + +This test can only run on Linux CI as we only build Swift SDK for Wasm on Linux CI nodes. + +``` +REQUIRES: platform=Linux +``` + +1. Let's install Swift SDK for Wasm first: + +``` +RUN: %{swift-sdk} list | %{FileCheck} --check-prefix CHECK-SDK-LIST-BEFORE %s +CHECK-SDK-LIST-BEFORE: No Swift SDKs are currently installed. +RUN: find "%{swift-sdk-generator_srcdir}/Bundles" -mindepth 1 -maxdepth 1 | xargs %{swift-sdk} install | %{FileCheck} --check-prefix CHECK-SDK-INSTALL %s +CHECK-SDK-INSTALL: Swift SDK bundle at +CHECK-SDK-INSTALL: successfully installed as +RUN: %{swift-sdk} list | grep wasm | wc -l | %{FileCheck} --check-prefix CHECK-SDK-LIST-AFTER %s +CHECK-SDK-LIST-AFTER: 2 +``` + +2. Using a prepared basic package that exercises Swift stdlib and `import WASILibc`: + +``` +RUN: rm -rf %t.dir +RUN: mkdir -p %t.dir +RUN: cp -r %S/Hello %t.dir +``` + +3. Building and running the prepared package: + + a) Non-embedded Swift SDK + + ``` + RUN: %{swift-sdk} list | grep -v embedded | xargs %{swift-run} --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-RUN-OUTPUT %s + CHECK-RUN-OUTPUT: Hello, world! + CHECK-RUN-OUTPUT-NEXT: Hello from WASILibc! + ``` + + b) Embedded Swift SDK + + ``` + RUN: %{swift-sdk} list | grep embedded | xargs %{swift-run} --package-path %t.dir/Hello --swift-sdk | %{FileCheck} --check-prefix CHECK-EMBEDDED-RUN-OUTPUT %s + CHECK-EMBEDDED-RUN-OUTPUT: Hello, world! + CHECK-EMBEDDED-RUN-OUTPUT-NEXT: Hello from WASILibc! + ``` + +4. Clean up installed Swift SDKs: + +``` +RUN: find %{swiftpm_homedir}/ -mindepth 1 -maxdepth 1 | xargs rm -rf +RUN: %{swift-sdk} list | %{FileCheck} --check-prefix CHECK-SDK-LIST-FINAL %s +CHECK-SDK-LIST-FINAL: No Swift SDKs are currently installed. +```