Skip to content

Commit

Permalink
Merge branch 'main' into johannes/rinja
Browse files Browse the repository at this point in the history
  • Loading branch information
Johennes committed Dec 18, 2024
2 parents 34313bf + 0ea522e commit fea221a
Show file tree
Hide file tree
Showing 157 changed files with 5,131 additions and 791 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ jobs:
- name: Run tests
run: cargo test --verbose

integration-tests-generation:
name: 🧩 Integration tests (generation)
- name: Run tests for binaries
run: cargo test --bins

integration-tests-jsi-bindings:
name: 🧩 Integration tests (JSI bindings)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -58,9 +61,27 @@ jobs:
- name: Installing hermes and test-runner
run: cargo xtask bootstrap

- name: Run tests of generated bindings
- name: Run tests of generated JSI bindings
run: ./scripts/run-tests.sh

integration-tests-wasm-bindings:
name: 🧩 Integration tests (WASM bindings)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Installing
run: cargo xtask bootstrap yarn

- name: Installing WASM
run: rustup target add wasm32-unknown-unknown

- name: Installing wasm-bindgen
run: cargo install wasm-bindgen-cli

- name: Run tests of generated WASM bindings
run: ./scripts/run-tests.sh --flavor wasm

integration-tests-checkout:
name: 🧩 Integration tests (checkout)
runs-on: ubuntu-latest
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/cocoapods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish to CocoaPods

on:
release:
types: [published]
workflow_dispatch:

jobs:
publish-cocoapods:
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"

- name: Install CocoaPods
run: gem install cocoapods

- name: Lint Podspec
run: pod spec lint uniffi-bindgen-react-native.podspec

- name: Publish to CocoaPods
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
run: pod trunk push uniffi-bindgen-react-native.podspec
60 changes: 60 additions & 0 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Compat

on:
schedule:
- cron: "0 0 * * *" # Once a day at midnight
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
integration-tests-generation:
strategy:
matrix:
runner:
- macos-latest
- ubuntu-latest
bob-version:
- 0.42.2
- 0.42.3
- latest
rn-version:
- 0.76.0
- latest

runs-on: ${{ matrix.runner }}
name: "bob ${{ matrix.bob-version }} / rn ${{ matrix.rn-version }} / ${{ matrix.runner == 'macos-latest' && 'ios' || 'android' }}"

steps:
- uses: actions/checkout@v4

- name: Install cargo-ndk
if: ${{ matrix.runner != 'macos-latest' }}
run: |
cargo install cargo-ndk
- name: Install JDK
if: ${{ matrix.runner != 'macos-latest' }}
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"

- name: Install Rust toolchains
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.runner == 'macos-latest' && 'aarch64-apple-ios-sim' || 'aarch64-linux-android' }}

- name: Generate & build turbo module
run: |
./scripts/test-turbo-modules.sh \
--slug '@my-org/my-lib' \
--ubrn-config integration/fixtures/compat/ubrn.config.yaml \
--builder-bob-version ${{ matrix.bob-version }} \
--rn-version ${{ matrix.rn-version }} \
--packgage-json-mixin integration/fixtures/compat/package.json \
--react-native-config integration/fixtures/compat/react-native.config.js \
--${{ matrix.runner == 'macos-latest' && 'ios' || 'android' }} \
../turbo-module
22 changes: 22 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish to npmjs
on:
release:
types: [published]
workflow_dispatch:

jobs:
publish-npmjs:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- run: npm install
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Upcoming releases

