Skip to content

BridgeJS: Prefix generated files with "BridgeJS." #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025
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
7 changes: 7 additions & 0 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import PackageDescription

let package = Package(
name: "Benchmarks",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.macCatalyst(.v13),
],
dependencies: [
.package(path: "../")
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@_spi(JSObject_id) import JavaScriptKit

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "return_string")
private func _return_string(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
@_extern(wasm, module: "bjs", name: "init_memory")
Expand All @@ -15,9 +16,14 @@ private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer<UInt8>?
private func _swift_js_retain(_ ptr: Int32) -> Int32
@_extern(wasm, module: "bjs", name: "swift_js_throw")
private func _swift_js_throw(_ id: Int32)
#endif

@_expose(wasm, "bjs_run")
@_cdecl("bjs_run")
public func _bjs_run() -> Void {
#if arch(wasm32)
run()
#else
fatalError("Only available on WebAssembly")
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,57 @@

@_spi(JSObject_id) import JavaScriptKit

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "make_jsstring")
private func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32
func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32
#else
func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "init_memory_with_result")
private func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
#else
func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) {
fatalError("Only available on WebAssembly")
}
#endif

func benchmarkHelperNoop() -> Void {
#if arch(wasm32)
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop")
func bjs_benchmarkHelperNoop() -> Void
#else
func bjs_benchmarkHelperNoop() -> Void {
fatalError("Only available on WebAssembly")
}
#endif
bjs_benchmarkHelperNoop()
}

func benchmarkHelperNoopWithNumber(_ n: Double) -> Void {
#if arch(wasm32)
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber")
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
#else
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
fatalError("Only available on WebAssembly")
}
#endif
bjs_benchmarkHelperNoopWithNumber(n)
}

func benchmarkRunner(_ name: String, _ body: JSObject) -> Void {
#if arch(wasm32)
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner")
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
#else
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
fatalError("Only available on WebAssembly")
}
#endif
var name = name
let nameId = name.withUTF8 { b in
_make_jsstring(b.baseAddress.unsafelyUnwrapped, Int32(b.count))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
}

private func createExportSwiftCommand(context: PluginContext, target: SwiftSourceModuleTarget) throws -> Command {
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "ExportSwift.swift")
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "ExportSwift.json")
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ExportSwift.swift")
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ExportSwift.json")
let inputSwiftFiles = target.sourceFiles.filter {
!$0.url.path.hasPrefix(context.pluginWorkDirectoryURL.path + "/")
}
Expand Down Expand Up @@ -58,8 +58,8 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
}

private func createImportTSCommand(context: PluginContext, target: SwiftSourceModuleTarget) throws -> Command? {
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "ImportTS.swift")
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "ImportTS.json")
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ImportTS.swift")
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ImportTS.json")
let inputTSFile = target.directoryURL.appending(path: "bridge-js.d.ts")
guard FileManager.default.fileExists(atPath: inputTSFile.path) else {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ extension BridgeJSCommandPlugin.Context {
arguments: [
"export",
"--output-skeleton",
generatedJavaScriptDirectory.appending(path: "ExportSwift.json").path,
generatedJavaScriptDirectory.appending(path: "BridgeJS.ExportSwift.json").path,
"--output-swift",
generatedDirectory.appending(path: "ExportSwift.swift").path,
generatedDirectory.appending(path: "BridgeJS.ExportSwift.swift").path,
"--verbose",
options.verbose ? "true" : "false",
]
Expand All @@ -126,9 +126,9 @@ extension BridgeJSCommandPlugin.Context {
arguments: [
"import",
"--output-skeleton",
generatedJavaScriptDirectory.appending(path: "ImportTS.json").path,
generatedJavaScriptDirectory.appending(path: "BridgeJS.ImportTS.json").path,
"--output-swift",
generatedDirectory.appending(path: "ImportTS.swift").path,
generatedDirectory.appending(path: "BridgeJS.ImportTS.swift").path,
"--verbose",
options.verbose ? "true" : "false",
"--module-name",
Expand Down
6 changes: 3 additions & 3 deletions Plugins/PackageToJS/Sources/PackageToJSPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ class SkeletonCollector {

var exportedSkeletons: [URL] = []
var importedSkeletons: [URL] = []
let exportedSkeletonFile = "ExportSwift.json"
let importedSkeletonFile = "ImportTS.json"
let exportedSkeletonFile = "BridgeJS.ExportSwift.json"
let importedSkeletonFile = "BridgeJS.ImportTS.json"
let context: PluginContext

init(context: PluginContext) {
Expand Down Expand Up @@ -709,7 +709,7 @@ class SkeletonCollector {
let directories = [
target.directoryURL.appending(path: "Generated/JavaScript"),
// context.pluginWorkDirectoryURL: ".build/plugins/PackageToJS/outputs/"
// .build/plugins/outputs/exportswift/MyApp/destination/BridgeJS/ExportSwift.json
// .build/plugins/outputs/exportswift/MyApp/destination/BridgeJS/BridgeJS.ExportSwift.json
context.pluginWorkDirectoryURL.deletingLastPathComponent().deletingLastPathComponent()
.appending(path: "outputs/\(package.id)/\(target.name)/destination/BridgeJS"),
]
Expand Down