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

chore: compile mobile with nwaku support (android) #3232

Open
6 of 8 tasks
richard-ramos opened this issue Jan 8, 2025 · 5 comments
Open
6 of 8 tasks

chore: compile mobile with nwaku support (android) #3232

richard-ramos opened this issue Jan 8, 2025 · 5 comments
Assignees
Labels
effort/weeks Estimated to be completed in a few weeks

Comments

@richard-ramos
Copy link
Member

richard-ramos commented Jan 8, 2025

Mobile should compile in android while using nwaku. This means all dependencies must be met, and no missing libraries warning should be visible.

  • Create custom library with a single HelloWorld function for all android architectures
  • Compile status-go including the custom library
  • Modify status-mobile to load a custom library in status-mobile
  • Run status-mobile in the simulator and in a device, and make sure the "HelloWorld" is displayed correctly in the logs
  • Replace custom library for libwaku
  • Run status-mobile in the simulator and in a device, and make sure the nwaku node is created with wakuNew from libwaku
  • Nix flake for building nwaku and modify status-mobile to use this nwaku flake
  • Modify CI build scripts
@Ivansete-status Ivansete-status moved this to In Progress in Waku Jan 8, 2025
@Ivansete-status Ivansete-status added the effort/weeks Estimated to be completed in a few weeks label Jan 8, 2025
@jakubgs
Copy link
Contributor

jakubgs commented Jan 13, 2025

Building status-go with included nim-waku(also stupidly known as nwaku) is not going to be trivial, for at least 3 reasons:

  1. Fetching status-go with nim-waku with included submodules = true takes about 4 minutes every time.
  2. nim-waku requires a custom build of Nim compiler due to use of nimbus-build-system which pins specific version.
  3. nim-waku cannot be built using a Nix derivation because it contains Rust submodules which require network access.

For these reasons it is not feasibly to simply add nim-waku as a submodule. We need a solution which will allow us to cache an already built version of nim-waku, otherwise developers both on status-go and status-mobile side will waste a lot of time re-compiling nim-waku, probably multiple times a day.

To achieve this in a clean manner the best possible solution is probably to develop a Nix flake setup for nim-waku. The same way we did it for nim-codex repository which also includes a Rust circom-compat-ffi submodule, which needed its own Nix flake.

@richard-ramos
Copy link
Member Author

@markoburcul, @jakubgs:

To add a bit more of details of what should the .flake for nwaku support to compile libwaku for mobile:

nwaku:

  1. For building RLN, this is done with rust and cross-rs in this script. cross-rs uses docker
  2. AndroidNDK should be installed (should be part of the dependencies in nix)
  3. An env variable ANDROID_NDK_HOME should be setup pointing to AndroidNDK
  4. This is the list of targets we need to execute
make libwaku-android-amd64
make libwaku-android-arm64
# compilation fails for the following targets, but it should still be possible to indicate to nix we want to compile these targets
# make libwaku-android-arm
# make libwaku-android-x86

This will generate the following folders inside ./build/android/. Each one of these folders should contain 2 shared objects: librln.so and libwaku.so

./arm64-v8a
./armeabi-v7a
./x86
./x86_64

@richard-ramos
Copy link
Member Author

richard-ramos commented Jan 14, 2025

@Ivansete-status @gabrielmer @jakubgs @markoburcul

To build status-mobile with libwaku, I'm currently doing this manually. Do note i'm using specific branches of status-go and status-mobile

  1. Open Android Studio, and run the emulator

# Clone the repos
git clone https://github.com/status-im/status-go.git
git clone https://github.com/status-im/status-mobile.git

# Build libwaku
cd status-go
export STATUS_GO_SRC_OVERRIDE=$(pwd)
git checkout feature/nwaku-in-status
git submodule init
git submodule update
cd third_party/nwaku
make update
make libwaku-android-amd64
make libwaku-android-arm64

# Create .aar
cd ../../../status-mobile
git checkout nwaku-in-status
TEMP_DIR=$(mktemp -d)
mkdir $TEMP_DIR/jni
cp -R ../status-go/third_party/nwaku/build/android/arm64-v8a $TEMP_DIR/jni/.
cp -R ../status-go/third_party/nwaku/build/android/x86_64 $TEMP_DIR/jni/.
echo '<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mylibrary" />' > $TEMP_DIR/AndroidManifest.xml
pushd $TEMP_DIR
zip -r libwaku.aar *
popd $TEMP_DIR
cp $TEMP_DIR/libwaku.aar ./android/app/libs/.
rm -rf $TEMP_DIR

# Build status-mobile
make run-clojure 
# Wait until it says `[:mobile] Build completed. (2034 files, 26 compiled, 0 warnings, 9.73s)` and press Ctrl+C

make run-android

@jakubgs
Copy link
Contributor

jakubgs commented Jan 16, 2025

Thanks, that's very helpful.

markoburcul added a commit to vacp2p/zerokit that referenced this issue Jan 22, 2025
Referenced issue: waku-org/nwaku#3232

Signed-off-by: markoburcul <[email protected]>
markoburcul added a commit to vacp2p/zerokit that referenced this issue Jan 23, 2025
markoburcul added a commit that referenced this issue Jan 23, 2025
It includes also androidndk and files needed for nimbus-build-system

Referenced issue: #3232

Signed-off-by: markoburcul <[email protected]>
markoburcul added a commit that referenced this issue Jan 23, 2025
It includes also androidndk and files needed for nimbus-build-system

Referenced issue: #3232

Signed-off-by: markoburcul <[email protected]>
@markoburcul
Copy link
Contributor

I've managed to overcome building the Nim compiler using nimbus-build-system. The issue I've encountered is that nwaku is using Nim 2.0.12 while for nim-codex it is 2.0.14.I will put this PR in draft so whoever reads this can see the progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/weeks Estimated to be completed in a few weeks
Projects
Status: In Progress
Development

No branches or pull requests

4 participants