Skip to content

Commit 44939d8

Browse files
Merge pull request #386 from swiftwasm/pr-5935e12666f1a5529ae63464c2fe58777793feec
BridgeJS: Prefix generated files with "BridgeJS."
2 parents f2f46e6 + ac5c225 commit 44939d8

File tree

12 files changed

+56
-13
lines changed

12 files changed

+56
-13
lines changed

Benchmarks/Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import PackageDescription
44

55
let package = Package(
66
name: "Benchmarks",
7+
platforms: [
8+
.macOS(.v10_15),
9+
.iOS(.v13),
10+
.tvOS(.v13),
11+
.watchOS(.v6),
12+
.macCatalyst(.v13),
13+
],
714
dependencies: [
815
.package(path: "../")
916
],

Benchmarks/Sources/Generated/ExportSwift.swift renamed to Benchmarks/Sources/Generated/BridgeJS.ExportSwift.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@_spi(JSObject_id) import JavaScriptKit
88

9+
#if arch(wasm32)
910
@_extern(wasm, module: "bjs", name: "return_string")
1011
private func _return_string(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
1112
@_extern(wasm, module: "bjs", name: "init_memory")
@@ -15,9 +16,14 @@ private func _init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer<UInt8>?
1516
private func _swift_js_retain(_ ptr: Int32) -> Int32
1617
@_extern(wasm, module: "bjs", name: "swift_js_throw")
1718
private func _swift_js_throw(_ id: Int32)
19+
#endif
1820
1921
@_expose(wasm, "bjs_run")
2022
@_cdecl("bjs_run")
2123
public func _bjs_run() -> Void {
24+
#if arch(wasm32)
2225
run()
26+
#else
27+
fatalError("Only available on WebAssembly")
28+
#endif
2329
}

Benchmarks/Sources/Generated/ImportTS.swift renamed to Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,57 @@
66

77
@_spi(JSObject_id) import JavaScriptKit
88

9+
#if arch(wasm32)
910
@_extern(wasm, module: "bjs", name: "make_jsstring")
10-
private func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32
11+
func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32
12+
#else
13+
func _make_jsstring(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) -> Int32 {
14+
fatalError("Only available on WebAssembly")
15+
}
16+
#endif
1117

18+
#if arch(wasm32)
1219
@_extern(wasm, module: "bjs", name: "init_memory_with_result")
13-
private func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
20+
func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32)
21+
#else
22+
func _init_memory_with_result(_ ptr: UnsafePointer<UInt8>?, _ len: Int32) {
23+
fatalError("Only available on WebAssembly")
24+
}
25+
#endif
1426

1527
func benchmarkHelperNoop() -> Void {
28+
#if arch(wasm32)
1629
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop")
1730
func bjs_benchmarkHelperNoop() -> Void
31+
#else
32+
func bjs_benchmarkHelperNoop() -> Void {
33+
fatalError("Only available on WebAssembly")
34+
}
35+
#endif
1836
bjs_benchmarkHelperNoop()
1937
}
2038

2139
func benchmarkHelperNoopWithNumber(_ n: Double) -> Void {
40+
#if arch(wasm32)
2241
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber")
2342
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
43+
#else
44+
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
45+
fatalError("Only available on WebAssembly")
46+
}
47+
#endif
2448
bjs_benchmarkHelperNoopWithNumber(n)
2549
}
2650

2751
func benchmarkRunner(_ name: String, _ body: JSObject) -> Void {
52+
#if arch(wasm32)
2853
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner")
2954
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
55+
#else
56+
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
57+
fatalError("Only available on WebAssembly")
58+
}
59+
#endif
3060
var name = name
3161
let nameId = name.withUTF8 { b in
3262
_make_jsstring(b.baseAddress.unsafelyUnwrapped, Int32(b.count))

Plugins/BridgeJS/Sources/BridgeJSBuildPlugin/BridgeJSBuildPlugin.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct BridgeJSBuildPlugin: BuildToolPlugin {
2424
}
2525

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

6060
private func createImportTSCommand(context: PluginContext, target: SwiftSourceModuleTarget) throws -> Command? {
61-
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "ImportTS.swift")
62-
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "ImportTS.json")
61+
let outputSwiftPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ImportTS.swift")
62+
let outputSkeletonPath = context.pluginWorkDirectoryURL.appending(path: "BridgeJS.ImportTS.json")
6363
let inputTSFile = target.directoryURL.appending(path: "bridge-js.d.ts")
6464
guard FileManager.default.fileExists(atPath: inputTSFile.path) else {
6565
return nil

Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ extension BridgeJSCommandPlugin.Context {
106106
arguments: [
107107
"export",
108108
"--output-skeleton",
109-
generatedJavaScriptDirectory.appending(path: "ExportSwift.json").path,
109+
generatedJavaScriptDirectory.appending(path: "BridgeJS.ExportSwift.json").path,
110110
"--output-swift",
111-
generatedDirectory.appending(path: "ExportSwift.swift").path,
111+
generatedDirectory.appending(path: "BridgeJS.ExportSwift.swift").path,
112112
"--verbose",
113113
options.verbose ? "true" : "false",
114114
]
@@ -126,9 +126,9 @@ extension BridgeJSCommandPlugin.Context {
126126
arguments: [
127127
"import",
128128
"--output-skeleton",
129-
generatedJavaScriptDirectory.appending(path: "ImportTS.json").path,
129+
generatedJavaScriptDirectory.appending(path: "BridgeJS.ImportTS.json").path,
130130
"--output-swift",
131-
generatedDirectory.appending(path: "ImportTS.swift").path,
131+
generatedDirectory.appending(path: "BridgeJS.ImportTS.swift").path,
132132
"--verbose",
133133
options.verbose ? "true" : "false",
134134
"--module-name",

Plugins/PackageToJS/Sources/PackageToJSPlugin.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ class SkeletonCollector {
667667

668668
var exportedSkeletons: [URL] = []
669669
var importedSkeletons: [URL] = []
670-
let exportedSkeletonFile = "ExportSwift.json"
671-
let importedSkeletonFile = "ImportTS.json"
670+
let exportedSkeletonFile = "BridgeJS.ExportSwift.json"
671+
let importedSkeletonFile = "BridgeJS.ImportTS.json"
672672
let context: PluginContext
673673

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy