Skip to content
Draft
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
8 changes: 7 additions & 1 deletion .github/actions/install-swift/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ runs:
zlib1g-dev
curl

# Keep the toolchain's `<root>/usr/bin` layout intact. Flattening it into
# /usr/local breaks toolchain discovery in the swiftbuild build system,
# which derives the toolchain root by stripping `usr/bin` from `swiftc`.
- name: Install Swift
shell: bash
run: curl -fL ${{ inputs.download-url }} | sudo tar xfz - --strip-components=2 -C /usr/local
run: |
sudo mkdir -p /opt/swift
curl -fL ${{ inputs.download-url }} | sudo tar xfz - --strip-components=1 -C /opt/swift
echo "/opt/swift/usr/bin" >> "$GITHUB_PATH"
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ jobs:
entry:
- os: ubuntu-24.04
toolchain:
download-url: https://download.swift.org/development/ubuntu2404/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a-ubuntu24.04.tar.gz
download-url: https://download.swift.org/development/ubuntu2404/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a-ubuntu24.04.tar.gz
wasi-backend: Node
target: "wasm32-unknown-wasip1"
build-system: swiftbuild
env: |
JAVASCRIPTKIT_DISABLE_TRACING_TRAIT=1
- os: ubuntu-24.04
toolchain:
download-url: https://download.swift.org/swift-6.3-branch/ubuntu2404/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-03-05-a/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-03-05-a-ubuntu24.04.tar.gz
wasi-backend: Node
target: "wasm32-unknown-wasip1"
build-system: native
- os: ubuntu-22.04
toolchain:
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a-ubuntu22.04.tar.gz
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a-ubuntu22.04.tar.gz
wasi-backend: Node
target: "wasm32-unknown-wasip1-threads"
build-system: swiftbuild

runs-on: ${{ matrix.entry.os }}
env:
Expand All @@ -55,7 +58,7 @@ jobs:
echo "SWIFT_BIN_PATH=$(dirname $(which swiftc))" >> $GITHUB_ENV
- run: make bootstrap
- run: npm run test:runtime
- run: make unittest
- run: make unittest BUILD_SYSTEM=${{ matrix.entry.build-system }}
# Skip unit tests with uwasi because its proc_exit throws
# unhandled promise rejection.
if: ${{ matrix.entry.wasi-backend != 'MicroWASI' }}
Expand Down Expand Up @@ -144,7 +147,7 @@ jobs:
- uses: actions/checkout@v7
- uses: ./.github/actions/install-swift
with:
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a-ubuntu22.04.tar.gz
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a-ubuntu22.04.tar.gz
- run: make bootstrap
- run: ./Utilities/bridge-js-generate.sh
- name: Check if BridgeJS generated files are up-to-date
Expand Down Expand Up @@ -175,7 +178,7 @@ jobs:
- uses: actions/checkout@v7
- uses: ./.github/actions/install-swift
with:
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a-ubuntu22.04.tar.gz
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a-ubuntu22.04.tar.gz
- uses: swiftwasm/setup-swiftwasm@v2
id: setup-wasm32-unknown-wasip1
with: { target: wasm32-unknown-wasip1 }
Expand All @@ -198,7 +201,7 @@ jobs:
- uses: actions/checkout@v7
- uses: ./.github/actions/install-swift
with:
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a-ubuntu22.04.tar.gz
download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a/swift-DEVELOPMENT-SNAPSHOT-2026-08-11-a-ubuntu22.04.tar.gz
- uses: swiftwasm/setup-swiftwasm@v2
id: setup-wasm32-unknown-wasip1
with: { target: wasm32-unknown-wasip1 }
Expand Down
2 changes: 1 addition & 1 deletion Examples/PlayBridgeJS/Sources/PlayBridgeJS/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import class Foundation.JSONDecoder
let importTS = ImportTS(progress: .silent, moduleName: moduleName, skeleton: $0)
return try importTS.finalize()
}
let linker = BridgeJSLink(skeletons: [skeleton], sharedMemory: false)
let linker = BridgeJSLink(skeletons: [skeleton])
let linked = try linker.link()

return PlayBridgeJSOutput(
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SWIFT_SDK_ID ?=
BUILD_SYSTEM ?= swiftbuild
ifeq ($(JAVASCRIPTKIT_DISABLE_TRACING_TRAIT),1)
TRACING_ARGS :=
else
Expand All @@ -16,7 +17,7 @@ unittest:
echo "SWIFT_SDK_ID is not set. Run 'swift sdk list' and pass a matching SDK, e.g. 'make unittest SWIFT_SDK_ID=<id>'."; \
exit 2; \
}
swift package --build-system native --swift-sdk "$(SWIFT_SDK_ID)" \
swift package --build-system "$(BUILD_SYSTEM)" --swift-sdk "$(SWIFT_SDK_ID)" \
$(TRACING_ARGS) \
--disable-sandbox \
js test --prelude ./Tests/prelude.mjs -Xnode --expose-gc
Expand Down
11 changes: 4 additions & 7 deletions Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import BridgeJSUtilities

