Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Cross compiling on android failed #1027

Closed
hanwencheng opened this issue Apr 23, 2020 · 8 comments · Fixed by #1063
Closed

Cross compiling on android failed #1027

hanwencheng opened this issue Apr 23, 2020 · 8 comments · Fixed by #1063

Comments

@hanwencheng
Copy link

System: Ubuntu 18.04 LTS on Windows WSL2

Following the guide here I could successfully compile Substrate node, but failing on compiling Kusama 0.7.3 (on master branch)

compiled with command

cargo build --target=aarch64-linux-android --release --bins --no-default-features

Get error

error[E0308]: mismatched types
   --> /home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/nix-0.10.0/src/sys/signal.rs:378:41
    |
378 |             SigHandler::SigAction(_) => (flags | SaFlags::SA_SIGINFO).bits(),
    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |
help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
    |
378 |             SigHandler::SigAction(_) => (flags | SaFlags::SA_SIGINFO).bits().try_into().unwrap(),
    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> /home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/nix-0.10.0/src/sys/signal.rs:387:28
    |
387 |         SaFlags::from_bits(self.sigaction.sa_flags).unwrap()
    |                            ^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `i32`
    |
help: you can convert an `i32` to `u32` and panic if the converted value wouldn't fit
    |
387 |         SaFlags::from_bits(self.sigaction.sa_flags.try_into().unwrap()).unwrap()
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> /home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/nix-0.10.0/src/sys/socket/mod.rs:800:29
    |
800 |         libc::bind(fd, ptr, len as c_int)
    |                             ^^^^^^^^^^^^ expected `u32`, found `i32`
    |
help: you can convert an `i32` to `u32` and panic if the converted value wouldn't fit
    |
800 |         libc::bind(fd, ptr, (len as c_int).try_into().unwrap())
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Compiling mio-extras v2.0.6
   Compiling sha2 v0.8.1
   Compiling sha-1 v0.8.2
   Compiling sha3 v0.8.2
   Compiling hmac v0.7.1
   Compiling pbkdf2 v0.3.0
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `nix`.
warning: build failed, waiting for other jobs to finish...
error: build failed
@tomaka
Copy link
Contributor

tomaka commented Apr 23, 2020

The shared_memory library depends on a version old version of nix.
cc elast0ny/shared_memory#32

Ideally we shouldn't introduce even more platform-specific code, but as a temporary fix it is possible to disable shared_memory on Android:

diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml
index 48aae981..e4dddac8 100644
--- a/parachain/Cargo.toml
+++ b/parachain/Cargo.toml
@@ -24,7 +24,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", op
 parking_lot = { version = "0.10.0", optional = true }
 log = { version = "0.4.8", optional = true }
 
