-
Notifications
You must be signed in to change notification settings - Fork 343
Description
Introduction
I would like to understand the appetite and work required to get Android and iOS support from Rusty V8. I know Android builds have previously been a included as a feature of Rusty V8, but were sadly short-lived. To my knowledge iOS builds have been attempted by community members but no support has landed in Rusty V8. I have a proof-of-concept of Deno Runtime interacting with a WebView on Android, but before I go much further with this wanted to see if there was any motivation to land support for pre-built Android & iOS binaries. If there is no motivation for this feature I can alternatively start exploring NativeScript, however, I believe Rusty V8 is a better solution due to Deno Core & Deno Runtime.
The current state of Deno on mobile (as I understand it)
Important
I am updating this section as progress occurs and as people provide additional information.
I've been whittling away at a prototype over the last few months and I've collated the knowledge I have gained from my attempts getting Deno running on Android & iOS. I know others have also been making attempts in this department and welcome people to chime in, as seen by the revert commits that reference disable Android in ci.
Android
Rusty V8
I have had success with getting [email protected] working on Android, however you need to cherry-pick the patch to disable relative vtable on Android.
For anyone following along at home, you can find the [email protected] binaries for Android on my fork or use RUSTY_V8_MIRROR=https://github.com/aidant/rusty_v8/releases/download
(no promises for support).
I and others have been making attempts to build latest for Android and are encountering fatal error: 'features.h' file not found
. I'm not sure if it also applies to this issue, but I saw it stated that clang downloaded from chromium does not include libclang shared libraries. @devsnek if your discussions with Chromium team are public could you please provide the tracking issue?
Deno Core
[email protected]
(compatible with [email protected]) works without any modifications on Android.
Deno Runtime
deno_runtime@5c54dc5
(compatible with [email protected]
) works on Android when combined with a cherry-pick of allowing webgpu to build on unsupported platforms and the removal of the FFI feature.
outdated FFI __clear_cache issue
Without removing the FFI feature, the application errors at runtime with dlopen failed: cannot locate symbol "__clear_cache"
. Decompiling the binary I can see the __clear_cache
symbol is referenced indirectly via op_ffi_unsafe_callback_create
-> libffi::middle::Closure::new
-> low::prep_closure
-> raw::ffi_prep_closure_loc
-> __builtin___clear_cache
hence the removal of the FFI feature.
I am not experienced enough with this ecosystem to understand what is needed to fix the root cause of the __clear_cache
issue. If anyone has any pointers that would be appreciated. Otherwise if I get some free time I intend to look into this myself at some point.
I believe I have identified the fix for the __clear_cache
runtime error in the FFI feature. You need to specify the compiler-rt runtime libraries using cargo::rustc-link-search=...
and cargo::rustc-link-lib=static=clang_rt.builtins-{target_arch}-{target_os}
. You can see my work-in-progress commit which I'll turn into a PR once its ready.
A side note, I've had to pipe stdout and stderr to __android_log_write
to prevent console.log
from entering the void. I was thinking it would be good to add support for the log
crate as an option for Stdio
. As then logs can be directly sent to __android_log_write
or the equivalent on iOS. This is a feature I could probably open a PR for.
iOS
Rusty V8
outdated iOS attempts
So far I have been unsuccessful in getting [email protected] compiled for iOS.
I've followed the cross-compiling for iOS guide and updated the build.rs
script to include the keys recommended for iOS. I've had to stray from the recommendations by omitting v8_enable_i18n_support = false
(seems its required for src/icu.rs
) and added v8_enable_shared_ro_heap = true
due to v8_enable_pointer_compression = false
. I've also had to apply the patch to remove support for bitcode.
I'm currently running into fatal error: 'cstdint' file not found
. I suspect the cause is clang downloaded from chromium does not include libclang shared libraries but am out of my depth with my current knowledge.
I've been able to get [email protected] to compile for iOS, but I have been unable to test it yet due to issues in Deno Runtime described bellow.
I've followed the cross-compiling for iOS guide and updated the build.rs
script to include the keys recommended for iOS. I've had to stray from the recommendations by omitting v8_enable_i18n_support = false
(seems its required for src/icu.rs
) and added v8_enable_shared_ro_heap = true
due to v8_enable_pointer_compression = false
. For some reason I have had to include -isysroot
flag to the bindgen clang args, while others have not. I've also had to apply the patch to remove support for bitcode and to not rely on external modules for version parsing which involves forking denoland/chromium_build
. Note I do not think these patches are required for latest.
There is also an issue where the file for RUSTY_V8_SRC_BINDING_PATH
is missing. This is because [email protected] does not build for iOS normally and therefore, the gen folder does not include the bindings file for iOS. Latest Rusty V8 includes a patch which respects explicitly set RUSTY_V8_SRC_BINDING_PATH but this is not included in [email protected].
Deno Core
N/A
Deno Runtime
I've not been able to get Deno Runtime working on iOS yet, a bunch of the extensions don't compile for iOS without patches, I'll see if I can tackle this at some point.
From my understanding (please correct me if I am wrong), the FFI feature will also need to be disabled on iOS due to Apple requiring statically linked libraries. Edit, you can use dynamic modules, but you have to embed them in your app’s binary. However, due to Turbocall the FFI feature will not work as is due to absence of writable executable memory in iOS apps.