Skip to content

Commit

Permalink
Add wasmtime as a default WASI runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Mar 9, 2024
1 parent d8efcdc commit de28dc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:

- name: Install dependencies for Ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install wabt -y
curl https://get.wasmer.io -sSfL | sh
run: sudo apt-get install wabt -y

- uses: bytecodealliance/actions/wasmtime/setup@v1

- name: Build the project
run: |
Expand All @@ -55,11 +55,6 @@ jobs:
cp -r static $HOME/.carton
- name: Run Tests
run: |
set -ex
if [ -e /home/runner/.wasmer/wasmer.sh ]; then
source /home/runner/.wasmer/wasmer.sh
fi
swift test
run: swift test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
brew "pre-commit"
brew "swiftformat"
brew "binaryen"
brew "wasmer"
brew "wabt"
17 changes: 16 additions & 1 deletion Sources/CartonCLI/Commands/TestRunners/CommandTestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ import CartonHelpers
import CartonKit
import Foundation

struct CommandTestRunnerError: Error, CustomStringConvertible {
let description: String

init(_ description: String) {
self.description = description
}
}

struct CommandTestRunner: TestRunner {
let testFilePath: AbsolutePath
let listTestCases: Bool
let testCases: [String]
let terminal: InteractiveWriter

func run() async throws {
let program = ProcessInfo.processInfo.environment["CARTON_TEST_RUNNER"] ?? "wasmer"
let program = try ProcessInfo.processInfo.environment["CARTON_TEST_RUNNER"] ?? defaultWASIRuntime()
terminal.write("\nRunning the test bundle with \"\(program)\":\n", inColor: .yellow)
var arguments = [program, testFilePath.pathString]
if listTestCases {
Expand All @@ -35,4 +43,11 @@ struct CommandTestRunner: TestRunner {
try await Process.run(arguments, parser: TestsParser(), terminal)
}

func defaultWASIRuntime() throws -> String {
let candidates = ["wasmtime", "wasmer"]
guard let found = candidates.lazy.compactMap({ Process.findExecutable($0) }).first else {
throw CommandTestRunnerError("No WASI runtime found. Please install one of the following: \(candidates.joined(separator: ", "))")
}
return found.pathString
}
}

0 comments on commit de28dc5

Please sign in to comment.