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
2 changes: 2 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSTool/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ extension BridgeType {
self = .string
case "Bool":
self = .bool
case "Void":
self = .void
default:
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion Plugins/PackageToJS/Templates/bin/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const harnesses = {
let options = await nodePlatform.defaultNodeSetup({
args: testFrameworkArgs,
onExit: (code) => {
if (code !== 0) {
// swift-testing returns EX_UNAVAILABLE (which is 69 in wasi-libc) for "no tests found"
if (code !== 0 && code !== 69) {
const stack = new Error().stack
console.error(`Test failed with exit code ${code}`)
console.error(stack)
Expand Down
4 changes: 4 additions & 0 deletions Tests/BridgeJSRuntimeTests/ExportAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import JavaScriptKit
@_extern(c)
func runJsWorks() -> Void

@JS func roundTripVoid() -> Void {
return
}

@JS func roundTripInt(v: Int) -> Int {
return v
}
Expand Down
11 changes: 11 additions & 0 deletions Tests/BridgeJSRuntimeTests/Generated/ExportSwift.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
// DO NOT EDIT.
//
// To update this file, just rebuild your project or run
// `swift package bridge-js`.
@_extern(wasm, module: "bjs", name: "return_string")
private func _return_string(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
@_extern(wasm, module: "bjs", name: "init_memory")
private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer<UInt8>?)

@_expose(wasm, "bjs_roundTripVoid")
@_cdecl("bjs_roundTripVoid")
public func _bjs_roundTripVoid() -> Void {
roundTripVoid()
}

@_expose(wasm, "bjs_roundTripInt")
@_cdecl("bjs_roundTripInt")
public func _bjs_roundTripInt(v: Int32) -> Int32 {
Expand Down
12 changes: 12 additions & 0 deletions Tests/BridgeJSRuntimeTests/Generated/JavaScript/ExportSwift.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
}
],
"functions" : [
{
"abiName" : "bjs_roundTripVoid",
"name" : "roundTripVoid",
"parameters" : [

],
"returnType" : {
"void" : {

}
}
},
{
"abiName" : "bjs_roundTripInt",
"name" : "roundTripInt",
Expand Down
1 change: 1 addition & 0 deletions Tests/prelude.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import assert from "node:assert";

/** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge.d.ts').Exports} exports */
function BridgeJSRuntimeTests_runJsWorks(instance, exports) {
exports.roundTripVoid();
for (const v of [0, 1, -1, 2147483647, -2147483648]) {
assert.equal(exports.roundTripInt(v), v);
}
Expand Down