## 🦊 What's Changed
* Switched from passing `ArrayBuffer`s to using `Uint8Array`, to accommodate WASM better. ([#187](https://github.com/jhugman/uniffi-bindgen-react-native/pull/187))

**Full Changelog**: https://github.com/jhugman/uniffi-bindgen-react-native/compare/0.28.3-1...main

# 0.28.3-1

This is the first supported release of the `uniffi-bindgen-react-native`. Please hack responsibly. Share and enjoy.

## 🦊 What's Changed
* Handle type parameter change in crnl 0.45.1 ([#182](https://github.com/jhugman/uniffi-bindgen-react-native/pull/182))
* Make first run more informative while compiling ([#185](https://github.com/jhugman/uniffi-bindgen-react-native/pull/185))
* Initial refactor in preparing for WASM ([#174](https://github.com/jhugman/uniffi-bindgen-react-native/pull/174))
* Add callbacks-example fixture from uniffi-rs ([#172](https://github.com/jhugman/uniffi-bindgen-react-native/pull/172))
* Fix CLI working without an extension ([#183](https://github.com/jhugman/uniffi-bindgen-react-native/pull/183))
* Use version released to Cocoapods and npm ([#184](https://github.com/jhugman/uniffi-bindgen-react-native/pull/184))

**Full Changelog**: https://github.com/jhugman/uniffi-bindgen-react-native/compare/0.28.3-0...0.28.3-1

/*
## ✨ What's New

## 🦊 What's Changed

## ⚠️ Breaking Changes

**Full Changelog**: https://github.com/jhugman/uniffi-bindgen-react-native/compare/{{previous}}...{{current}}
*/
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ heck = "0.5.0"
paste = "1.0.14"
pathdiff = { version = "0.2.1", features = ["camino"] }
serde = { version = "1", features = ["derive"] }
uniffi = "=0.28.2"
uniffi_bindgen = "=0.28.2"
uniffi_meta = "=0.28.2"
uniffi = "=0.28.3"
uniffi_bindgen = "=0.28.3"
uniffi_meta = "=0.28.3"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![CI](https://github.com/jhugman/uniffi-bindgen-react-native/actions/workflows/ci.yml/badge.svg)](https://github.com/jhugman/uniffi-bindgen-react-native/actions/workflows/ci.yml)
[![build-bob compatibility](https://github.com/jhugman/uniffi-bindgen-react-native/actions/workflows/compat.yml/badge.svg)](https://github.com/jhugman/uniffi-bindgen-react-native/actions/workflows/compat.yml)

# uniffi-bindgen-react-native
[UniFFI](https://mozilla.github.io/uniffi-rs/latest/) is a multi-language bindings generator for Rust.
Expand Down
9 changes: 8 additions & 1 deletion bin/cli.cjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -32,13 +33,19 @@ const rootDir = getRootDir();

const args = process.argv.slice(2);
if (args.length === 1 && args[0] === "--path") {
console.log(`${rootDir}/bin/cli`);
console.log(`${rootDir}/bin/cli.cjs`);
process.exit(0);
}

// Construct the path to the Cargo.toml file
const manifestPath = path.join(rootDir, "crates/ubrn_cli/Cargo.toml");

if (!fs.existsSync(path.join(rootDir, "target"))) {
console.log(
"🤖 Building the uniffi-bindgen-react-native command… this is only needed first time",
);
}

// Run the cargo command
const command = `cargo run --quiet --manifest-path "${manifestPath}" -- ${args.join(" ")}`;
try {
Expand Down
24 changes: 0 additions & 24 deletions cpp/includes/ForeignBytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,3 @@ struct ForeignBytes {
int32_t len;
uint8_t *data;
};

namespace uniffi_jsi {
using namespace facebook;

template <> struct Bridging<ForeignBytes> {
static ForeignBytes fromJs(jsi::Runtime &rt, const jsi::Value &value) {
try {
auto buffer = value.asObject(rt).getArrayBuffer(rt);
return ForeignBytes{
.len = static_cast<int32_t>(buffer.length(rt)),
.data = buffer.data(rt),
};
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}

static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
ForeignBytes value) {
throw jsi::JSError(rt, "Unreachable ForeignBytes.toJs");
}
};

} // namespace uniffi_jsi
38 changes: 38 additions & 0 deletions cpp/includes/UniffiByteArray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/
*/
#pragma once

#include "Bridging.h"
#include <jsi/jsi.h>

namespace uniffi_jsi {
using namespace facebook;

template <> struct Bridging<jsi::ArrayBuffer> {
static jsi::ArrayBuffer value_to_arraybuffer(jsi::Runtime &rt,
const jsi::Value &value) {
try {
return value.asObject(rt)
.getPropertyAsObject(rt, "buffer")
.getArrayBuffer(rt);
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}

static jsi::Value arraybuffer_to_value(jsi::Runtime &rt,
const jsi::ArrayBuffer &arrayBuffer) {
try {
jsi::Object obj(rt);
obj.setProperty(rt, "buffer", arrayBuffer);
return jsi::Value(rt, obj);
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
};

} // namespace uniffi_jsi
20 changes: 7 additions & 13 deletions cpp/includes/UniffiCallInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once
#include <ReactCommon/CallInvoker.h>
#include <condition_variable>
#include <future>
#include <jsi/jsi.h>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -58,26 +59,19 @@ class UniffiCallInvoker {
if (std::this_thread::get_id() == threadId_) {
func(rt);
} else {
std::mutex mtx;
std::condition_variable cv;
bool done = false;
std::promise<void> promise;
auto future = promise.get_future();
// The runtime argument was added to CallFunc in
// https://github.com/facebook/react-native/pull/43375
//
// This can be changed once that change is released.
// react::CallFunc wrapper = [&func, &mtx, &cv, &done](jsi::Runtime &rt) {
std::function<void()> wrapper = [&func, &rt, &mtx, &cv, &done]() {
// react::CallFunc wrapper = [&func, &promise](jsi::Runtime &rt) {
std::function<void()> wrapper = [&func, &promise, &rt]() {
func(rt);
{
std::lock_guard<std::mutex> lock(mtx);
done = true;
}
cv.notify_one();
promise.set_value();
};
callInvoker_->invokeAsync(std::move(wrapper));

std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock, [&done] { return done; });
future.wait();
}
}

Expand Down
1 change: 1 addition & 0 deletions cpp/includes/UniffiJsiTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ForeignBytes.h"
#include "ReferenceHolder.h"
#include "RustBuffer.h"
#include "UniffiByteArray.h"
#include "UniffiCallInvoker.h"
#include "UniffiRustCallStatus.h"
#include "UniffiString.h"
Expand Down
7 changes: 5 additions & 2 deletions cpp/includes/UniffiString.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ template <> struct Bridging<std::string> {
static jsi::Value arraybuffer_to_string(jsi::Runtime &rt,
const jsi::Value &value) {
try {
auto buffer = value.asObject(rt).getArrayBuffer(rt);
auto buffer =
uniffi_jsi::Bridging<jsi::ArrayBuffer>::value_to_arraybuffer(rt,
value);
auto string =
jsi::String::createFromUtf8(rt, buffer.data(rt), buffer.length(rt));
return jsi::Value(rt, string);
Expand All @@ -40,7 +42,8 @@ template <> struct Bridging<std::string> {
std::make_shared<CMutableBuffer>(CMutableBuffer(bytes, len));
auto arrayBuffer = jsi::ArrayBuffer(rt, payload);

return jsi::Value(rt, arrayBuffer);
return uniffi_jsi::Bridging<jsi::ArrayBuffer>::arraybuffer_to_value(
rt, arrayBuffer);
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
Expand Down
19 changes: 19 additions & 0 deletions crates/ubrn_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
wasm = ["quote", "prettyplease", "syn", "proc-macro2"]

[dependencies]
anyhow = { workspace = true }
Expand All @@ -20,3 +23,19 @@ uniffi_meta = { workspace = true }
extend = "1.2.0"
topological-sort = "0.2.2"
toml = "0.5"

[dependencies.quote]
version = "1.0"
optional = true

[dependencies.prettyplease]
version = "0.2"
optional = true

[dependencies.syn]
version = "2.0"
optional = true

[dependencies.proc-macro2]
version = "1.0"
optional = true
Loading

0 comments on commit fea221a

Please sign in to comment.