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

Set up CI for bob / rn compatibility matrix and handle non-standard codegen output dirs #163

Merged
merged 28 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1a9059e
Set up CI for bob / rn compatibility matrix
Johennes Nov 13, 2024
3c62eb6
Shorten job name
Johennes Nov 13, 2024
54e1b43
Further shorten names
Johennes Nov 13, 2024
06a92cc
Appease prettier
Johennes Nov 13, 2024
2419811
Add missing \
Johennes Nov 13, 2024
d616f84
Allow mutable yarn installs
Johennes Nov 13, 2024
5d6c630
Install cargo-ndk if needed
Johennes Nov 13, 2024
f91d93e
Fix if statement
Johennes Nov 13, 2024
6df9a36
Install rust toolchains
Johennes Nov 13, 2024
fd0c748
Install Java 17
Johennes Nov 13, 2024
580acb8
Appease prettier once more
Johennes Nov 13, 2024
003c812
Add further bob versions
Johennes Nov 13, 2024
b408f62
Add bob 0.42.1
Johennes Nov 13, 2024
257884d
Remove 0.42.1
Johennes Nov 15, 2024
299e25d
Remove unused --ios-name parameter
Johennes Nov 15, 2024
90bbaca
Allow package.json mixins
Johennes Nov 15, 2024
3799a4f
Add package.json mixin to test matrix
Johennes Nov 15, 2024
3672ef4
Change fixtures path
Johennes Nov 15, 2024
0b08caa
Fix empty mixin name
Johennes Nov 15, 2024
88fb39c
Always use package.json mixin
Johennes Nov 15, 2024
8fd9c2d
Revert to standard paths and org scope
Johennes Nov 15, 2024
125cf24
Add missing slash
Johennes Nov 15, 2024
0cdd977
Switch back to custom codegen paths
Johennes Nov 15, 2024
2016643
Add badge
Johennes Nov 15, 2024
d75dc6f
Use 'latest'
Johennes Nov 15, 2024
f233d50
Rename PKG_JSON_MIXIN
Johennes Nov 20, 2024
bf3e7b9
Document cron expression
Johennes Nov 25, 2024
59bc61e
Handle non-standard codegen output dirs (#165)
Johennes Nov 26, 2024
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
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
Comment on lines +19 to +25
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this.


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
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻


# uniffi-bindgen-react-native
[UniFFI](https://mozilla.github.io/uniffi-rs/latest/) is a multi-language bindings generator for Rust.
Expand Down
11 changes: 11 additions & 0 deletions crates/ubrn_cli/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub(crate) struct AndroidConfig {

#[serde(default = "AndroidConfig::default_package_name")]
pub(crate) package_name: String,

#[serde(default = "AndroidConfig::default_codegen_output_dir")]
pub(crate) codegen_output_dir: String,
}

impl Default for AndroidConfig {
Expand Down Expand Up @@ -82,13 +85,21 @@ impl AndroidConfig {
fn default_jni_libs() -> String {
"src/main/jniLibs".to_string()
}

fn default_codegen_output_dir() -> String {
workspace::package_json().android_codegen_output_dir()
}
}

impl AndroidConfig {
pub(crate) fn directory(&self, project_root: &Utf8Path) -> Utf8PathBuf {
project_root.join(&self.directory)
}

pub(crate) fn codegen_output_dir(&self, project_root: &Utf8Path) -> Utf8PathBuf {
project_root.join(&self.codegen_output_dir)
}

pub(crate) fn jni_libs(&self, project_root: &Utf8Path) -> Utf8PathBuf {
self.directory(project_root).join(&self.jni_libs)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/ubrn_cli/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,15 @@ mod tests {
cargo_extras: ExtraArgs::default(),
api_level: 21,
package_name: "com.tester".to_string(),
codegen_output_dir: "android/generated".to_string(),
};
let ios = IOsConfig {
directory: "ios".to_string(),
framework_name: "MyRustCrateFramework".to_string(),
xcodebuild_extras: ExtraArgs::default(),
targets: Default::default(),
cargo_extras: ExtraArgs::default(),
codegen_output_dir: "ios/generated".to_string(),
};
let bindings = BindingsConfig {
cpp: "cpp/bindings".to_string(),
Expand Down
7 changes: 5 additions & 2 deletions crates/ubrn_cli/src/codegen/templates/build.kt.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ android {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"generated/java",
"generated/jni"
{%- let root = self.project_root() %}
{%- let dir = self.config.project.android.codegen_output_dir(root) %}
{%- let codegen = self.relative_to(root, dir) %}
"{{ codegen }}/java",
"{{ codegen }}/jni"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ Pod::Spec.new do |s|
{%- let framework = self.relative_to(root, dir) %}
{%- let dir = self.config.project.ios.directory(root) %}
{%- let ios = self.relative_to(root, dir) %}
{%- let dir = self.config.project.ios.codegen_output_dir(root) %}
{%- let codegen = self.relative_to(root, dir) %}
{%- let dir = self.config.project.tm.cpp_path(root) %}
{%- let tm = self.relative_to(root, dir) %}
{%- let dir = self.config.project.bindings.cpp_path(root) %}
{%- let bindings = self.relative_to(root, dir) -%}
s.source_files = "{{ ios }}/**/*.{h,m,mm}", "{{ tm }}/**/*.{hpp,cpp,c,h}", "{{ bindings }}/**/*.{hpp,cpp,c,h}"
s.source_files = "{{ ios }}/**/*.{h,m,mm}", "{{ codegen }}/**/*.{h,m,mm}", "{{ tm }}/**/*.{hpp,cpp,c,h}", "{{ bindings }}/**/*.{hpp,cpp,c,h}"
s.vendored_frameworks = "{{ framework }}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
Expand Down
36 changes: 36 additions & 0 deletions crates/ubrn_cli/src/config/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl PackageJson {
}
}

pub(crate) fn android_codegen_output_dir(&self) -> String {
self.codegen_config.output_dir.android.clone()
}

pub(crate) fn ios_codegen_output_dir(&self) -> String {
self.codegen_config.output_dir.ios.clone()
}

pub(crate) fn repo(&self) -> &PackageJsonRepo {
&self.repository
}
Expand All @@ -69,6 +77,8 @@ pub(crate) struct RnCodegenConfig {
pub(crate) js_srcs_dir: String,
#[serde(default)]
android: RnAndroidCodegenConfig,
#[serde(default)]
output_dir: RnOutputDirCodegenConfig,
}

impl Default for RnCodegenConfig {
Expand All @@ -82,3 +92,29 @@ impl Default for RnCodegenConfig {
struct RnAndroidCodegenConfig {
java_package_name: Option<String>,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct RnOutputDirCodegenConfig {
#[serde(default = "default_ios_codegen_output_dir")]
ios: String,
#[serde(default = "default_android_codegen_output_dir")]
android: String,
}

impl Default for RnOutputDirCodegenConfig {
fn default() -> Self {
Self {
ios: default_ios_codegen_output_dir(),
android: default_android_codegen_output_dir(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels slightly awkward having to pass in the default values here and in the serde macros. But I think we need to do it this way to account for either the whole object missing or only one of its fields?

}
}
}

fn default_android_codegen_output_dir() -> String {
"android/generated".to_string()
}

fn default_ios_codegen_output_dir() -> String {
"ios/generated".to_string()
}
11 changes: 11 additions & 0 deletions crates/ubrn_cli/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub(crate) struct IOsConfig {

#[serde(default = "IOsConfig::default_cargo_extras")]
pub(crate) cargo_extras: ExtraArgs,

#[serde(default = "IOsConfig::default_codegen_output_dir")]
pub(crate) codegen_output_dir: String,
}

impl IOsConfig {
Expand Down Expand Up @@ -74,6 +77,10 @@ impl IOsConfig {
let args: &[&str] = &["aarch64-apple-ios", sim_target];
args.iter().map(|s| Target::from_str(s).unwrap()).collect()
}

fn default_codegen_output_dir() -> String {
workspace::package_json().ios_codegen_output_dir()
}
}

impl Default for IOsConfig {
Expand All @@ -87,6 +94,10 @@ impl IOsConfig {
project_root.join(&self.directory)
}

pub(crate) fn codegen_output_dir(&self, project_root: &Utf8Path) -> Utf8PathBuf {
project_root.join(&self.codegen_output_dir)
}

pub(crate) fn framework_path(&self, project_root: &Utf8Path) -> Utf8PathBuf {
let filename = format!("{}.xcframework", self.framework_name);
project_root.join(filename)
Expand Down
18 changes: 17 additions & 1 deletion docs/src/reference/config-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ android:
apiLevel: 21
jniLibs: src/main/jniLibs
packageName: <DERIVED FROM package.json>
codegenOutputDir: <DERIVED FROM package.json>
```

The `directory` is the location of the Android project, relative to the root of the React Native library project.
Expand All @@ -91,10 +92,16 @@ The `directory` is the location of the Android project, relative to the root of
Reducing the number of targets to build for will speed up the edit-compile-run cycle.
```

`packageName` is the name of the Android package that Codegen used to generate the TurboModule. This is derived from the `package.json` file, and can almost always be left.
`packageName` is the name of the Android package that Codegen used to generate the TurboModule. `codegenOutputDir` is the path under which Codegen stores its generated files. Both are derived from the `package.json` file, and can almost always be left.

To customize the `packageName`, you should edit or add the entry at the path `codegenConfig`/`android`/`javaPackageName` in `package.json`.

To customize the `codegenOutputDir`, you should edit or add the entry at the path `codegenConfig`/`outputDir`/`android` in `package.json`.

```admonish warning
Note that for Android the `outputDir` value in `package.json` needs to have a matching entry under `dependency`/`platforms`/`android`/`cmakeListsPath` in `react-native.config.js`. For example, if you set the Android output directory in `package.json` to `android/tmp`, the `cmakeListsPath` value in `react-native.config.js` needs to be set to `tmp/jni/CMakeLists.txt`.
```

## `ios`

This is to configure the build steps for the Rust, the bindings, and the turbo-module code for iOS.
Expand All @@ -110,6 +117,7 @@ ios:
- aarch64-apple-ios-sim
xcodebuildExtras: []
frameworkName: build/MyFramework
codegenOutputDir: <DERIVED FROM package.json>
```


Expand All @@ -121,6 +129,14 @@ The `directory` is the location of the iOS project, relative to the root of the

`xcodebuildExtras` is a list of extra arguments passed directly to the `xcodebuild` command.

`codegenOutputDir` is the path under which Codegen stores its generated files. This is derived from the `package.json` file, and can almost always be left.

To customize the `codegenOutputDir`, you should edit or add the entry at the path `codegenConfig`/`outputDir`/`ios` in `package.json`.

```admonish warning
Note that for Android the `outputDir` value in `package.json` needs to have a matching entry under `dependency`/`platforms`/`android`/`cmakeListsPath` in `react-native.config.js`. For example, if you set the Android output directory in `package.json` to `android/tmp`, the `cmakeListsPath` value in `react-native.config.js` needs to be set to `tmp/jni/CMakeLists.txt`.
```

## `turboModule`

This section configures the location of the Typescript and C++ files generated by the `generate turbo-module` command.
Expand Down
8 changes: 8 additions & 0 deletions integration/fixtures/compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codegenConfig": {
"outputDir": {
"ios": "ios/tmp",
"android": "android/tmp"
}
}
}
9 changes: 9 additions & 0 deletions integration/fixtures/compat/react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
dependency: {
platforms: {
android: {
cmakeListsPath: "tmp/jni/CMakeLists.txt",
},
},
},
};
4 changes: 4 additions & 0 deletions integration/fixtures/compat/ubrn.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rust:
repo: https://github.com/ianthetechie/uniffi-starter
branch: main
manifestPath: rust/foobar/Cargo.toml
Loading
Loading