Skip to content

Commit 171408b

Browse files
committed
feat: Build chain-wallet-lib with 16kb page memory size.
1 parent 60ccc96 commit 171408b

File tree

23 files changed

+211
-185
lines changed

23 files changed

+211
-185
lines changed

Cargo.lock

Lines changed: 77 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.71.0"
2+
channel = "1.89.0"
33
components = ["rust-src", "rustfmt", "rust-std"]

src/catalyst-toolbox/catalyst-toolbox/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ chain-ser = { path = "../../chain-libs/chain-ser" }
2727
chain-storage = { path = "../../chain-libs/chain-storage" }
2828
chain-time = { path = "../../chain-libs/chain-time" }
2929
chain-impl-mockchain = { workspace = true }
30-
time = { version = "0.3", features = ["formatting", "parsing", "macros"] }
30+
time = { version = "0.3.29", features = ["formatting", "parsing", "macros"] }
3131
itertools = "0.10"
3232
jcli = { path = "../../jormungandr/jcli" }
3333
jormungandr-lib = { workspace = true }

src/chain-wallet-libs/Earthfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
VERSION 0.7
2+
3+
cordova-build:
4+
# It is needed to use an older version of rustc
5+
FROM rust:1.89.0-slim-bullseye
6+
7+
# Install deps
8+
RUN rustup component add rustfmt
9+
# Install python
10+
RUN apt update
11+
RUN apt -y install python3
12+
RUN python3 --version
13+
# Install uniffi_bindgen
14+
RUN cargo install --version 0.21.1 uniffi_bindgen
15+
RUN uniffi-bindgen --version
16+
# Install podman needed for cross
17+
RUN apt-get -y install podman
18+
19+
# Install Android NDK 29
20+
RUN wget -q https://dl.google.com/android/repository/android-ndk-r29-linux.zip -O /tmp/ndk.zip && \
21+
unzip -q /tmp/ndk.zip -d /opt && \
22+
rm /tmp/ndk.zip
23+
ENV ANDROID_NDK_HOME=/opt/android-ndk-r29
24+
25+
26+
COPY --dir ../../+rust-source/src \
27+
../../+rust-source/tests \
28+
../../+rust-source/Cargo.toml \
29+
../../+rust-source/Cargo.lock \
30+
./catalyst-core
31+
RUN ls ./catalyst-core/src/chain-wallet-libs/bindings/wallet-cordova/src/android
32+
RUN cd ./catalyst-core && cargo b -p wallet-uniffi --release
33+
RUN cd ./catalyst-core/src/chain-wallet-libs/bindings/wallet-cordova/scripts && RUSTFLAGS="-C embed-bitcode" python3 build_android.py
34+
RUN ls ./catalyst-core/src/chain-wallet-libs/bindings/wallet-cordova/src/android

src/chain-wallet-libs/bindings/wallet-cordova/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ compatible.
4747

4848
### Android
4949

50-
- [cross](https://github.com/cross-rs/cross) is currently used for building the
51-
native libraries for Android.
50+
- Android NDK >= 29 and ANDROID_NDK_HOME env variable properly set pointing to it.
5251
- [uniffi-bindgen](https://github.com/mozilla/uniffi-rs). The version must be the same one that is used in the `wallet-uniffi` crate. This can be found [here](../wallet-uniffi/Cargo.toml).
5352

5453
### iOS
@@ -86,11 +85,12 @@ cargo b --release
8685
./gen_bindings.sh
8786
```
8887

89-
[build_jni.py](scripts/build_jni.py) in the `scripts` directory will compile the
88+
[build_android.py](scripts/build_android.py) in the `scripts` directory will compile the
9089
Android native libraries, generate the Kotlin bindings, and copy those to this
9190
package in the `src/android` directory.
91+
The script to compile legacy version of the libraries is at [build_jni.py](scripts/build_jni.py)
9292
```
93-
RUSTFLAGS="-C embed-bitcode" python3 build_jni.py
93+
RUSTFLAGS="-C embed-bitcode" python3 build_android.py
9494
```
9595

9696
[build_ios.py](scripts/build_ios.py) in the `scripts` directory will compile the

src/chain-wallet-libs/bindings/wallet-cordova/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wallet-cordova-plugin",
3-
"version": "0.8.3",
3+
"version": "0.8.6",
44
"description": "Jormungandr wallet Cordova Plugin",
55
"cordova": {
66
"id": "wallet-cordova-plugin",

src/chain-wallet-libs/bindings/wallet-cordova/plugin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
<framework src="src/android/jna-compile.gradle" custom="true" type="gradleReference" />
2828

2929

30-
<source-file src="src/android/libs/x86/libuniffi_jormungandr_wallet.so" target-dir="libs/x86" />
31-
<source-file src="src/android/libs/x86_64/libuniffi_jormungandr_wallet.so" target-dir="libs/x86_64" />
32-
<source-file src="src/android/libs/arm64-v8a/libuniffi_jormungandr_wallet.so" target-dir="libs/arm64-v8a" />
33-
<source-file src="src/android/libs/armeabi-v7a/libuniffi_jormungandr_wallet.so" target-dir="libs/armeabi-v7a" />
30+
<source-file src="src/android/libs/i686-linux-android/libuniffi_jormungandr_wallet.so" target-dir="libs/x86" />
31+
<source-file src="src/android/libs/x86_64-linux-android/libuniffi_jormungandr_wallet.so" target-dir="libs/x86_64" />
32+
<source-file src="src/android/libs/aarch64-linux-android/libuniffi_jormungandr_wallet.so" target-dir="libs/arm64-v8a" />
33+
<source-file src="src/android/libs/armv7a-linux-androideabi/libuniffi_jormungandr_wallet.so" target-dir="libs/armeabi-v7a" />
3434
</platform>
3535

3636
<platform name="electron">
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
import subprocess
5+
import shutil
6+
import sys
7+
import os
8+
9+
from directories import rust_build_directory, plugin_directory
10+
11+
libname = "libuniffi_jormungandr_wallet.so"
12+
android_libs_directory = Path("src/android/libs")
13+
14+
15+
# Keep all four targets
16+
targets = {
17+
"aarch64-linux-android": "aarch64-linux-android",
18+
"armv7-linux-androideabi": "armv7a-linux-androideabi",
19+
"i686-linux-android": "i686-linux-android",
20+
"x86_64-linux-android": "x86_64-linux-android",
21+
}
22+
23+
# Set API level and page size
24+
ANDROID_API = "21"
25+
PAGE_SIZE = "16384"
26+
27+
NDK_HOME = os.environ.get("ANDROID_NDK_HOME")
28+
if not NDK_HOME:
29+
print("ERROR: ANDROID_NDK_HOME is not set")
30+
sys.exit(1)
31+
32+
33+
def copy_libs(release=True):
34+
debug_or_release = "release" if release else "debug"
35+
36+
for rust_target, android_target in targets.items():
37+
dst = plugin_directory / android_libs_directory / android_target
38+
dst.mkdir(parents=True, exist_ok=True)
39+
40+
src = rust_build_directory / rust_target / debug_or_release / libname
41+
print(dst)
42+
shutil.copy(src, dst)
43+
44+
45+
def run(release=True):
46+
for rust_target, android_target in targets.items():
47+
cargo_args = [
48+
"cargo", "rustc",
49+
"--target", rust_target,
50+
"-p", "wallet-uniffi",
51+
"--features", "builtin-bindgen",
52+
]
53+
54+
if release:
55+
cargo_args.append("--release")
56+
57+
cargo_args.extend([
58+
"--",
59+
# "-C", f"link-arg=--target={rust_target}",
60+
"-C", f"link-arg=-Wl,-z,max-page-size={PAGE_SIZE}",
61+
"-C", f"linker={NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/{android_target}{ANDROID_API}-clang"
62+
])
63+
64+
print(f"Building target {rust_target}...")
65+
out = subprocess.run(cargo_args)
66+
if out.returncode != 0:
67+
print("Couldn't build target:", rust_target)
68+
sys.exit(1)
69+
70+
copy_libs(release)
71+
72+
73+
if __name__ == "__main__":
74+
run()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dependencies {
2-
implementation 'net.java.dev.jna:jna:5.9.0@aar'
2+
implementation 'net.java.dev.jna:jna:5.18.1@aar'
33
}

src/chain-wallet-libs/bindings/wallet-uniffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wallet-uniffi"
3-
version = "0.8.3"
3+
version = "0.8.6"
44
edition = "2018"
55

66
[lib]

0 commit comments

Comments
 (0)