Skip to content

Commit 4b7981b

Browse files
Merge pull request #91 from swiftwasm/omit-unsafe-linker-flags
Remove all unsafe linker flags from Package.swift
2 parents 4235226 + 738d873 commit 4b7981b

File tree

10 files changed

+83
-100
lines changed

10 files changed

+83
-100
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ jobs:
66
strategy:
77
matrix:
88
os: [macOS-10.15, Ubuntu-18.04]
9-
include:
10-
- os: macOS-10.15
11-
toolchain: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.3-SNAPSHOT-2020-08-10-a/swift-wasm-5.3-SNAPSHOT-2020-08-10-a-osx.tar.gz
12-
- os: Ubuntu-18.04
13-
toolchain: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.3-SNAPSHOT-2020-08-10-a/swift-wasm-5.3-SNAPSHOT-2020-08-10-a-linux.tar.gz
149
runs-on: ${{ matrix.os }}
1510
steps:
1611
- name: Checkout
@@ -23,8 +18,5 @@ jobs:
2318
export SWIFTENV_ROOT="$HOME/.swiftenv"
2419
export PATH="$SWIFTENV_ROOT/bin:$PATH"
2520
eval "$(swiftenv init -)"
26-
swiftenv install $TOOLCHAIN_DOWNLOAD
2721
make bootstrap
2822
make test
29-
env:
30-
TOOLCHAIN_DOWNLOAD: ${{ matrix.toolchain }}

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
wasm-5.3-SNAPSHOT-2020-08-10-a
1+
wasm-5.3-SNAPSHOT-2020-10-02-a

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
22

33
.PHONY: bootstrap
44
bootstrap:
5+
./scripts/install-toolchain.sh
56
npm install
67

78
.PHONY: build

Package.swift

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.2
22

33
import PackageDescription
44

@@ -10,34 +10,8 @@ let package = Package(
1010
targets: [
1111
.target(
1212
name: "JavaScriptKit",
13-
dependencies: ["_CJavaScriptKit"],
14-
linkerSettings: [
15-
.unsafeFlags(
16-
[
17-
"-Xlinker",
18-
"--export=swjs_call_host_function",
19-
"-Xlinker",
20-
"--export=swjs_prepare_host_function_call",
21-
"-Xlinker",
22-
"--export=swjs_cleanup_host_function_call",
23-
"-Xlinker",
24-
"--export=swjs_library_version",
25-
],
26-
.when(platforms: [.wasi])
27-
),
28-
]
29-
),
30-
.target(
31-
name: "_CJavaScriptKit",
32-
linkerSettings: [
33-
.unsafeFlags(
34-
[
35-
"-Xlinker",
36-
"--allow-undefined",
37-
],
38-
.when(platforms: [.wasi])
39-
),
40-
]
13+
dependencies: ["_CJavaScriptKit"]
4114
),
15+
.target(name: "_CJavaScriptKit"),
4216
]
4317
)

[email protected]

Lines changed: 0 additions & 41 deletions
This file was deleted.

Sources/JavaScriptKit/Compatibility.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,8 @@ public class JSClosure: JSFunction {
190190
// │ │ │
191191
// └─────────────────────┴──────────────────────────┘
192192

193-
@_cdecl("swjs_prepare_host_function_call")
194-
func _prepare_host_function_call(_ argc: Int32) -> UnsafeMutableRawPointer {
195-
let argumentSize = MemoryLayout<RawJSValue>.size * Int(argc)
196-
return malloc(Int(argumentSize))!
197-
}
198-
199-
@_cdecl("swjs_cleanup_host_function_call")
200-
func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
201-
free(pointer)
202-
}
203-
204-
@_cdecl("swjs_call_host_function")
205-
func _call_host_function(
193+
@_cdecl("_call_host_function_impl")
194+
func _call_host_function_impl(
206195
_ hostFuncRef: JavaScriptHostFuncRef,
207196
_ argv: UnsafePointer<RawJSValue>, _ argc: Int32,
208197
_ callbackFuncRef: JavaScriptObjectRef
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "_CJavaScriptKit.h"
2+
#include <stdlib.h>
3+
4+
#if __wasm32__
5+
6+
void _call_host_function_impl(const JavaScriptHostFuncRef host_func_ref,
7+
const RawJSValue *argv, const int argc,
8+
const JavaScriptObjectRef callback_func);
9+
10+
__attribute__((export_name("swjs_call_host_function")))
11+
void _call_host_function(const JavaScriptHostFuncRef host_func_ref,
12+
const RawJSValue *argv, const int argc,
13+
const JavaScriptObjectRef callback_func) {
14+
_call_host_function_impl(host_func_ref, argv, argc, callback_func);
15+
}
16+
17+
__attribute__((export_name("swjs_prepare_host_function_call")))
18+
void *_prepare_host_function_call(const int argc) {
19+
return malloc(argc * sizeof(RawJSValue));
20+
}
21+
22+
__attribute__((export_name("swjs_cleanup_host_function_call")))
23+
void _cleanup_host_function_call(void *argv_buffer) {
24+
free(argv_buffer);
25+
}
26+
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 _library_version() {
32+
return 700;
33+
}
34+
35+
#endif

Sources/_CJavaScriptKit/dummy.c

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/install-toolchain.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
scripts_dir="$(cd "$(dirname $0)" && pwd)"
5+
6+
swift_version="$(cat $scripts_dir/../.swift-version)"
7+
swift_tag="swift-$swift_version"
8+
9+
if [ -z "$(which swiftenv)" ]; then
10+
echo "swiftenv not installed, please install it before this script."
11+
exit 1
12+
fi
13+
14+
if [ ! -z "$(swiftenv versions | grep $swift_version)" ]; then
15+
echo "$swift_version is already installed."
16+
exit 0
17+
fi
18+
19+
case $(uname -s) in
20+
Darwin)
21+
toolchain_download="$swift_tag-osx.tar.gz"
22+
;;
23+
Linux)
24+
if [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=18.04" ]; then
25+
toolchain_download="$swift_tag-ubuntu18.04.tar.gz"
26+
elif [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=20.04" ]; then
27+
toolchain_download="$swift_tag-ubuntu20.04.tar.gz"
28+
else
29+
echo "Unknown Ubuntu version"
30+
exit 1
31+
fi
32+
;;
33+
*)
34+
echo "Unrecognised platform $(uname -s)"
35+
exit 1
36+
;;
37+
esac
38+
39+
toolchain_download_url="https://github.com/swiftwasm/swift/releases/download/$swift_tag/$toolchain_download"
40+
41+
swiftenv install "$toolchain_download_url"

0 commit comments

Comments
 (0)