public struct BridgeJSLink {
var skeletons: [BridgeJSSkeleton] = []
let sharedMemory: Bool
/// Whether to track the lifetime of Swift objects.
///
/// This is useful for debugging memory issues.
Expand All @@ -19,11 +18,9 @@ public struct BridgeJSLink {
private let importedModuleRegistry = ImportedJSModuleRegistry()

public init(
skeletons: [BridgeJSSkeleton] = [],
sharedMemory: Bool = false
skeletons: [BridgeJSSkeleton] = []
) {
self.skeletons = skeletons
self.sharedMemory = sharedMemory
}

/// The identity mode from the config file, resolved from skeletons.
Expand Down Expand Up @@ -1173,7 +1170,7 @@ public struct BridgeJSLink {
}

/// Generates JavaScript output using CodeFragmentPrinter for better maintainability
private func generateJavaScript(data: LinkData) throws -> String {
private func generateJavaScript(data: LinkData, sharedMemory: Bool) throws -> String {
let header = """
// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
// DO NOT EDIT.
Expand Down Expand Up @@ -1346,7 +1343,7 @@ public struct BridgeJSLink {
return printer.lines.joined(separator: "\n")
}

public func link() throws -> (outputJs: String, outputDts: String) {
public func link(sharedMemory: Bool = false) throws -> (outputJs: String, outputDts: String) {
intrinsicRegistry.reset()
importedModuleRegistry.configure(skeletons: skeletons)
intrinsicRegistry.classNamespaces = skeletons.reduce(into: [:]) { result, unified in
Expand All @@ -1359,7 +1356,7 @@ public struct BridgeJSLink {
}
intrinsicRegistry.typeOwnerModules = collectTypeOwnerModules()
let data = try collectLinkData()
let outputJs = try generateJavaScript(data: data)
let outputJs = try generateJavaScript(data: data, sharedMemory: sharedMemory)
let outputDts = generateTypeScript(data: data)
return (outputJs, outputDts)
}
Expand Down
12 changes: 11 additions & 1 deletion Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@preconcurrency import func Foundation.fputs
@preconcurrency import func Foundation.open
@preconcurrency import func Foundation.strerror
@preconcurrency import var Foundation.stderr
@preconcurrency import var Foundation.errno
@preconcurrency import var Foundation.O_WRONLY
@preconcurrency import var Foundation.O_CREAT
Expand All @@ -15,6 +14,17 @@
@preconcurrency import class Foundation.FileManager
@preconcurrency import class Foundation.JSONDecoder
@preconcurrency import class Foundation.ProcessInfo

#if canImport(Darwin)
@preconcurrency import var Darwin.stderr
#elseif canImport(Glibc)
@preconcurrency import var Glibc.stderr
#elseif canImport(Musl)
@preconcurrency import var Musl.stderr
#elseif canImport(Android)
@preconcurrency import var Android.stderr
#endif

import SwiftParser
import SwiftSyntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import ArgumentParser
let skeletonData = try readData(from: skeletonFile)
skeletons.append(try JSONDecoder().decode(BridgeJSSkeleton.self, from: skeletonData))
}
let link = BridgeJSLink(skeletons: skeletons, sharedMemory: false)
let link = BridgeJSLink(skeletons: skeletons)
return try link.link()
}

Expand Down
14 changes: 6 additions & 8 deletions Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Testing
)
importSwift.addSourceFile(sourceFile, inputFilePath: "\(name).swift")
let importResult = try importSwift.finalize()
var bridgeJSLink = BridgeJSLink(sharedMemory: false)
var bridgeJSLink = BridgeJSLink()
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let unifiedData = try encoder.encode(importResult)
Expand Down Expand Up @@ -99,8 +99,7 @@ import Testing
let bridgeJSLink: BridgeJSLink = BridgeJSLink(
skeletons: [
outputSkeleton
],
sharedMemory: false
]
)
try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".Global")
}
Expand Down Expand Up @@ -133,8 +132,7 @@ import Testing
skeletons: [
globalSkeleton,
privateSkeleton,
],
sharedMemory: false
]
)
try snapshot(bridgeJSLink: bridgeJSLink, name: "MixedModules")
}
Expand All @@ -151,7 +149,7 @@ import Testing
)
importSwift.addSourceFile(sourceFile, inputFilePath: "\(name).swift")
let importResult = try importSwift.finalize()
var bridgeJSLink = BridgeJSLink(sharedMemory: false)
var bridgeJSLink = BridgeJSLink()
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let unifiedData = try encoder.encode(importResult)
Expand Down Expand Up @@ -182,7 +180,7 @@ import Testing
#expect(explicitlyUncachedClass?.identityMode == false)

// Verify generated JS via snapshot
let bridgeJSLink = BridgeJSLink(skeletons: [outputSkeleton], sharedMemory: false)
let bridgeJSLink = BridgeJSLink(skeletons: [outputSkeleton])
try snapshot(bridgeJSLink: bridgeJSLink, name: "IdentityModeClass.PerClass")
}

Expand All @@ -206,7 +204,7 @@ import Testing
#expect(explicitlyUncachedClass?.identityMode == false)

// Verify generated JS via snapshot
let bridgeJSLink = BridgeJSLink(skeletons: [outputSkeleton], sharedMemory: false)
let bridgeJSLink = BridgeJSLink(skeletons: [outputSkeleton])
try snapshot(bridgeJSLink: bridgeJSLink, name: "IdentityModeClass.ConfigPointer")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Testing
}

private func importLines(_ skeletons: [BridgeJSSkeleton]) throws -> [String] {
var link = BridgeJSLink(sharedMemory: false)
var link = BridgeJSLink()
let encoder = JSONEncoder()
for skeleton in skeletons {
_ = try link.addSkeletonFile(data: try encoder.encode(skeleton))
Expand Down
Loading
Loading