android: Set SDK/API level via version-suffxed --target
triple
#209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We haven't set the SDK/API level via the
__ANDROID_API__
define for a very long time and so far got away with it. However, while debugging whybacktrace
(and by extension Ruststd
which reuses that crate) wasn't generating symbolicated stacktraces inpanic_log
, and whyfindshlibs
wasn't providing the list of loaded libraries tosentry
, we found that both rely on expanding the__ANDROID_API__
define via compiling a small C file viacc
to make the code conditional on SDK/API >= 21:gimli-rs/findshlibs#65
rust-lang/backtrace-rs#415
(It would have been lovely if these crates emitted a
cargo:warning
when the define wasn't set at all, indicating an "incomplete" cross-compiler setup, and/or looked at the runtime Android API version via something like rust-mobile/ndk#479.)Note that
backtrace 0.3.74
/ Rust 1.82 (rust-lang/rust@0763a3a) no longer rely on this because Rust 1.82 bumped the minimum SDK/API level to 21: rust-lang/backtrace-rs#656We could set this define directly, or rely on
clang
to set it for us by appending the SDK/API level to the target triple, of the form<arch>-linux-android<sdk level>
. The latter is more common. Keep in mind that thecc
crate adds an unversioned--target=<arch>-linux-android
to the command line arguments as well, but clang seems to deduplicate them (or look at the latter--target
which contains our version).Note that this effectively reverts 32efed6 because we must now always pass the SDK level via the triple again, even if the host also happens to be Android with the same architecture.