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

Android NDK 25 [firefox-android: main] #5442

Merged
merged 3 commits into from
Mar 30, 2023
Merged

Android NDK 25 [firefox-android: main] #5442

merged 3 commits into from
Mar 30, 2023

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Mar 24, 2023

This updates the code to use android NDK 25.

The upgrade caused all kinds of issues, see #5436 for details. This PR contains a hack to work around those issues. It's very ugly, but it works at least. Is there a better way to do this?

Pull Request checklist

  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGES_UNRELEASED.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

@bendk bendk requested review from ncalexan and rvandermeulen March 24, 2023 20:11
@bendk bendk mentioned this pull request Mar 24, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2023

Codecov Report

Patch coverage: 33.33% and project coverage change: -0.04 ⚠️

Comparison is base (86c84c2) 45.11% compared to head (2ded859) 45.08%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5442      +/-   ##
==========================================
- Coverage   45.11%   45.08%   -0.04%     
==========================================
  Files         172      172              
  Lines       14378    14387       +9     
==========================================
- Hits         6487     6486       -1     
- Misses       7891     7901      +10     
Impacted Files Coverage Δ
.../support/rc_crypto/nss/nss_build_common/src/lib.rs 65.09% <33.33%> (-1.91%) ⬇️

... and 4 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rvandermeulen rvandermeulen removed their request for review March 24, 2023 20:31
@rvandermeulen
Copy link
Contributor

I guess @glandium can't formally review this, but ultimately I think he's the one who should sign off on whatever lands here.

Copy link
Member

@ncalexan ncalexan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing here that worries me beyond the obvious grossness of the workaround.

The only suggestion I have is that if it's a) helpful and b) going to be a persistent situation, we could teach the rust-android-gradle plugin to do this symbol dance (or to remove -nodefaultlibs or whatever the flag was) and generalize this slightly.

I'm going to mark this r+ and trust @bendk and @glandium to agree on the details. Ben, land when you're comfortable.

What a tremendous waste of time and effort :(

@bendk bendk force-pushed the ndk25 branch 8 times, most recently from 68edfed to 6a0f8eb Compare March 29, 2023 23:29
rvandermeulen and others added 3 commits March 30, 2023 09:55
The new NDK doesn't link to `libgcc` anymore, which breaks our our NSS
and SQLCipher libraries since they depended on the symbols from
libclang_rt.builtins-x86_64-android` like `__extenddftf2`. See mozilla#5436 for
more details.

The change works around this by manually linking to the
libclang_rt.builtins-x86_64-android library in this case.

Added a doc on how to upgrade the Android NDK which hopefully will help
us in the future.  Extracted some common code from the the
`build-*-android.sh` scripts to make these directions simpler.
@bendk bendk merged commit 2c97beb into mozilla:main Mar 30, 2023
Niels-Be added a commit to Niels-Be/rusqlite that referenced this pull request Nov 4, 2024
Adds a temporary workaround for [an issue] with the Rust compiler and Android when
compiling for x86_64 devices.

The Android NDK used to include `libgcc` for unwind support (which is required by Rust
among others). From NDK r23, `libgcc` is removed, replaced by LLVM's `libunwind`.
However, `libgcc` was ambiently providing other compiler builtins, one of which we
require: `__extenddftf2` for software floating-point emulation. This is used by SQLite
(via the `rusqlite` crate), which defines a `LONGDOUBLE_TYPE` type as `long double`.

Rust uses a `compiler-builtins` crate that does not provide `__extenddftf2` because
[it involves floating-point types that are not supported by Rust][unsupported]. For
some reason, they _do_ export this symbol for `aarch64-linux-android`, but they do not
for `x86_64-linux-android`. Thus we run into a problem when trying to compile and run
the SDK on an x86_64 emulator.

The workaround comes from [this Mozilla PR]: we tell Cargo to statically link the
builtins from the Clang runtime provided inside the NDK, to provide this symbol.

[an issue]: rust-lang/rust#109717
[this Mozilla PR]:mozilla/application-services#5442
[unsupported]: https://github.com/rust-lang/compiler-builtins#unimplemented-functions

This fix was copied from: https://github.com/nerdcash/Nerdbank.Cryptocurrencies/pull/262/files#diff-7cc5f1ef7cbfce3114fe631861f19de2c050c13ff71e987100669131bb9ffa25

Fixes rusqlite#1380
Niels-Be added a commit to Niels-Be/rusqlite that referenced this pull request Nov 26, 2024
Adds a temporary workaround for [an issue] with the Rust compiler and Android when
compiling for x86_64 devices.

The Android NDK used to include `libgcc` for unwind support (which is required by Rust
among others). From NDK r23, `libgcc` is removed, replaced by LLVM's `libunwind`.
However, `libgcc` was ambiently providing other compiler builtins, one of which we
require: `__extenddftf2` for software floating-point emulation. This is used by SQLite
(via the `rusqlite` crate), which defines a `LONGDOUBLE_TYPE` type as `long double`.

Rust uses a `compiler-builtins` crate that does not provide `__extenddftf2` because
[it involves floating-point types that are not supported by Rust][unsupported]. For
some reason, they _do_ export this symbol for `aarch64-linux-android`, but they do not
for `x86_64-linux-android`. Thus we run into a problem when trying to compile and run
the SDK on an x86_64 emulator.

The workaround comes from [this Mozilla PR]: we tell Cargo to statically link the
builtins from the Clang runtime provided inside the NDK, to provide this symbol.

[an issue]: rust-lang/rust#109717
[this Mozilla PR]:mozilla/application-services#5442
[unsupported]: https://github.com/rust-lang/compiler-builtins#unimplemented-functions

This fix was copied from: Electric-Coin-Company/zcash-android-wallet-sdk@1bf2f84

Fixes rusqlite#1380

Co-authored-by: Jack Grigg <jack@electriccoin.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants