Skip to content

Commit

Permalink
jsi tests work pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
laptou committed Aug 22, 2023
1 parent ea18a9e commit 4ef5be1
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
members = [
"jsi-sys",
"jsi-macros",
"jsi-tests",
"jsi",
"js-api",
"js-tests",
]
resolver = "2"
57 changes: 0 additions & 57 deletions js-tests/build.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions jsi-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# `js-tests`

This crate contains tests for `jsi-rs`. The tests are run against
[Hermes](https://github.com/facebook/hermes), which is Facebook's reference
implementation of JavaScript for React Native.

## Building and running tests

Hermes is a Git submodule of this repository, so it should be cloned
automatically when you clone this repo. The initial build of this crate will
take a while because it builds Hermes first.

Once that build finishes, you can run `cargo test` as normal.
71 changes: 71 additions & 0 deletions jsi-tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use std::{env, os::unix::process::CommandExt, path::PathBuf, process::Command};

fn main() {
let pkg_base = env::var_os("CARGO_MANIFEST_DIR").unwrap();
let pkg_base = PathBuf::from(pkg_base);

let hermes_build_status = Command::new("bash")
.args([pkg_base.join("../vendor/build-hermes.sh")])
.current_dir(pkg_base.join("../vendor"))
.output()
.expect("hermes build script could not be executed");

if !hermes_build_status.status.success() {
panic!(
"hermes build script failed\n\nstdout: {}\n\nstderr: {}",
String::from_utf8_lossy(&hermes_build_status.stdout),
String::from_utf8_lossy(&hermes_build_status.stderr),
)
}

let rn_base = pkg_base.join("../vendor/react-native/packages/react-native");

let includes = vec![
rn_base.join("React"),
rn_base.join("React/Base"),
rn_base.join("ReactCommon/jsi"),
rn_base.join("ReactCommon/callinvoker"),
pkg_base.join("../vendor/hermes/API"),
pkg_base.join("../vendor/hermes/public"),
pkg_base.join("include"),
];

for include in &includes {
println!("cargo:rerun-if-changed={:?}", include);
}

let includes: Vec<_> = IntoIterator::into_iter(includes)
.map(|p| dunce::canonicalize(&p).expect(&format!("missing include path {:?}", p)))
.collect();

let compiles: Vec<PathBuf> = vec![];

let compiles: Vec<_> = IntoIterator::into_iter(compiles)
.map(|p| dunce::canonicalize(&p).expect(&format!("missing compile file {:?}", p)))
.collect();

cxx_build::CFG
.exported_header_dirs
.extend(includes.iter().map(|e| e.as_path()));

let bridges = vec!["src/ffi.rs"];

for bridge in &bridges {
println!("cargo:rerun-if-changed={}", bridge);
}

cxx_build::bridges(bridges)
.flag_if_supported("-std=c++17")
.files(compiles)
.compile("js-tests");

println!("cargo:rustc-link-lib=hermes");
println!(
"cargo:rustc-link-search={}",
pkg_base.join("../vendor/hermes/build/API/hermes/").to_string_lossy()
);
println!(
"cargo:rustc-env=LD_LIBRARY_PATH={}",
pkg_base.join("../vendor/hermes/build/API/hermes/").to_string_lossy()
);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion js-tests/tests/basic.rs → jsi-tests/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cxx::UniquePtr;

use splicer_js_tests::ffi::bridge::*;
use jsi_tests::ffi::bridge::*;
use jsi_sys::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion js-tests/tests/common.rs → jsi-tests/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cxx::UniquePtr;

use splicer_js_tests::ffi::bridge::*;
use jsi_tests::ffi::bridge::*;
use jsi::RuntimeHandle;
use jsi_sys::*;

Expand Down
2 changes: 1 addition & 1 deletion js-tests/tests/function.rs → jsi-tests/tests/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cxx::UniquePtr;

use splicer_js_tests::ffi::bridge::*;
use jsi_tests::ffi::bridge::*;
use jsi_sys::*;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions jsi/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ impl<'rt> JsiObject<'rt> {
.has_property(rt.get_inner_mut(), prop.0.as_ref().unwrap())
}

pub fn set(&mut self, prop: PropName, value: JsiValue, rt: &mut RuntimeHandle<'rt>) {
pub fn set(&mut self, prop: PropName, value: &JsiValue, rt: &mut RuntimeHandle<'rt>) {
sys::Object_setProperty(
self.0.pin_mut(),
rt.get_inner_mut(),
prop.0.as_ref().unwrap(),
value.0,
value.0.as_ref().unwrap(),
)
}

Expand Down
7 changes: 4 additions & 3 deletions vendor/build-hermes.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euxo pipefail
cd hermes
utils/build/configure.py
cd build
ninja
cmake -S . -B build -G Ninja
cmake --build ./build

0 comments on commit 4ef5be1

Please sign in to comment.