diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..6ec57b7 --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,52 @@ +name: Swift + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + macos: + name: macOS + runs-on: macos-26 + steps: + - uses: actions/checkout@v4 + # The runners' stable Xcode has an older Swift. Xcode gives the SDKs; + # the toolchain is swift.org's, as `.swift-version` pins it. + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - uses: SwiftyLab/setup-swift@latest + with: + swift-version: "6.4.2" + - name: Swift version + run: swift --version + - name: Build + run: swift build --build-tests + - name: Test + run: swift test --skip-build + - name: Test the WasmKit engine + working-directory: Packages/RuntimeWasm + run: swift test + - name: Test the scripts + run: python3 -m unittest discover -s Scripts -p 'test_*.py' + + linux: + name: Linux (${{ matrix.arch }}) + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + runner: ubuntu-24.04 + - arch: arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + container: swift:6.4.2-trixie + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build --build-tests + - name: Test + run: swift test --skip-build diff --git a/Packages/RuntimeWasm/Sources/RuntimeWasm/GuestMemory.swift b/Packages/RuntimeWasm/Sources/RuntimeWasm/GuestMemory.swift index 8fb886c..dd1b77e 100644 --- a/Packages/RuntimeWasm/Sources/RuntimeWasm/GuestMemory.swift +++ b/Packages/RuntimeWasm/Sources/RuntimeWasm/GuestMemory.swift @@ -30,13 +30,13 @@ struct GuestMemory { let count = Int(count) guard count > 0 else { return [] } try check(offset, count) - return memory.withUnsafeBufferPointer(offset: UInt(offset), count: count) { Array($0) } + return try memory.withUnsafeBufferPointer(offset: UInt(offset), count: count) { Array($0) } } func write(_ bytes: [UInt8], at offset: UInt32) throws { guard !bytes.isEmpty else { return } try check(offset, bytes.count) - memory.withUnsafeMutableBufferPointer(offset: UInt(offset), count: bytes.count) { buffer in + try memory.withUnsafeMutableBufferPointer(offset: UInt(offset), count: bytes.count) { buffer in buffer.copyBytes(from: bytes) } } diff --git a/Packages/RuntimeWasm/Sources/RuntimeWasm/WasmGL.swift b/Packages/RuntimeWasm/Sources/RuntimeWasm/WasmGL.swift index a59fc9e..47e976d 100644 --- a/Packages/RuntimeWasm/Sources/RuntimeWasm/WasmGL.swift +++ b/Packages/RuntimeWasm/Sources/RuntimeWasm/WasmGL.swift @@ -108,7 +108,7 @@ public final class WasmGL { } // GL doesn't call back into the guest, so its memory can't move // while the pointer is held. - let result = memory.withUnsafeMutableBufferPointer(offset: 0, count: memory.byteCount) { buffer in + let result = try memory.withUnsafeMutableBufferPointer(offset: 0, count: memory.byteCount) { buffer in context.base = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) context.size = UInt64(buffer.count) return rt_gl_call(&context, index, slots)