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

aarch64-linux-android target fails if using rust nightly #1128

Closed
4 of 11 tasks
Nohac opened this issue Nov 11, 2022 · 11 comments
Closed
4 of 11 tasks

aarch64-linux-android target fails if using rust nightly #1128

Nohac opened this issue Nov 11, 2022 · 11 comments
Labels
A-android Area: android targets bug
Milestone

Comments

@Nohac
Copy link

Nohac commented Nov 11, 2022

Checklist

Describe your issue

I'm not sure if this belongs here, since the same thing happens if I try compiling without cross, but I figured I'd start here and work my way down.

If I try to build any rust project using the latest rust nightly, I'm getting the following linking error:

cross build --target aarch64-linux-android
   Compiling androidbuild v0.1.0 (/project)
error: linking with `aarch64-linux-android-gcc` failed: exit status: 1
  |
  = note: "aarch64-linux-android-gcc" "/tmp/rustcZXuIpd/symbols.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.28jvuwflw0ats6rm.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.2u3srmfk0bv538y4.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.3pby2ewnttqmnytk.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.41d8uq9xy8r5uuh1.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.okc32n2krtvmwrv.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.snltws6l1csb9t2.rcgu.o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c.if8dlr15e5s0nn.rcgu.o" "-Wl,--as-needed" "-L" "/target/aarch64-linux-android/debug/deps" "-L" "/target/debug/deps" "-L" "/rust/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/rust/lib/rustlib/aarch64-linux-android/lib/libstd-ca201f8924e1a745.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libpanic_unwind-7a65eafe14f452ef.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libobject-9edec975292b096b.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libmemchr-7101bcf92ac73e01.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libaddr2line-133819781a63c739.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libgimli-47df885212c9ec97.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_demangle-7b8caa98eca7572d.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libstd_detect-9a1b49175d4e38cb.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libhashbrown-0ffd5b9fedd3b1ae.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libminiz_oxide-995414520fa49f31.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libadler-3c86b51ab749f965.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_alloc-28b6d4e7d7c1f355.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libunwind-394e28c2f903c2e9.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcfg_if-3ed771790aba2d34.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/liblibc-f211a911193b255a.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/liballoc-11386607a3accfa5.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_core-001d5bd9a65e4337.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcore-088bc0b43b3ec677.rlib" "/rust/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-78ef6e03d835568c.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/rust/lib/rustlib/aarch64-linux-android/lib" "-o" "/target/aarch64-linux-android/debug/deps/androidbuild-3f3983647d92fd8c" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /android-ndk/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lunwind
          collect2: error: ld returned 1 exit status
          

error: could not compile `androidbuild` due to previous error

This works using rust stable, and it used to work with nightly, maybe one or two month ago.
I've been stuck on this for a while now, so any help would be greatly appreciated.

What target(s) are you cross-compiling for?

aarch64-linux-android

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.4

Example

rustup update
rustup default nightly
mkdir androidbuild && cd androidbuild
cargo init .
cross build --target aarch64-linux-android
@Alexhuszagh Alexhuszagh added bug A-android Area: android targets labels Nov 11, 2022
@Alexhuszagh
Copy link
Contributor

I believe this is likely fixed by migrating to a higher SDK level, and a recent nightly started using more recent API flags, and would likely be fixed by migrating the default to say, Android 10 or 11. This is addressed by #1023, but we'd have to change the default build version since we currently default to Android 9 which is quite old.

@Alexhuszagh Alexhuszagh added this to the v0.3.0 milestone Nov 11, 2022
@Emilgardis
Copy link
Member

the nightly change is rust-lang/rust#103673

@astraw
Copy link

astraw commented Nov 12, 2022

@Nohac this can be fixed in your project by configuring cross to build std. In Cross.toml:

[build]
build-std = true

Unfortunately, this errors on stable, so you need some way to do this only on nightly. Here's how we did that: https://github.com/strawlab/iana-time-zone/pull/87/files

@Nohac
Copy link
Author

Nohac commented Nov 12, 2022

I updated my local ndk to r25b (25.1.8937393) as @Alexhuszagh mentioned, and that solved the linker error!

On change I noticed updating to the new ndk, is that they got rid of a binary called aarch64-linux-android-ar and replaced it with llvm-ar. For some reason https://github.com/a1ien/rusb seems to, somewhere in the chain, specifically look for aarch64-linux-android-ar, and I'm not able to find out how to change it, the only way I got it to build was to symlink llvm-ar to aarch64-linux-android-ar, which is a bit annoying.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Nov 12, 2022

@Nohac That's odd, I thought we solved that actually. Rust also looks for these tools internally, so I believe this should be required. Let me check if our symlink script is failing, although it shouldn't...

# later NDK versions switch to using `llvm-${tool}` rather than `${target}-tool`
# want to ensure we just have backwards-compatible aliases
local tool=
local tool_src=
local tool_dst=
for tool in ar as nm objcopy objdump ranlib readelf size string strip; do
tool_src="/android-ndk/bin/llvm-${tool}"
tool_dst="/android-ndk/bin/${target}-${tool}"
if [[ ! -f "${tool_dst}" ]] && [[ -f "${tool_src}" ]]; then
ln -s "${tool_src}" "${tool_dst}"
elif [[ "${tool}" == "ld" ]] && [[ ! -f "${tool_dst}" ]]; then
ln -s "/android-ndk/bin/${tool}" "${tool_dst}"
fi
done

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Nov 12, 2022

@Nohac Can you provide the exact configuration you used? Here's a sample build of mine using a newer NDK which has:

$ file $(which llvm-ar)
/android-ndk/bin/llvm-ar: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, stripped
$ file $(which aarch64-linux-android-ar)
/android-ndk/bin/aarch64-linux-android-ar: symbolic link to /android-ndk/bin/llvm-ar

This is using NDK version r25b, SDK level 28, and therefore Android version 9.0.0_r1. In short, this symlink should be already provided, but clearly seems to not be (which is an issue).

@Nohac
Copy link
Author

Nohac commented Nov 14, 2022

To clarify, I only did this locally, I wasn't aware that you already deal with this in cross, which is nice to see.
I'm also not sure how to test this with cross, as I don't understand how to change the android ndk version. I looked at #1023, but setting the env variables seems to do nothing.

@Emilgardis
Copy link
Member

the env vars are for when building the image with cargo build-docker-image --target aarch64-linux-android --build-arg <arg>=<value>

@Alexhuszagh
Copy link
Contributor

There's also a section on the wiki for building images with other Android versions.

@Nohac
Copy link
Author

Nohac commented Nov 23, 2022

@Alexhuszagh sorry for the late reply. Following the wiki and choosing a new ndk version seems to have solved the problem, no symlinking necessary, thanks!

I'm not sure if you want to close this issue now, or wait until it's solved in the default docker image?

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Nov 23, 2022

I believe this was fixed by default in #1023 so it should work for the latest main images.

See the lines in the diff:
25c7121#diff-f06084a481085226ba75aa7f2bf1e15c6148a90c79688dee8b6daeb605db5bb2R16

We've changed it to use ARG ANDROID_NDK=r25b as the default, and the previous was r21d, with a hard-coded URL of NDK_URL=https://dl.google.com/android/repository/android-ndk-r21d-linux-x86_64.zip.

This wasn't before you made the comment, and then I changed the PR to increment the Android NDK versions for this exact purpose.

mberry added a commit to Argyle-Software/kyber that referenced this issue Mar 16, 2023
Failing due to not locating libunwind
This is related to: cross-rs/cross#1128
There are workarounds here: rust-lang/rust#85806 (comment)
Someone might want to try implement it later
For now I'm pulling the android compiles
mberry added a commit to Argyle-Software/kyber that referenced this issue Mar 16, 2023
* v0.5.0
Update: changelog
Update: wasm binary and files
Bump: deps
Add: release on version tag github action
Add: release checklist

* Remove: Android CI target
Failing due to not finding libunwind
This is related to: cross-rs/cross#1128
There is a workaround: rust-lang/rust#85806 (comment)
Someone might want to try implement it later
For now I'm pulling out the android compiles from CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-android Area: android targets bug
Projects
None yet
Development

No branches or pull requests

4 participants