Skip to content

Commit

Permalink
use __wasi__ instead of __Embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn committed Oct 30, 2024
1 parent d4348f3 commit fbd62f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
5 changes: 1 addition & 4 deletions Examples/Embedded/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ let package = Package(
"JavaScriptKit",
.product(name: "dlmalloc", package: "swift-dlmalloc")
],
cSettings: [
.unsafeFlags(["-fdeclspec"]),
.define("__Embedded"),
],
cSettings: [.unsafeFlags(["-fdeclspec"])],
swiftSettings: [
.enableExperimentalFeature("Embedded"),
.enableExperimentalFeature("Extern"),
Expand Down
8 changes: 2 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ let package = Package(
dependencies: ["_CJavaScriptKit"],
resources: shouldBuildForEmbedded ? [] : [.copy("Runtime")],
cSettings: shouldBuildForEmbedded ? [
.unsafeFlags(["-fdeclspec"]),
.define("__Embedded"),
.unsafeFlags(["-fdeclspec"])
] : nil,
swiftSettings: shouldBuildForEmbedded
? [
Expand All @@ -29,10 +28,7 @@ let package = Package(
.unsafeFlags(["-Xfrontend", "-emit-empty-object-file"])
] : nil,
),
.target(
name: "_CJavaScriptKit",
cSettings: shouldBuildForEmbedded ? [.define("__Embedded")] : nil
),
.target(name: "_CJavaScriptKit"),
.target(
name: "JavaScriptBigIntSupport",
dependencies: ["_CJavaScriptBigIntSupport", "JavaScriptKit"]
Expand Down
8 changes: 5 additions & 3 deletions Sources/_CJavaScriptKit/_CJavaScriptKit.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "_CJavaScriptKit.h"
#if __wasm32__
#if __Embedded
#ifndef __wasi__
#if __has_include("malloc.h")
#include <malloc.h>
#endif
Expand Down Expand Up @@ -31,8 +31,10 @@ void swjs_cleanup_host_function_call(void *argv_buffer) {
free(argv_buffer);
}

#ifndef __Embedded
// cdecls don't work in Embedded, also @_expose(wasm) can be used with Swift >=6.0
// NOTE: This __wasi__ check is a hack for Embedded compatibility (assuming that if __wasi__ is defined, we are not building for Embedded)
// cdecls don't work in Embedded, but @_expose(wasm) can be used with Swift >=6.0
// the previously used `#if __Embedded` did not play well with SwiftPM (defines needed to be on every target up the chain)
#ifdef __wasi__
bool _call_host_function_impl(const JavaScriptHostFuncRef host_func_ref,
const RawJSValue *argv, const int argc,
const JavaScriptObjectRef callback_func);
Expand Down
2 changes: 1 addition & 1 deletion Sources/_CJavaScriptKit/include/_CJavaScriptKit.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _CJavaScriptKit_h
#define _CJavaScriptKit_h

#if __Embedded
#ifndef __wasi__
#include <stddef.h>
#else
#include <stdlib.h>
Expand Down

0 comments on commit fbd62f4

Please sign in to comment.