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

Draft documentation #72

Merged
merged 4 commits into from
Oct 2, 2024
Merged

Draft documentation #72

merged 4 commits into from
Oct 2, 2024

Conversation

jhugman
Copy link
Owner

@jhugman jhugman commented Aug 17, 2024

First cut of the reference sections of the documentation.

The 48a01ca commit is likely the most interesting to readers and reviewers.

This is not ready to merge, but should be instructive nevertheless.

This is likely best reviewed via mdbook serve docs.

@jhugman jhugman requested review from wesc and zzorba August 17, 2024 16:58
@jhugman jhugman marked this pull request as draft August 17, 2024 16:58
Copy link
Collaborator

@zzorba zzorba left a comment

Choose a reason for hiding this comment

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

Looks good, a couple small typos and one or two organizational notes.

Happy to review again when its finalized.

Running the following command from within your project:

```sh
alias ubrn=$(pwd)/node_modules/.bin/uniffi-bindgen-react-native
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be useful to include a comment about mono-repo support, or suggest they use this command instead which should work in both repo structures

UBRN_BIN=$(node -p "require('path').resolve(require.resolve('uniffi-bindgen-react-native/package.json'), '../../.bin/uniffi-bindgen-react-native')")

```
The checkout command can be operated in two ways, either:
1. with a `REPO` argument and optional `--branch` argument. OR
2. with a config file which may specify a repo and branch, or just a `directory`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's implied, but might be worth mentioning that you can just include a rust crate under rust_modules/{NAME}/Cargo.toml instead of executing this step.


## `build android`

Build the crate for use on an Android device or emulator, using `cargo ndk`, which in turn uses Android Native Development Kit.
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing that we had to do here, was make sure that we were linking to the correct NDK.

This changes from RN version to version, but in our usage we had to set an ANDROID_NDK_HOME variable in our script for this to pick up the appropriate version.

You can find the version you need in your react-native android/build.gradle file in the ndkVersion variable.

export ANDROID_NDK_HOME=${ANDROID_SDK_ROOT}/ndk/26.1.10909125/

Once the library files (one for each target) are created, they are copied into the `jniLibs` specified by the YAML configuration.

```admonish note
React Native requires that the Rust library be built as a static library. The CMake based build will combine the C++ with the static library into a shared object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like it might be best promoted to a 'preparing your Rust library' section. It could call this out, and maybe link to the Uniffi docs about how to tag functions to be exported?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good plan. I will address a "Prepare your Rust library" in a different PR.



## `generate bindings`
Generate the just the bindings. In most cases, this command should not be called directly, but with the build, with `--and-generate`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove extra the, Generate just the bindings


This is to configure the build steps for the Rust, the bindings, and the turbo-module code for iOS.

This section can be completely missed out, as sensible defaults are provided, but can also be customized:
Copy link
Collaborator

Choose a reason for hiding this comment

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

grammar nit: completely missed out feels strange, maybe 'completely omitted'. Don't feel strongly, if this is a british vs american english thing.


This list of [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) of file that should not be generated or overwritten by the `--and-generate` flag, and the `generate turbo-module` command.

This is useful if you want to customize one or more of the generated files, and not losen those changes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"not lose those changes"

- For iOS:
- a `Module.h` and `Module.mm` file which receives the codegen'd install method calls, and digs around to find the `jsi::Runtime` and `react::CallInvoker`. It then calls into the generic C++ install code.
- To build for iOS:
- A podspec file to tell Xcode about the generated files, and the framework name/location.
Copy link
Collaborator

Choose a reason for hiding this comment

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

framework name/location for the compiled rust library.

.trim_matches('-')
.trim_matches('_')
.to_string()
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm going to start slowly work out where this is needed and where it isn't. Selectively adding trim_react_native_2 to defaults until everything works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be something good to ask Johannes in our matrix room, he seems to know about these things.

@jhugman jhugman marked this pull request as ready for review October 2, 2024 19:35
@jhugman jhugman requested a review from zzorba October 2, 2024 19:35
@jhugman jhugman merged commit 11c4f3d into main Oct 2, 2024
1 check passed
@jhugman jhugman deleted the jhugman/docs-1 branch October 2, 2024 19:55
Copy link
Collaborator

@zzorba zzorba left a comment

Choose a reason for hiding this comment

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

LGTM

```json
{
"scripts": {
"ubrn": "npx uniffi-bindgen-react-native"
Copy link
Collaborator

Choose a reason for hiding this comment

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

so fwiw at least in my repo, just having uniffi-bindgen-react-native as a dependency was seemingly enough to let me call yarn ubrn without issue? Maybe that's a yarn thing, I think its fine to keep this documentation since it won't hurt.

jhugman pushed a commit that referenced this pull request Oct 7, 2024
Relates to: #109

I'm not sure if this is strictly necessary anymore because once I had it
done, I realized that #72 has stripped the `reactnative` prefix from the
package name again. So technically UBRN's current output should work
with what create-react-native-library generates without this change
applied. It might not hurt either way though?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants