GeezerVison is showing github.com — revert to cdecl-based exports for swift 5.10 compatibility · swiftwasm/JavaScriptKit@025b9fc
File treeExpand file treeCollapse file tree Open diff view settings Embedded/Sources/EmbeddedApp
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Examples/Basic/Package.swift +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,9 @@ import PackageDescription | 4 | 4 |
| 5 | 5 | let package = Package( | 6 | 6 | name: "Basic", | | 7 | + platforms: [ | | 8 | + .macOS(.v14) | | 9 | + ], | 7 | 10 | dependencies: [.package(name: "JavaScriptKit", path: "../../")], | 8 | 11 | targets: [ | 9 | 12 | .executableTarget( | |
Collapse file Copy file name to clipboardExpand all lines: Examples/Embedded/Sources/EmbeddedApp/_thingsThatShouldNotBeNeeded.swift +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,9 +2,9 @@ import JavaScriptKit | 2 | 2 |
| 3 | 3 | // NOTE: it seems the embedded tree shaker gets rid of these exports if they are not used somewhere | 4 | 4 | func _i_need_to_be_here_for_wasm_exports_to_work() { | 5 | | - _ = _library_features | 6 | | - _ = _call_host_function_impl | 7 | | - _ = _free_host_function_impl | | 5 | + _ = _swjs_library_features | | 6 | + _ = _swjs_call_host_function | | 7 | + _ = _swjs_free_host_function | 8 | 8 | } | 9 | 9 |
| 10 | 10 | // TODO: why do I need this? and surely this is not ideal... figure this out, or at least have this come from a C lib | |
Collapse file Copy file name to clipboardExpand all lines: Sources/JavaScriptKit/Features.swift +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,11 +2,17 @@ enum LibraryFeatures { | 2 | 2 | static let weakRefs: Int32 = 1 << 0 | 3 | 3 | } | 4 | 4 |
| 5 | | -@_expose(wasm, "swjs_library_features") | 6 | | -public func _library_features() -> Int32 { | | 5 | +@_cdecl("_library_features") | | 6 | +func _library_features() -> Int32 { | 7 | 7 | var features: Int32 = 0 | 8 | 8 | #if !JAVASCRIPTKIT_WITHOUT_WEAKREFS | 9 | 9 | features |= LibraryFeatures.weakRefs | 10 | 10 | #endif | 11 | 11 | return features | 12 | 12 | } | | 13 | + | | 14 | +#if hasFeature(Embedded) | | 15 | +// cdecls currently don't work in embedded, and expose for wasm only works >=6.0 | | 16 | +@_expose(wasm, "swjs_library_features") | | 17 | +public func _swjs_library_features() -> Int32 { _library_features() } | | 18 | +#endif |
Collapse file Copy file name to clipboardExpand all lines: Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift +24-6Lines changed: 24 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -186,8 +186,8 @@ private func makeAsyncClosure(_ body: @escaping ([JSValue]) async throws -> JSVa | 186 | 186 | // └─────────────────────┴──────────────────────────┘ | 187 | 187 |
| 188 | 188 | /// Returns true if the host function has been already released, otherwise false. | 189 | | -@_expose(wasm, "swjs_call_host_function") | 190 | | -public func _call_host_function_impl( | | 189 | +@_cdecl("_call_host_function_impl") | | 190 | +func _call_host_function_impl( | 191 | 191 | _ hostFuncRef: JavaScriptHostFuncRef, | 192 | 192 | _ argv: UnsafePointer<RawJSValue>, _ argc: Int32, | 193 | 193 | _ callbackFuncRef: JavaScriptObjectRef | @@ -217,8 +217,9 @@ extension JSClosure { | 217 | 217 | } | 218 | 218 | } | 219 | 219 |
| 220 | | -@_expose(wasm, "swjs_free_host_function") | 221 | | -public func _free_host_function_impl(_ hostFuncRef: JavaScriptHostFuncRef) {} | | 220 | + | | 221 | +@_cdecl("_free_host_function_impl") | | 222 | +func _free_host_function_impl(_ hostFuncRef: JavaScriptHostFuncRef) {} | 222 | 223 |
| 223 | 224 | #else | 224 | 225 |
| @@ -229,8 +230,25 @@ extension JSClosure { | 229 | 230 |
| 230 | 231 | } | 231 | 232 |
| 232 | | -@_expose(wasm, "swjs_free_host_function") | 233 | | -public func _free_host_function_impl(_ hostFuncRef: JavaScriptHostFuncRef) { | | 233 | +@_cdecl("_free_host_function_impl") | | 234 | +func _free_host_function_impl(_ hostFuncRef: JavaScriptHostFuncRef) { | 234 | 235 | JSClosure.sharedClosures[hostFuncRef] = nil | 235 | 236 | } | 236 | 237 | #endif | | 238 | + | | 239 | +#if hasFeature(Embedded) | | 240 | +// cdecls currently don't work in embedded, and expose for wasm only works >=6.0 | | 241 | +@_expose(wasm, "swjs_call_host_function") | | 242 | +public func _swjs_call_host_function( | | 243 | + _ hostFuncRef: JavaScriptHostFuncRef, | | 244 | + _ argv: UnsafePointer<RawJSValue>, _ argc: Int32, | | 245 | + _ callbackFuncRef: JavaScriptObjectRef) -> Bool { | | 246 | + | | 247 | + _call_host_function_impl(hostFuncRef, argv, argc, callbackFuncRef) | | 248 | +} | | 249 | + | | 250 | +@_expose(wasm, "swjs_free_host_function") | | 251 | +public func _swjs_free_host_function(_ hostFuncRef: JavaScriptHostFuncRef) { | | 252 | + _free_host_function_impl(hostFuncRef) | | 253 | +} | | 254 | +#endif |
Collapse file Copy file name to clipboardExpand all lines: Sources/_CJavaScriptKit/_CJavaScriptKit.c +32-6Lines changed: 32 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,13 @@ extern void *memcpy (void *__restrict, const void *__restrict, size_t); | 13 | 13 | #include <stdbool.h> | 14 | 14 |
| 15 | 15 | #endif | | 16 | +/// The compatibility runtime library version. | | 17 | +/// Notes: If you change any interface of runtime library, please increment | | 18 | +/// this and `SwiftRuntime.version` in `./Runtime/src/index.ts`. | | 19 | +__attribute__((export_name("swjs_library_version"))) | | 20 | +int swjs_library_version(void) { | | 21 | + return 708; | | 22 | +} | 16 | 23 |
| 17 | 24 | __attribute__((export_name("swjs_prepare_host_function_call"))) | 18 | 25 | void *swjs_prepare_host_function_call(const int argc) { | @@ -24,14 +31,33 @@ void swjs_cleanup_host_function_call(void *argv_buffer) { | 24 | 31 | free(argv_buffer); | 25 | 32 | } | 26 | 33 |
| 27 | | -/// The compatibility runtime library version. | 28 | | -/// Notes: If you change any interface of runtime library, please increment | 29 | | -/// this and `SwiftRuntime.version` in `./Runtime/src/index.ts`. | 30 | | -__attribute__((export_name("swjs_library_version"))) | 31 | | -int swjs_library_version(void) { | 32 | | - return 708; | | 34 | +#ifndef __Embedded | | 35 | +// cdecls don't work in Embedded, also @_expose(wasm) can be used with Swift >=6.0 | | 36 | +bool _call_host_function_impl(const JavaScriptHostFuncRef host_func_ref, | | 37 | + const RawJSValue *argv, const int argc, | | 38 | + const JavaScriptObjectRef callback_func); | | 39 | + | | 40 | +__attribute__((export_name("swjs_call_host_function"))) | | 41 | +bool swjs_call_host_function(const JavaScriptHostFuncRef host_func_ref, | | 42 | + const RawJSValue *argv, const int argc, | | 43 | + const JavaScriptObjectRef callback_func) { | | 44 | + return _call_host_function_impl(host_func_ref, argv, argc, callback_func); | | 45 | +} | | 46 | + | | 47 | +void _free_host_function_impl(const JavaScriptHostFuncRef host_func_ref); | | 48 | + | | 49 | +__attribute__((export_name("swjs_free_host_function"))) | | 50 | +void swjs_free_host_function(const JavaScriptHostFuncRef host_func_ref) { | | 51 | + _free_host_function_impl(host_func_ref); | 33 | 52 | } | 34 | 53 |
| | 54 | +int _library_features(void); | | 55 | + | | 56 | +__attribute__((export_name("swjs_library_features"))) | | 57 | +int swjs_library_features(void) { | | 58 | + return _library_features(); | | 59 | +} | | 60 | +#endif | 35 | 61 | #endif | 36 | 62 |
| 37 | 63 | _Thread_local void *swjs_thread_local_closures; |
|