Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all unsafe linker flags from Package.swift #91

Merged
merged 3 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ jobs:
strategy:
matrix:
os: [macOS-10.15, Ubuntu-18.04]
include:
- os: macOS-10.15
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
- os: Ubuntu-18.04
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
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -23,8 +18,5 @@ jobs:
export SWIFTENV_ROOT="$HOME/.swiftenv"
export PATH="$SWIFTENV_ROOT/bin:$PATH"
eval "$(swiftenv init -)"
swiftenv install $TOOLCHAIN_DOWNLOAD
make bootstrap
make test
env:
TOOLCHAIN_DOWNLOAD: ${{ matrix.toolchain }}
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wasm-5.3-SNAPSHOT-2020-08-10-a
wasm-5.3-SNAPSHOT-2020-10-02-a
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

.PHONY: bootstrap
bootstrap:
./scripts/install-toolchain.sh
npm install

.PHONY: build
Expand Down
32 changes: 3 additions & 29 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.2

import PackageDescription

Expand All @@ -10,34 +10,8 @@ let package = Package(
targets: [
.target(
name: "JavaScriptKit",
dependencies: ["_CJavaScriptKit"],
linkerSettings: [
.unsafeFlags(
[
"-Xlinker",
"--export=swjs_call_host_function",
"-Xlinker",
"--export=swjs_prepare_host_function_call",
"-Xlinker",
"--export=swjs_cleanup_host_function_call",
"-Xlinker",
"--export=swjs_library_version",
],
.when(platforms: [.wasi])
),
]
),
.target(
name: "_CJavaScriptKit",
linkerSettings: [
.unsafeFlags(
[
"-Xlinker",
"--allow-undefined",
],
.when(platforms: [.wasi])
),
]
dependencies: ["_CJavaScriptKit"]
),
.target(name: "_CJavaScriptKit"),
]
)
41 changes: 0 additions & 41 deletions Package@swift-5.2.swift

This file was deleted.

7 changes: 0 additions & 7 deletions Sources/JavaScriptKit/Compatibility.swift

This file was deleted.

15 changes: 2 additions & 13 deletions Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,8 @@ public class JSClosure: JSFunction {
// │ │ │
// └─────────────────────┴──────────────────────────┘

@_cdecl("swjs_prepare_host_function_call")
func _prepare_host_function_call(_ argc: Int32) -> UnsafeMutableRawPointer {
let argumentSize = MemoryLayout<RawJSValue>.size * Int(argc)
return malloc(Int(argumentSize))!
}

@_cdecl("swjs_cleanup_host_function_call")
func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
free(pointer)
}

@_cdecl("swjs_call_host_function")
func _call_host_function(
@_cdecl("_call_host_function_impl")
func _call_host_function_impl(
_ hostFuncRef: JavaScriptHostFuncRef,
_ argv: UnsafePointer<RawJSValue>, _ argc: Int32,
_ callbackFuncRef: JavaScriptObjectRef
Expand Down
35 changes: 35 additions & 0 deletions Sources/_CJavaScriptKit/_CJavaScriptKit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "_CJavaScriptKit.h"
#include <stdlib.h>

#if __wasm32__

void _call_host_function_impl(const JavaScriptHostFuncRef host_func_ref,
const RawJSValue *argv, const int argc,
const JavaScriptObjectRef callback_func);

__attribute__((export_name("swjs_call_host_function")))
void _call_host_function(const JavaScriptHostFuncRef host_func_ref,
const RawJSValue *argv, const int argc,
const JavaScriptObjectRef callback_func) {
_call_host_function_impl(host_func_ref, argv, argc, callback_func);
}

__attribute__((export_name("swjs_prepare_host_function_call")))
void *_prepare_host_function_call(const int argc) {
return malloc(argc * sizeof(RawJSValue));
}

__attribute__((export_name("swjs_cleanup_host_function_call")))
void _cleanup_host_function_call(void *argv_buffer) {
free(argv_buffer);
}

/// The compatibility runtime library version.
/// Notes: If you change any interface of runtime library, please increment
/// this and `SwiftRuntime.version` in `./Runtime/src/index.ts`.
__attribute__((export_name("swjs_library_version")))
int _library_version() {
return 700;
}

#endif
1 change: 0 additions & 1 deletion Sources/_CJavaScriptKit/dummy.c

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/install-toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -eu

scripts_dir="$(cd "$(dirname $0)" && pwd)"

swift_version="$(cat $scripts_dir/../.swift-version)"
swift_tag="swift-$swift_version"

if [ -z "$(which swiftenv)" ]; then
echo "swiftenv not installed, please install it before this script."
exit 1
fi

if [ ! -z "$(swiftenv versions | grep $swift_version)" ]; then
echo "$swift_version is already installed."
exit 0
fi

case $(uname -s) in
Darwin)
toolchain_download="$swift_tag-osx.tar.gz"
;;
Linux)
if [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=18.04" ]; then
toolchain_download="$swift_tag-ubuntu18.04.tar.gz"
elif [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=20.04" ]; then
toolchain_download="$swift_tag-ubuntu20.04.tar.gz"
else
echo "Unknown Ubuntu version"
exit 1
fi
;;
*)
echo "Unrecognised platform $(uname -s)"
exit 1
;;
esac

toolchain_download_url="https://github.com/swiftwasm/swift/releases/download/$swift_tag/$toolchain_download"

swiftenv install "$toolchain_download_url"