diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift index a41a86e8..751e239e 100644 --- a/Benchmarks/Package.swift +++ b/Benchmarks/Package.swift @@ -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: "../") ], diff --git a/Benchmarks/Sources/Generated/ExportSwift.swift b/Benchmarks/Sources/Generated/BridgeJS.ExportSwift.swift similarity index 87% rename from Benchmarks/Sources/Generated/ExportSwift.swift rename to Benchmarks/Sources/Generated/BridgeJS.ExportSwift.swift index 9d4a8a9c..9d0a5181 100644 --- a/Benchmarks/Sources/Generated/ExportSwift.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.ExportSwift.swift @@ -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?, _ len: Int32) @_extern(wasm, module: "bjs", name: "init_memory") @@ -15,9 +16,14 @@ private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer? 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 } \ No newline at end of file diff --git a/Benchmarks/Sources/Generated/ImportTS.swift b/Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift similarity index 55% rename from Benchmarks/Sources/Generated/ImportTS.swift rename to Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift index 521c49c0..d7a6cf71 100644 --- a/Benchmarks/Sources/Generated/ImportTS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift @@ -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?, _ len: Int32) -> Int32 +func _make_jsstring(_ ptr: UnsafePointer?, _ len: Int32) -> Int32 +#else +func _make_jsstring(_ ptr: UnsafePointer?, _ 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?, _ len: Int32) +func _init_memory_with_result(_ ptr: UnsafePointer?, _ len: Int32) +#else +func _init_memory_with_result(_ ptr: UnsafePointer?, _ 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)) diff --git a/Benchmarks/Sources/Generated/JavaScript/ExportSwift.json b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.ExportSwift.json similarity index 100% rename from Benchmarks/Sources/Generated/JavaScript/ExportSwift.json rename to Benchmarks/Sources/Generated/JavaScript/BridgeJS.ExportSwift.json diff --git a/Benchmarks/Sources/Generated/JavaScript/ImportTS.json b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.ImportTS.json similarity index 100% rename from Benchmarks/Sources/Generated/JavaScript/ImportTS.json rename to Benchmarks/Sources/Generated/JavaScript/BridgeJS.ImportTS.json diff --git a/Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift b/Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift index c9ea8987..8353b5c4 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift @@ -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 + "/") } @@ -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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift b/Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift index f20f7837..88222a0e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift @@ -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", ] @@ -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", diff --git a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift index 04f4dcd4..3e6637a2 100644 --- a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift +++ b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift @@ -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) { @@ -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"), ] diff --git a/Tests/BridgeJSRuntimeTests/Generated/ExportSwift.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.ExportSwift.swift similarity index 100% rename from Tests/BridgeJSRuntimeTests/Generated/ExportSwift.swift rename to Tests/BridgeJSRuntimeTests/Generated/BridgeJS.ExportSwift.swift diff --git a/Tests/BridgeJSRuntimeTests/Generated/ImportTS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.ImportTS.swift similarity index 100% rename from Tests/BridgeJSRuntimeTests/Generated/ImportTS.swift rename to Tests/BridgeJSRuntimeTests/Generated/BridgeJS.ImportTS.swift diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/ExportSwift.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.ExportSwift.json similarity index 100% rename from Tests/BridgeJSRuntimeTests/Generated/JavaScript/ExportSwift.json rename to Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.ExportSwift.json diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/ImportTS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.ImportTS.json similarity index 100% rename from Tests/BridgeJSRuntimeTests/Generated/JavaScript/ImportTS.json rename to Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.ImportTS.json