Skip to content

CI: Detect Android API from the toolchain#5280

Open
10ne1 wants to merge 4 commits into
rust-lang:mainfrom
10ne1:android-detect-API-from-toolchain
Open

CI: Detect Android API from the toolchain#5280
10ne1 wants to merge 4 commits into
rust-lang:mainfrom
10ne1:android-detect-API-from-toolchain

Conversation

@10ne1

@10ne1 10ne1 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

This is a follow-up to PR #5269 to address @tgross35 request to detect the Android API levels from the toolchain instead of hardcoding it in the tests.

The first 2 commits address @tgross35 request, while the last two fix 2 separate pre-existing uncovered issues (details in the commit messages).

A libc-0.2 backport might be desired to get the new Android CI infra there as well, but I'll leave it up to the maintainers / reviewers to decide.

Sources

No library/API changes; this is test-harness and CI-only.

Useful references:

Checklist

CI-only change: no src/ or libc-test/semver modifications.

  • Relevant tests in libc-test/semver have been updated (N/A)
  • No placeholder or unstable values (N/A)
  • Tested: validated in my fork on GitHub-hosted runners. This PR's own CI run exercises it directly.

AI disclosure

This PR was written with the help of Claude Code, but was not vibe-coded. I'm not a fan of vibe-coding.

I used AI to better understand the codebase myself (asked it a lot of questions), review both my code and any code generated by AI, used it especially to detect bugs and corner-cases and suggest fixes, however I very carefully reviewed & edited each code/comment lines, the commit messages and so on, until I was satisfied with the result.

Even this PR description was written entirely by myself and only reviewed by AI for errors.

@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in an Android module

cc @maurer

Comment thread libc-test/build.rs Outdated
Comment thread libc-test/build.rs Outdated
Comment thread libc-test/build.rs Outdated
Comment thread ci/docker/aarch64-linux-android/Dockerfile
Comment thread libc-test/build.rs Outdated
@rustbot

This comment has been minimized.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

10ne1 added 4 commits July 22, 2026 15:31
Add "android" to the Versions platform-version detection. Knowing it
allows version-gating the Android test skips instead of hardcoding them.

The level can appear in two macros:
  1. Old clang defines __ANDROID_API__ directly as an integer.
  2. Modern clang defines it as an alias of __ANDROID_MIN_SDK_VERSION__.

A toolchain whose target triple carries no API level defines neither
number, so nothing is parsed and the level stays undetected.

An undetected level (android == None) causes its consumers to treat it
conservatively: every API-gated skip stays active, as if the toolchain
targeted the oldest level possible.

Nothing consumes the value yet, so it has no effect on what is tested.
Next commits will add users for it.

Suggested-by: Trevor Gross <tg@trevorgross.com>
Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Convert the existing hardcoded "added in API level N" test skips into
gates on the detected API level added in the previous commit.

Items stay skipped when the toolchain builds below their introduction
level (or when no level was detected) and get tested once the toolchain
provably targets a high enough level.

There are no test coverage changes.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Bionic implements the termios API as static inline functions in
<termios.h> until API 28 turns them into real libc.so symbols,
so below that level the C-side function address is the header's
inline, never matching the symbol Rust links against.

Skip the function pointer identity check (the only check ctest
generates for a foreign function) for the termios family below API 28.

This surfaced when pinning the C test compilation to a real API
level (see next commit). At level 24, e.g. on arm, all thirteen
termios pointer comparisons fail.

It is ordered before the pin commit to keep commits bisectable.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Each CC wrapper's name (e.g. x86_64-linux-android28-clang) tells clang
which API to target: clang infers "-target" from the invoked binary
name whenever none is given explicitly.

Ours said 28 everywhere, which only reflects the NDK's link-time stub
level, not the level of the bionic that actually runs the tests. Every
job now targets API 24 (the level the arm and aarch64 emulators run
and the level the retired x86_64 sysimage ran), so the dynamic skips
resolve exactly as the old hardcoded ones did and coverage is unchanged.

Each Dockerfile declares that level once, in an ANDROID_API build arg.
For the arm and aarch64 emulator jobs the arg also selects the system
image android-install-sdk.sh installs, so the wrapper cannot drift from
the image the tests run on.

This mismatch was invisible before because the tests were hardcoded to
skip higher API levels regardless of the toolchain: it surfaced after
extracting the real API level from the toolchain and wiring in the
dynamic skip mechanism (previous commits) instead of hardcoding.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
@10ne1
10ne1 force-pushed the android-detect-API-from-toolchain branch from cc83081 to 4d48e10 Compare July 22, 2026 15:01
@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@10ne1

10ne1 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants