zkmopro / mopro

Making client-side proving on mobile simple.
https://zkmopro.org
Apache License 2.0
131 stars 35 forks source link

Fix Android build #81

Closed oskarth closed 9 months ago

oskarth commented 9 months ago

Problem

Currently Android CI build doesn't work. Some users have reported similar problems locally.

Details

User report

 ./scripts/build_android.sh config-example.toml 
= note: ld: unknown options: --version-script=/var/folders/hj/cgm2qndd02b6qbvv2rc46k080000gn/T/rustcNXwgFX/list --no-undefined-version --as-needed -Bstatic -Bdynamic --eh-frame-hdr -z --gc-sections -z -z
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `ark-circom` (lib) due to 1 previous error 

Failing CI

ELF (EM: 183)
          /usr/bin/ld: /home/runner/work/mopro/mopro/mopro-ffi/target/aarch64-linux-android/debug/deps/ark_circom-0a9603226fc50811.ark_circom.d89761b3e14fbdfb-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/runner/work/mopro/mopro/mopro-ffi/target/aarch64-linux-android/debug/deps/ark_circom-0a9603226fc50811.ark_circom.d89761b3e14fbdfb-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183)
          /usr/bin/ld: /home/runner/work/mopro/mopro/mopro-ffi/target/aarch64-linux-android/debug/deps/ark_circom-0a9603226fc50811.ark_circom.d89761b3e14fbdfb-cgu.0.rcgu.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status

error: could not compile `ark-circom` (lib) due to 1 previous error

Latest working

I try to revert to the latest commit (7b2413f) that passes CI
and it can still successfully build for android
so I think we made some changes that cause the CI to fail

Other notes

One difference between build_ios and build_android is:

# Update bindings
cd "${PROJECT_DIR}"
./scripts/update_bindings.sh $CONFIG_FILE

in build_ios, perhaps this leads to different behavior when building for android in some circumstances? With the new toml config format.

Acceptance criteria

Android build works locally and on CI.

oskarth commented 9 months ago

Also need to adjust target dir to root

vivianjeng commented 9 months ago
I try to revert to the latest commit (7b2413f) that passes CI
and it can still successfully build for android
so I think we made some changes that cause the CI to fail

I didn't notice that the previous CI also don't pass but the error is not caught (so it passed) I think it is because of the architecture but when I tried x86_64 it shows

note: /usr/bin/ld: cannot find -llog: No such file or directory
          collect2: error: ld returned 1 exit status

I am still figuring this out

ethzanity commented 9 months ago

Thanks @oskarth and @vivianjeng -- I managed to resolve the issue by adding a .cargo/config.toml file specifying the exact clang linker to be used, as follows

[target.x86_64-linux-android] linker = "{NDK_PATH}/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android21-clang" I noticed that there was a mac popup window (either unpacking or authenticating the binaries) that appeared the first time I compiled successfully.

Separately, in line 97 of config-example-android.toml I had to add ${PROJECT_DIR} in front of cp ${PROJECT_DIR}/target/${ARCHITECTURE}/${LIB_DIR}/libmopro_ffi.so jniLibs/${FOLDER}/libuniffi_mopro.so

vivianjeng commented 9 months ago

Thank you @ethzanity I also solved CI with this: https://github.com/rust-lang/rustup/issues/2872#issuecomment-1158238378 See: #82

oskarth commented 9 months ago

I guess we can close this issue now