Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
./Vendor/checkout-dependency --category component-model

swift --version
swift test --sanitize address --traits ComponentModel,WasmDebuggingSupport ${{ matrix.test-args }}
swift test --sanitize address --traits FileSystem,ComponentModel,WasmDebuggingSupport ${{ matrix.test-args }}
swift build --package-path Benchmarks

build-macos:
Expand All @@ -71,7 +71,7 @@ jobs:
# Swift 6.3.2
- os: macos-26
xcode: Xcode_26.5
test-args: "--sanitize address --traits ComponentModel,WasmDebuggingSupport"
test-args: "--sanitize address --traits FileSystem,ComponentModel,WasmDebuggingSupport"

runs-on: ${{ matrix.os }}
name: "build-macos (${{ matrix.xcode }})"
Expand Down Expand Up @@ -132,15 +132,15 @@ jobs:
matrix:
include:
- swift: "swift:6.3-noble"
test-args: "--traits ComponentModel,WasmDebuggingSupport --enable-code-coverage"
test-args: "--traits FileSystem,ComponentModel,WasmDebuggingSupport --enable-code-coverage"
build-benchmarks: true
run-benchmarks: true
build-dev-dashboard: true
- swift: "swiftlang/swift:nightly-6.4.x-noble"
test-args: "--traits ComponentModel,WasmDebuggingSupport"
test-args: "--traits FileSystem,ComponentModel,WasmDebuggingSupport"
build-benchmarks: true
- swift: "swiftlang/swift:nightly-main-noble"
test-args: "--traits ComponentModel,WasmDebuggingSupport"
test-args: "--traits FileSystem,ComponentModel,WasmDebuggingSupport"
build-benchmarks: true

runs-on: ubuntu-24.04
Expand Down Expand Up @@ -234,9 +234,9 @@ jobs:
run: ./build-exec swift sdk install "${{ matrix.musl-swift-sdk-download }}" --checksum "${{ matrix.musl-swift-sdk-checksum }}"

- name: Build (x86_64-swift-linux-musl)
run: ./build-exec swift build --swift-sdk x86_64-swift-linux-musl --traits ComponentModel,WasmDebuggingSupport --explicit-target-dependency-import-check error
run: ./build-exec swift build --swift-sdk x86_64-swift-linux-musl --traits FileSystem,ComponentModel,WasmDebuggingSupport --explicit-target-dependency-import-check error
- name: Build (aarch64-swift-linux-musl)
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl --traits ComponentModel,WasmDebuggingSupport --explicit-target-dependency-import-check error
run: ./build-exec swift build --swift-sdk aarch64-swift-linux-musl --traits FileSystem,ComponentModel,WasmDebuggingSupport --explicit-target-dependency-import-check error

build-android:
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -297,4 +297,4 @@ jobs:
- name: Install Swift SDK
run: swift sdk install https://download.swift.org/swift-6.3.2-release/wasm-sdk/swift-6.3.2-RELEASE/swift-6.3.2-RELEASE_wasm.artifactbundle.tar.gz --checksum a61f0584c93283589f8b2f42db05c1f9a182b506c2957271402992655591dd7c
- name: Build with the Swift SDK
run: swift build --swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm" --traits ComponentModel --explicit-target-dependency-import-check error --product wasmkit-cli
run: swift build --swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm" --traits FileSystem,ComponentModel --explicit-target-dependency-import-check error --product wasmkit-cli
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ add_compile_definitions(
include(FetchContent)

option(WASMKIT_BUILD_CLI "Build wasmkit-cli" ON)
option(WASMKIT_ENABLE_FILESYSTEM "Enable FileSystem support" ON)

if(WASMKIT_BUILD_CLI)
set(BUILD_TESTING OFF) # disable ArgumentParser tests
Expand Down
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ let package = Package(
.library(name: "_CabiShims", targets: ["_CabiShims"]),
],
traits: [
.default(enabledTraits: []),
.default(enabledTraits: ["FileSystem"]),
"FileSystem",
"ComponentModel",
"WasmDebuggingSupport",
],
Expand Down Expand Up @@ -112,7 +113,10 @@ let package = Package(
name: "WasmParser",
dependencies: [
"WasmTypes",
.product(name: "SystemPackage", package: "swift-system"),
.product(
name: "SystemPackage", package: "swift-system",
condition: .when(traits: ["FileSystem"])
),
.target(
name: "ComponentModel",
condition: .when(traits: ["ComponentModel"])
Expand Down
6 changes: 6 additions & 0 deletions Sources/WasmKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_wasmkit_library(WasmKit
Imports.swift
Module.swift
ModuleParser.swift
ModuleParser+FileSystem.swift
SIMDOpcode.swift
Translator.swift
Validator.swift
Expand Down Expand Up @@ -47,5 +48,10 @@ add_wasmkit_library(WasmKit
Execution/V128Storage.swift
)

if(WASMKIT_ENABLE_FILESYSTEM)
target_compile_options(WasmKit PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-D;FileSystem>)
endif()

target_link_wasmkit_libraries(WasmKit PUBLIC
_CWasmKit WasmParser SystemExtras WasmTypes SystemPackage)
29 changes: 16 additions & 13 deletions Sources/WasmKit/Execution/ParsedComponentBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
#if ComponentModel
import ComponentModel
import SystemPackage
import WasmParser

// MARK: - Component Parsing

/// Parse a component binary file from a caller-owned file descriptor.
///
/// The descriptor is consumed from its current offset and is not closed by
/// this function.
public func parseComponent(
fileHandle: FileDescriptor,
features: WasmFeatureSet = .default
) throws -> ParsedComponent {
let stream = try FileHandleStream(fileHandle: fileHandle)
return try parseComponent(stream: stream, features: features)
}

/// Parse a component binary into a `ParsedComponent` ready for instantiation.
///
/// This function converts the streaming `ComponentParser` output into a
Expand Down Expand Up @@ -609,3 +596,19 @@
}

#endif

#if ComponentModel && FileSystem
import struct SystemPackage.FileDescriptor

/// Parse a component binary file from a caller-owned file descriptor.
///
/// The descriptor is consumed from its current offset and is not closed by
/// this function.
public func parseComponent(
fileHandle: FileDescriptor,
features: WasmFeatureSet = .default
) throws -> ParsedComponent {
let stream = try FileHandleStream(fileHandle: fileHandle)
return try parseComponent(stream: stream, features: features)
}
#endif
38 changes: 38 additions & 0 deletions Sources/WasmKit/ModuleParser+FileSystem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if FileSystem
import WasmParser
import SystemExtras
import SystemPackage

#if os(Windows)
import ucrt
#endif

/// Parse a given file as a WebAssembly binary format file
/// > Note: <https://webassembly.github.io/spec/core/binary/index.html>
public func parseWasm(filePath: FilePath, features: WasmFeatureSet = .default) throws -> Module {
#if os(Windows)
// TODO: Upstream `O_BINARY` to `SystemPackage
let accessMode = FileDescriptor.AccessMode(
rawValue: FileDescriptor.AccessMode.readOnly.rawValue | O_BINARY
)
#else
let accessMode: FileDescriptor.AccessMode = .readOnly
#endif
let fileHandle = try FileDescriptor.open(filePath, accessMode)
return try withThrowing {
try parseWasm(fileHandle: fileHandle, features: features)
} defer: {
try fileHandle.close()
}
}

/// Parse a WebAssembly binary file from a caller-owned file descriptor.
///
/// The descriptor is consumed from its current offset and is not closed by
/// this function.
public func parseWasm(fileHandle: FileDescriptor, features: WasmFeatureSet = .default) throws -> Module {
let stream = try FileHandleStream(fileHandle: fileHandle)
let module = try parseModule(stream: stream, features: features)
return module
}
#endif
35 changes: 0 additions & 35 deletions Sources/WasmKit/ModuleParser.swift
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import SystemExtras
import SystemPackage
import WasmParser

#if os(Windows)
import ucrt
#endif

/// Parse a given file as a WebAssembly binary format file
/// > Note: <https://webassembly.github.io/spec/core/binary/index.html>
public func parseWasm(filePath: FilePath, features: WasmFeatureSet = .default) throws -> Module {
#if os(Windows)
// TODO: Upstream `O_BINARY` to `SystemPackage
let accessMode = FileDescriptor.AccessMode(
rawValue: FileDescriptor.AccessMode.readOnly.rawValue | O_BINARY
)
#else
let accessMode: FileDescriptor.AccessMode = .readOnly
#endif
let fileHandle = try FileDescriptor.open(filePath, accessMode)
return try withThrowing {
try parseWasm(fileHandle: fileHandle, features: features)
} defer: {
try fileHandle.close()
}
}

/// Parse a WebAssembly binary file from a caller-owned file descriptor.
///
/// The descriptor is consumed from its current offset and is not closed by
/// this function.
public func parseWasm(fileHandle: FileDescriptor, features: WasmFeatureSet = .default) throws -> Module {
let stream = try FileHandleStream(fileHandle: fileHandle)
let module = try parseModule(stream: stream, features: features)
return module
}

/// Parse a given byte array as a WebAssembly binary format file
/// > Note: <https://webassembly.github.io/spec/core/binary/index.html>
public func parseWasm(bytes: [UInt8], features: WasmFeatureSet = .default) throws(WasmKitError) -> Module {
Expand Down
10 changes: 9 additions & 1 deletion Sources/WasmParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ add_wasmkit_library(WasmParser
)

target_link_wasmkit_libraries(WasmParser PUBLIC
SystemExtras WasmTypes SystemPackage)
WasmTypes)

if(WASMKIT_ENABLE_FILESYSTEM)
target_compile_options(WasmParser PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-D;FileSystem>)
target_link_wasmkit_libraries(WasmParser PUBLIC
SystemPackage)
endif()

Loading
Loading