Skip to content

React Native support#1423

Merged
haaawk merged 2 commits intotursodatabase:mainfrom
ospfranco:osp/react-native
Jun 25, 2024
Merged

React Native support#1423
haaawk merged 2 commits intotursodatabase:mainfrom
ospfranco:osp/react-native

Conversation

@ospfranco
Copy link
Contributor

Adds the necessary scripts to build the C bindings for iOS and Android which the in turn only need to be dropped into iOS/Android projects to be used via Obj-C++ or Android's JNI.

For my specific use case I use them in op-sqlite.

@haaawk
Copy link
Collaborator

haaawk commented Jun 24, 2024

Some CI checks are failing @ospfranco

[dependencies]
bytes = "1.5.0"
lazy_static = "1.4.0"
libsql = { path = "../../libsql", features = ["encryption"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not an acceptable change. Most of our projects that use C bindings depend on the encryption feature.

edition = "2021"

[lib]
crate-type = ["cdylib", "staticlib"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Removing cdylib for all targets is probably not acceptable.

hyper-rustls = { version = "0.25", features = ["webpki-roots"]}

[profile.release]
strip = "symbols"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is something we need to talk about. Removing symbols makes debugging really hard. @penberg @MarinPostma @LucioFranco do you have any opinion about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried this to reduce the size of the binary, Rust binaries are way to large for mobile targets. Currently with symbol stripping the binary sits at 60mbs, which is way too much.

Recently wrote more about this:

https://ospfranco.com/rust-reduce-binary-size/

I can remove it, but don't have the time to see how to apply stripping and lto optimization for conditional targets, did not find any documentation on how to do it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then maybe comment it out with a note that it should be uncommented for android/ios builds to reduce the size of the binary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already removed, I commented it out

[toolchain]
profile = "default"
channel = "1.78.0"
targets = ["x86_64-apple-ios", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android", "i686-linux-android"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need a desktop targets for linux and macos as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want, it makes it easier to set up cross compilation on new machines as you don't have to run the rustup install target ... commands but this is entirely optional

Copy link
Contributor

Choose a reason for hiding this comment

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

This force the installation of too many toolchains that are useless most of the time, and it just broke my installation by creating conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to remove it

Copy link
Collaborator

Choose a reason for hiding this comment

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

How did it create conflicts? It seems pretty harmless except for using some disk space, no?

@ospfranco
Copy link
Contributor Author

ospfranco commented Jun 24, 2024

Thanks for taking a look, however, I'm currently swamped with work and next week I'm going on vacation for several months. Feel free to take over this PR and modify it as you see fit:

  • The changes on build.rs are reversible
  • Encryption seems to be compiling sqlcipher (?) via cmake, which also includes OpenSSL flags, the problem the compilation step is hard to integrate with Android (and that's why I had to disable it). Someone else that knows the internals of libsql should give it a try.
  • The rest seem trivial

After all is done and said, you only need to follow the guide I left you on notion to produce a static lib and run that against the opsqlite sample app. Once the emulator starts and everything is green you are ready to go.

P.S. if you do turn on encryption, it will require a modification to the bindings to send the encryption key from JS, so, open a PR when the time comes and I will take a look.

@haaawk
Copy link
Collaborator

haaawk commented Jun 25, 2024

Thanks for taking a look, however, I'm currently swamped with work and next week I'm going on vacation for several months. Feel free to take over this PR and modify it as you see fit:

I'm not sure I will have capacity to take this PR over. Could you please finish it to the state that's mergable. Right now multiple CI checks are failing for it so it is impossible to accept such work and integrate it into the repository.

  • The changes on build.rs are reversible

What does that mean? They are not needed? The changes that are required by Android and iOS need to be merged and if they are not compatible with other targets then they should be guarded with android or ios feature.

  • Encryption seems to be compiling sqlcipher (?) via cmake, which also includes OpenSSL flags, the problem the compilation step is hard to integrate with Android (and that's why I had to disable it). Someone else that knows the internals of libsql should give it a try.

It's ok to disable the encryption for Android and maybe iOS for now but it should be done only for that targets not for all targets which breaks them.

  • The rest seem trivial

After all is done and said, you only need to follow the guide I left you on notion to produce a static lib and run that against the opsqlite sample app. Once the emulator starts and everything is green you are ready to go.

Could you paste a link to that guide please? I haven't seen it yet.

P.S. if you do turn on encryption, it will require a modification to the bindings to send the encryption key from JS, so, open a PR when the time comes and I will take a look.

Add steps for Android

PR comments
@ospfranco
Copy link
Contributor Author

ospfranco commented Jun 25, 2024

Leaving the guide to submitting updates to op-sqlite here for future reference:

https://ospfranco.notion.site/Libsql-4dbbf5793f654eccb9f5f68901224e97

@haaawk haaawk added this pull request to the merge queue Jun 25, 2024
Merged via the queue into tursodatabase:main with commit 30623f9 Jun 25, 2024
@ospfranco ospfranco deleted the osp/react-native branch June 26, 2024 11:58
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.

3 participants