Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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') )

###

Expand Down
8 changes: 8 additions & 0 deletions wasm/Hello/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
11 changes: 11 additions & 0 deletions wasm/Hello/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// swift-tools-version: 6.2
import PackageDescription

let package = Package(
name: "Hello",
targets: [
.executableTarget(
name: "Hello"
),
]
)
9 changes: 9 additions & 0 deletions wasm/Hello/Sources/Hello/Hello.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import WASILibc

@main
struct Hello {
static func main() {
print("Hello, world!")
puts("Hello from WASILibc!")
}
}
13 changes: 13 additions & 0 deletions wasm/Hello/Tests/HelloTests/HelloTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
53 changes: 53 additions & 0 deletions wasm/swiftpm.md
Original file line number Diff line number Diff line change
@@ -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. Creating a package from `init` template:

```
RUN: rm -rf %t.dir
RUN: mkdir -p %t.dir
RUN: cp -r %S/Hello %t.dir
```

3. Building and running prepared `"Hello, world!"` executable from the newly created 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 SDK:

```
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.
Comment on lines +50 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit scary to remove the shared Swift SDK directory in a test tbh 😅 How about isolating SDK installation directory by --swift-sdks-path %t/swift-sdks or whatever?

```