-[target.'cfg(not(target_os = "unknown"))'.dependencies]
+[target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
 shared_memory = { version = "0.10.0", optional = true }
 
 [features]
diff --git a/parachain/src/wasm_executor/mod.rs b/parachain/src/wasm_executor/mod.rs
index 64c27278..2b64eb3b 100644
--- a/parachain/src/wasm_executor/mod.rs
+++ b/parachain/src/wasm_executor/mod.rs
@@ -101,7 +101,7 @@ pub enum Error {
 	#[display(fmt = "WASM worker error: {}", _0)]
 	External(String),
 	#[display(fmt = "Shared memory error: {}", _0)]
-	#[cfg(not(target_os = "unknown"))]
+	#[cfg(not(any(target_os = "android", target_os = "unknown")))]
 	SharedMem(shared_memory::SharedMemError),
 }
 
diff --git a/parachain/src/wasm_executor/validation_host.rs b/parachain/src/wasm_executor/validation_host.rs
index 84be3dee..0f123349 100644
--- a/parachain/src/wasm_executor/validation_host.rs
+++ b/parachain/src/wasm_executor/validation_host.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
 
-#![cfg(not(target_os = "unknown"))]
+#![cfg(not(any(target_os = "android", target_os = "unknown")))]
 
 use std::{process, env, sync::Arc, sync::atomic, mem};
 use codec::{Decode, Encode, EncodeAppend};

@hanwencheng
Copy link
Author

hanwencheng commented Apr 23, 2020

With these patches, I got the following error

error: failed to run custom build command for `jemalloc-sys v0.3.2`

Caused by:
  process didn't exit successfully: `/home/hanwen/Projects/polkadot/target/release/build/jemalloc-sys-325c06c5496cd499/build-script-build` (exit code: 101)
--- stdout
TARGET=aarch64-linux-android
HOST=x86_64-unknown-linux-gnu
NUM_JOBS=12
OUT_DIR="/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out"
BUILD_DIR="/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out/build"
SRC_DIR="/home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.3.2"
OPT_LEVEL = Some("3")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-unknown-linux-gnu")
CC_aarch64-linux-android = None
CC_aarch64_linux_android = Some("/home/hanwen/Library/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang")
CFLAGS_aarch64-linux-android = None
CFLAGS_aarch64_linux_android = Some("-std=gnu11 -fPIC -D OS_ANDROID -D ANDROID")
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CC="/home/hanwen/Library/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
CFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC --target=aarch64-linux-android -std=gnu11 -fPIC -D OS_ANDROID -D ANDROID"
JEMALLOC_REPO_DIR="jemalloc"
JEMALLOC_SRC_DIR="/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out/jemalloc"
cargo:rustc-cfg=prefixed
--with-jemalloc-prefix=_rjem_
running: "sh" "/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out/jemalloc/configure" "--disable-cxx" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=aarch64-linux-android" "--build=x86_64-unknown-linux-gnu" "--prefix=/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out"
checking for xsltproc... false
checking for aarch64-linux-android-gcc... /home/hanwen/Library/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang
checking whether the C compiler works... no

--- stderr
configure: error: in `/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out/build':
configure: error: C compiler cannot create executables
See `config.log' for more details
thread 'main' panicked at 'command did not execute successfully: "sh" "/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out/jemalloc/configure" "--disable-cxx" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=aarch64-linux-android" "--build=x86_64-unknown-linux-gnu" "--prefix=/home/hanwen/Projects/polkadot/target/aarch64-linux-android/release/build/jemalloc-sys-b79acd8a819a4581/out"
expected success, got: exit code: 77', /home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/jemalloc-sys-0.3.2/build.rs:392:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

warning: build failed, waiting for other jobs to finish...

@tomaka
Copy link
Contributor

tomaka commented Apr 23, 2020

That's unrelated to this issue

@hanwencheng
Copy link
Author

hanwencheng commented Apr 24, 2020

With parity-util-mem = { version = "*", default-features = false, features = [] } in ./Cargo.toml

has error of

error[E0425]: cannot find function `iterate_sockets_info` in this scope
  --> /home/hanwen/.cargo/registry/src/github.com-1ecc6299db9ec823/netstat2-0.8.1/src/integrations/shared_api.rs:11:5
   |
7  | / pub fn get_sockets_info(
8  | |     af_flags: AddressFamilyFlags,
9  | |     proto_flags: ProtocolFlags,
10 | | ) -> Result<Vec<SocketInfo>, Error> {
11 | |     iterate_sockets_info(af_flags, proto_flags)?.collect()
   | |     ^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `get_sockets_info`
12 | | }
   | |_- similarly named function `get_sockets_info` defined here

error: aborting due to previous error

@hanwencheng
Copy link
Author

when validation_host is disabled it cause the problem in wasm executor

error[E0412]: cannot find type `ValidationPool` in this scope
  --> parachain/src/wasm_executor/mod.rs:74:13
   |
74 |     Remote(&'a ValidationPool),
   |                ^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `ValidationPool` in this scope
  --> parachain/src/wasm_executor/mod.rs:76:17
   |
76 |     RemoteTest(&'a ValidationPool),
   |                    ^^^^^^^^^^^^^^ not found in this scope

@tomaka
Copy link
Contributor

tomaka commented May 4, 2020

In that file (wasm_executor/mod.rs), try to replace all the
#[cfg(target_os = "unknown")] with #[cfg(any(target_os = "unknown", target_os = "android"))]
and all the
#[cfg(not(target_os = "unknown"))] with #[cfg(not(any(target_os = "unknown", target_os = "android")))]

@hanwencheng
Copy link
Author

Thanks, it works!

Does the shared memory only related to the validation process, and that's why we can disable it in Android since the Android node only works as a light client?

@tomaka
Copy link
Contributor

tomaka commented May 4, 2020

Yes.

@hanwencheng hanwencheng reopened this May 4, 2020
svyatonik added a commit that referenced this issue Jun 25, 2021
23dda62 Rococo <> Wococo messages relay (#1030)
bcde21d Update the wasm builder to substrate master (#1029)
a8318ce Make target signer optional when sending message. (#1018)
f8602e1 Fix insufficient balance when send message. (#1020)
d95c0a7 greedy relayer don't need message dispatch to be prepaid if dispatch is supposed to be paid at the target chain (#1016)
ad5876f Update types. (#1027)
116cbbc CI: fix starting the pipeline (#1022)
7e0fadd Add temporary `canary` job (#1019)
6787091 Update types to contain dispatch_fee_payment (#1017)
03f79ad Allow Root to assume SourceAccount. (#1011)
372d019 Return dispatch_fee_payment from message details RPC (#1014)
604eb1c Relay basic single-bit message dispatch results back to the source chain (#935)
bf52fff Use plain source_queue view when selecting nonces for delivery (#1010)
fc5cf7d pay dispatch fee at target chain (#911)
1e35477 Bump Substrate to `286d7ce` (#1006)
7ad07b3 Add --only-mandatory-headers mode (#1004)
5351dc9 Messages relayer operating mode (#995)
9bc29a7 Rococo <> Wococo relayer balance guard (#998)
bc17341 rename messages_dispatch_weight -> message_details (#996)
95be244 Bump Rococo and Wococo spec versions (#999)
c35567b Move ChainWithBalances::NativeBalance -> Chain::Balance (#990)
1bfece1 Fix some nits (#988)
334ea0f Increase pause before starting relays again (#989)
7fb8248 Fix clippy in test code (#993)
d60ae50 fix clippy issues (#991)
75ca813 Make sure GRANDPA shares state with RPC. (#987)
da2a38a Bump Substrate (#986)
5a9862f Update submit finality proof weight formula (#981)
69df513 Flag for rejecting all outbound messages (#982)
14d0506 Add script to setup bench machine. (#984)
e74e8ab Move CI from GitHub Actions to GitLab (#814)
c5ca5dd Custom justification verification (#979)
643f10d Always run on-demand headers relay in complex relay (#975)
a35b0ef Add JSON type definitions for Rococo<>Wococo bridge (#977)
0eb83f2 Update cargo.deny (#980)
e1d1f4c Bump Rococo/Wococo spec_version (#976)
deac90d increase pause before starting relays (#974)
68d6d79 Revert to use InspectCmd, bump substrate `6bef4f4` (#966)
66e1508 Avoid hashing headers twice in verify_justification (#973)
a31844f Bump `environmental` dependency (#972)
2a4c29a in auto-relays keep trying to connect to nodes until connection is established (#971)
0e767b3 removed stray file (#969)
b9545dc Serve multiple lanes with single complex relay instance (#964)
73419f4 Correct type error (#968)
bac256f Start finality relay spec-version guards for Rococo <> Wococo finality relays (#965)
bfd7037 pass source and target chain ids to account_ownership_proof (#963)
8436073 Upstream changes from Polkadot repo (#961)
e58d851 Increase account endowment amount (#960)

git-subtree-dir: bridges
git-subtree-split: 23dda6248236b27f20d76cbedc30e189cc6f736c
ghost pushed a commit that referenced this issue Jun 25, 2021
23dda62 Rococo <> Wococo messages relay (#1030)
bcde21d Update the wasm builder to substrate master (#1029)
a8318ce Make target signer optional when sending message. (#1018)
f8602e1 Fix insufficient balance when send message. (#1020)
d95c0a7 greedy relayer don't need message dispatch to be prepaid if dispatch is supposed to be paid at the target chain (#1016)
ad5876f Update types. (#1027)
116cbbc CI: fix starting the pipeline (#1022)
7e0fadd Add temporary `canary` job (#1019)
6787091 Update types to contain dispatch_fee_payment (#1017)
03f79ad Allow Root to assume SourceAccount. (#1011)
372d019 Return dispatch_fee_payment from message details RPC (#1014)
604eb1c Relay basic single-bit message dispatch results back to the source chain (#935)
bf52fff Use plain source_queue view when selecting nonces for delivery (#1010)
fc5cf7d pay dispatch fee at target chain (#911)
1e35477 Bump Substrate to `286d7ce` (#1006)
7ad07b3 Add --only-mandatory-headers mode (#1004)
5351dc9 Messages relayer operating mode (#995)
9bc29a7 Rococo <> Wococo relayer balance guard (#998)
bc17341 rename messages_dispatch_weight -> message_details (#996)
95be244 Bump Rococo and Wococo spec versions (#999)
c35567b Move ChainWithBalances::NativeBalance -> Chain::Balance (#990)
1bfece1 Fix some nits (#988)
334ea0f Increase pause before starting relays again (#989)
7fb8248 Fix clippy in test code (#993)
d60ae50 fix clippy issues (#991)
75ca813 Make sure GRANDPA shares state with RPC. (#987)
da2a38a Bump Substrate (#986)
5a9862f Update submit finality proof weight formula (#981)
69df513 Flag for rejecting all outbound messages (#982)
14d0506 Add script to setup bench machine. (#984)
e74e8ab Move CI from GitHub Actions to GitLab (#814)
c5ca5dd Custom justification verification (#979)
643f10d Always run on-demand headers relay in complex relay (#975)
a35b0ef Add JSON type definitions for Rococo<>Wococo bridge (#977)
0eb83f2 Update cargo.deny (#980)
e1d1f4c Bump Rococo/Wococo spec_version (#976)
deac90d increase pause before starting relays (#974)
68d6d79 Revert to use InspectCmd, bump substrate `6bef4f4` (#966)
66e1508 Avoid hashing headers twice in verify_justification (#973)
a31844f Bump `environmental` dependency (#972)
2a4c29a in auto-relays keep trying to connect to nodes until connection is established (#971)
0e767b3 removed stray file (#969)
b9545dc Serve multiple lanes with single complex relay instance (#964)
73419f4 Correct type error (#968)
bac256f Start finality relay spec-version guards for Rococo <> Wococo finality relays (#965)
bfd7037 pass source and target chain ids to account_ownership_proof (#963)
8436073 Upstream changes from Polkadot repo (#961)
e58d851 Increase account endowment amount (#960)

git-subtree-dir: bridges
git-subtree-split: 23dda6248236b27f20d76cbedc30e189cc6f736c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants