-
Notifications
You must be signed in to change notification settings - Fork 109
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
ndk: Add definitions and bindings for API levels #479
base: master
Are you sure you want to change the base?
Conversation
CC @daxpedda |
I think this is a Rust 1.80 clippy false-positive. The types may not be constructed by us, but they are However, no API currently takes these symbols, so we might as well skip & hide them until they become useful? ( |
Re-running CI jobs because some changes to |
`android/api-levels.h` from the NDK defines constants for all (NDK-supported) API levels and both a getter for the "current apps' target API level" as well as the API level of the device the app is running on. Create bindings to allow users to query this information at runtime from their Rust code as well. The equivalent of the NDK's `__ANDROID_API__` define are our `api-level-xx` crate features, used to restrict APIs (and inexistant linker symbols) at build-time. (As there is no full-fledged Android build system involved, users of the `ndk` crate are expected to keep this in sync with the minimum/target API level passed to their build tool of choice.)
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 why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` 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#656 We 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 the `cc` 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.
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 why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` 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#656 We 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 the `cc` 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 rust-mobile@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.
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 why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` 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#656 We 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 the `cc` 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 rust-mobile@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.
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 why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` 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#656 We 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 the `cc` 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.
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 why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` 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#656 We 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 the `cc` 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 rust-mobile@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.
android/api-levels.h
from the NDK defines constants for all (NDK-supported) API levels and both a getter for the "current apps' target API level" as well as the API level of the device the app is running on. Create bindings to allow users to query this information at runtime from their Rust code as well.The equivalent of the NDK's
__ANDROID_API__
define are ourapi-level-xx
crate features, used to restrict APIs (and inexistant linker symbols) at build-time.(As there is no full-fledged Android build system involved, users of the
ndk
crate are expected to keep this in sync with the minimum/target API level passed to their build tool of choice.)