Skip to content

Commit 806ccfa

Browse files
feat: compatiblity with NativeScript iOS runtime (#17)
* feat: compatiblity with NativeScript iOS runtime * fix comment * call js-defined block from another thread * fix: expose protocol-defined methods from classes that conform * start work on types * patch libffi * patch config.sub * add libffi prebuilt binaries * nit: remove build-libffi instruction from readme * fix: update libffi include path * fix: allow Node.js to resolve "objc" from examples dir without package installation (#18) While Deno could resolve it, Node.js couldn't find "objc" without performing `cd examples && npm install` (which would mean instructing contributors to do npm installs both at root and in a subdir, which is a pain). After weighing up an amusing number of differently cursed workarounds, we landed on this one. * feat: add ability to specify metadata path using METADATA_PATH * feat: add Charon runtime * work * more work on types * ts types closer than ever * more work on types * dont emit setter methods for properties that already exist * optional protocol members * examples all pass typechecking * fix ts types * feat(MetadataGenerator): rewrite using an intermediate format * spritekit controller demo * support changing method impls on class definitions * add target to metagen, start testing core, start working on interop * work on interop.Pointer * implement bunch of interop API * support more overloads of interop.Reference * more work on Hermes & core compat * fix(metadata): handle case of no arg being passed (#20) `deno task metagen` was producing: metadata.undefined.nsmd Co-authored-by: Dj <43033058+DjDeveloperr@users.noreply.github.com> * fix: dont use napi_wrap on strings --------- Co-authored-by: Jamie Birch <14055146+shirakaba@users.noreply.github.com>
1 parent 9505d56 commit 806ccfa

File tree

280 files changed

+268101
-3309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+268101
-3309
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ build/
44
deno.lock
55
package-lock.json
66
node_modules/
7+
# This node_modules is manually created and version-controlled. Inside it, we
8+
# commit a symlink back up to our root-level "objc" package. It avoids having
9+
# to do a package install both at root level and in the examples directory.
10+
!examples/node_modules
711
NativeScript for macOS.app/
812
*.dylib
913
libffi/build_*

CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if(BRIDGE_TARGET_PLATFORM STREQUAL "ios")
2424
set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
2525
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
2626
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0")
27-
set(LIBFFI_BUILD "build_iphoneos-arm64")
27+
set(LIBFFI_BUILD "iphoneos-arm64")
2828
set(TARGET_PLATFORM_IOS TRUE)
2929
set(SDK_NAME "iphoneos")
3030
set(CMAKE_OSX_ARCHITECTURES "arm64")
@@ -33,15 +33,15 @@ elseif(BRIDGE_TARGET_PLATFORM STREQUAL "ios-sim")
3333
set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
3434
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
3535
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0")
36-
set(LIBFFI_BUILD "build_iphonesimulator-universal")
36+
set(LIBFFI_BUILD "iphonesimulator-universal")
3737
set(TARGET_PLATFORM_IOS TRUE)
3838
set(TARGET_PLATFORM_SIM TRUE)
3939
set(SDK_NAME "iphonesimulator")
4040
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
4141
elseif(BRIDGE_TARGET_PLATFORM STREQUAL "macos")
4242
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "13.0")
4343
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0")
44-
set(LIBFFI_BUILD "build_macosx-universal")
44+
set(LIBFFI_BUILD "macosx-universal")
4545
set(TARGET_PLATFORM_MACOS TRUE)
4646
unset(BUILD_FRAMEWORK)
4747
set(SDK_NAME "macosx")
@@ -78,7 +78,7 @@ message(STATUS "SDK = ${CMAKE_OSX_SYSROOT}")
7878
include_directories(
7979
${CMAKE_CURRENT_SOURCE_DIR}/include
8080
${CMAKE_CURRENT_SOURCE_DIR}/metadata/include
81-
${CMAKE_CURRENT_SOURCE_DIR}/libffi/${LIBFFI_BUILD}/include
81+
${CMAKE_CURRENT_SOURCE_DIR}/libffi/prebuilt/${LIBFFI_BUILD}/include
8282
/Library/Developer/CommandLineTools/usr/include
8383
)
8484

@@ -102,6 +102,7 @@ set(LIB_SOURCE_FILES
102102
src/Object.mm
103103
src/CustomClass.mm
104104
src/CFunction.mm
105+
src/Interop.mm
105106
)
106107

107108
add_library(
@@ -159,14 +160,14 @@ message(STATUS "LIBFFI_BUILD = ${LIBFFI_BUILD}")
159160
target_link_directories(
160161
${NAME}
161162
PRIVATE
162-
${CMAKE_CURRENT_SOURCE_DIR}/libffi/${LIBFFI_BUILD}/.libs
163+
${CMAKE_CURRENT_SOURCE_DIR}/libffi/prebuilt/${LIBFFI_BUILD}
163164
)
164165

165166
target_link_libraries(
166167
${NAME}
167168
PRIVATE
168169
objc
169-
ffi_convenience
170+
ffi
170171
"-framework Foundation"
171172
)
172173

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ JavaScript land. Made using Node-API and `libffi` under the hood.
66
## Building
77

88
```sh
9-
deno task build-libffi
10-
119
deno task build macos
1210
# or build for iOS
1311
deno task build ios-universal

bench/main.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import "objc";
22
import { bench, run } from "mitata";
33

4-
const str = NSString.stringWithUTF8String("Hello World");
4+
const arr = NSMutableArray.arrayWithCapacity(100);
55

6-
const str2 = new Proxy(str, {
6+
const arr2 = new Proxy(arr, {
77
get: (target, prop) => {
88
return target[prop];
99
},
1010
});
1111

1212
bench("noop", () => {});
1313

14-
bench("[str length] (manual, direct)", () => {
15-
str.lengthCustom;
14+
bench("[arr count] (dynamic, ffi)", () => {
15+
arr.count;
1616
});
1717

18-
bench("[str length] (dynamic, ffi)", () => {
19-
str.length;
20-
});
21-
22-
bench("[str length] (dynamic, proxy)", () => {
23-
str2.length;
18+
bench("[arr count] (dynamic, proxy)", () => {
19+
arr2.count;
2420
});
2521

2622
await run({

core-test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
core/

core-test/deno.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tasks": {
3+
"transform-core": "rm -rf ./core && cp -r ../../NativeScript/dist/packages/core ./core && deno run -A --unstable transform_core.js ios",
4+
"bundle": "./node_modules/.bin/esbuild --bundle --outfile=/Users/dj/Projects/hermes-testing/HermesTest/HermesTest/main.js --format=esm src/index.js"
5+
}
6+
}

core-test/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "core-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"@swc/cli": "^0.1.62",
14+
"@swc/core": "^1.3.95",
15+
"esbuild": "0.19.5"
16+
},
17+
"dependencies": {
18+
"@nativescript/core": "file:../../NativeScript/packages/core",
19+
"acorn": "^8.11.2",
20+
"css-tree": "^2.3.1",
21+
"emoji-regex": "^10.3.0",
22+
"objc": "file:..",
23+
"reduce-css-calc": "^2.1.8",
24+
"tslib": "^2.6.2"
25+
}
26+
}

core-test/spack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
entry: {
3+
web: __dirname + "/src/index.ts",
4+
},
5+
output: {
6+
path: __dirname + "/dist",
7+
},
8+
};

core-test/src/compat.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
globalThis.global = globalThis;
2+
3+
globalThis.__ANDROID__ = false;
4+
globalThis.__IOS__ = true;
5+
globalThis.__VISIONOS__ = false;
6+
globalThis.__dirname = NSBundle.mainBundle.bundlePath;
7+
8+
function NativeScriptEmbedder() {}
9+
10+
globalThis.NativeScriptEmbedder = NativeScriptEmbedder;
11+
12+
globalThis.nativeScriptEmbedder = new NativeScriptEmbedder();
13+
14+
NativeScriptEmbedder.sharedInstance = function () {
15+
return nativeScriptEmbedder;
16+
};
17+
18+
NativeScriptEmbedder.prototype.setDelegate = function (delegate) {
19+
this.delegate = delegate;
20+
};
21+
22+
WeakRef.prototype.get = function () {
23+
return this.deref();
24+
};
25+
26+
globalThis.CGRectMake = function (x, y, width, height) {
27+
return { origin: { x, y }, size: { width, height } };
28+
};

core-test/src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import "./compat.js";
2+
import "../core/globals/index.js";
3+
import { StackLayout, Application } from "../core/index.js";
4+
5+
Application.run({
6+
create: () => {
7+
const stackLayout = new StackLayout();
8+
stackLayout.backgroundColor = "yellow";
9+
return stackLayout;
10+
},
11+
});

0 commit comments

Comments
 (0)