angelcam / arrow-client

Angelcam Connector - a referential client implementing the Angelcam Arrow protocol
Apache License 2.0
71 stars 18 forks source link

MIPSEL static compilation issues #40

Closed jassycliq closed 3 years ago

jassycliq commented 3 years ago

Thanks for this wonderful project! I've been trying to get the arrow client compiled for the Wyze cam v2 which runs an Ingenic T20 (mipsel based) chipset. Unfortunately, the only toolchain that I could find for it is an uclibc toolchain which required me to go the static build route.

After much trial and error I was finally able to get it to successfully compile by adding the following lines to the static-build bash script:

rustflags = ["-C", "target-feature=+crt-static", "-C", "link-args=-lgcc"]

I've been running this for a few hours without issue but was wondering if if this would cause any issues further down the road or if there is a way to build without this workaround.

operutka commented 3 years ago

Hi @jassycliq! Thank you for your interest in this project.

The script for static linking with MUSL is there mostly as an example. uClibc targets are quite problematic and different GCC toolchains may require different compilation options. Those options that you mentioned should be fine. They affect linking and if you managed to link the resulting binary successfully, it should work fine.

I should also mention that mipsel-unknown-linux-uclibc is currently supported by Rust as a Tier 3 target. It means that it should be possible to build Arrow Client without linking it statically to MUSL. You'll need Rust nightly though and you'll also need to use the "build-std" feature of Cargo: https://doc.rust-lang.org/cargo/reference/unstable.html#build-std

It should be relatively simple. You'll need to create a .cargo/config like this:

# uncomment these if some crates fail to compile because of missing std
# [build]
# rustflags = ["--cfg=has_std"]

[unstable]
build-std = ["core", "std", "alloc", "proc_macro", "panic_abort", "panic_unwind"]
build-std-features = []
# if there are problems with missing symbols for the backtrace-rs, you can try these two instead:
# build-std = ["core", "std", "alloc", "proc_macro", "panic_abort"]
# build-std-features = ["panic_immediate_abort"]

[target.mipsel-unknown-linux-uclibc]
# adjust these two according to your cross toolchain
ar = "mipsel-openwrt-linux-uclibc-ar"
linker = "mipsel-openwrt-linux-uclibc-gcc"

You'll also need to add path to your cross toolchain bin to the PATH env. variable. And you'll also need to set CC_mipsel_unknown_linux_uclibc to the name of your cross GCC bin.

Once you've set up all this you can just build Arrow Client using:

cargo +nightly build --target=mipsel-unknown-linux-uclibc --release --verbose
jassycliq commented 3 years ago

Appreciate the help!

Unfortunately, this seems to be beyond my current understanding. I was able to get to the point of compiling std but it fails. I've tried everything I could find online but am stuck.

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_SPACEin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:124:38 | 124 | let additional_space = libc::CMSG_SPACE(source_len) as usize; | ^^^^^^^^^^ not found inlibc`

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_FIRSTHDRin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:157:30 | 157 | let mut cmsg = libc::CMSG_FIRSTHDR(&msg); | ^^^^^^^^^^^^^ not found inlibc`

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_NXTHDRin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:161:26 | 161 | cmsg = libc::CMSG_NXTHDR(&msg, cmsg); | ^^^^^^^^^^^ not found inlibc`

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_DATAin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:194:26 | 194 | let data = libc::CMSG_DATA(previous_cmsg).cast(); | ^^^^^^^^^ not found inlibc`

error[E0425]: cannot find value 'cmsg_len_zero' in this scope --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:376:47 | 376 | let data_len = (*cmsg).cmsg_len - cmsg_len_zero; | ^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_DATAin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:377:30 | 377 | let data = libc::CMSG_DATA(cmsg).cast(); | ^^^^^^^^^ not found inlibc`

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_NXTHDRin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:428:23 | 428 | libc::CMSG_NXTHDR(&msg, current) | ^^^^^^^^^^^ not found inlibc`

error[E0425]: cannot find function, tuple struct or tuple variantCMSG_FIRSTHDRin cratelibc --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:430:23 | 430 | libc::CMSG_FIRSTHDR(&msg) | ^^^^^^^^^^^^^ not found inlibc`

`error: aborting due to 8 previous errors

For more information about this error, tryrustc --explain E0425. error: could not compilestd`

Caused by: process didn't exit successfully: rustc --crate-name std --edition=2018 /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type rlib --emit=dep-info,metadata,link -C opt-level=s -C panic=abort -C codegen-units=1 -C metadata=a24811040ed2792f -C extra-filename=-a24811040ed2792f --out-dir /home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps --target mipsel-unknown-linux-uclibc -C linker=mipsel-ingenic-linux-uclibc-gcc -Z force-unstable-if-unmarked -L dependency=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps -L dependency=/home/arrow-client-dyn/target/release/deps --extern alloc=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/liballoc-31041c2a1db3d074.rmeta --extern cfg_if=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libcfg_if-250741371baca692.rmeta --extern compiler_builtins=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libcompiler_builtins-f15537d2940e0daa.rmeta --extern core=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libcore-18bb8b0a011257d4.rmeta --extern hashbrown=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libhashbrown-5acae8bea38a3fec.rmeta --extern libc=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/liblibc-8ce6f1d5b46e2a33.rmeta --extern panic_abort=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libpanic_abort-1fbc8adc07cf40b7.rmeta --extern rustc_demangle=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/librustc_demangle-075394b42af065c8.rmeta --extern unwind=/home/arrow-client-dyn/target/mipsel-unknown-linux-uclibc/release/deps/libunwind-0f08a6cfd615e4bc.rmeta --cap-lints allow --cfg backtrace_in_libstd (exit code: 1) `

Hopefully it's something that is easily fixed but if not, I at least got the statically linked build working. Once again, thank you for the project and help!

operutka commented 3 years ago

Unfortunately, this cannot be solved easily. Tier 3 targets are not guaranteed to build and sometimes there are problems. ~This seems to be a bug in the libc crate which is a dependency of std. Feel free to report it here: https://github.com/rust-lang/libc~

Sorry, my bad. The problem is directly in std. The report should go here: https://github.com/rust-lang/rust