Skip to content

fs::hard_link: use linkat on Android#159346

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:android-linkat
Jul 23, 2026
Merged

fs::hard_link: use linkat on Android#159346
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:android-linkat

Conversation

@RalfJung

@RalfJung RalfJung commented Jul 15, 2026

Copy link
Copy Markdown
Member

According to 6249cda, linkat needs API level 21. That is ancient (2014, Android 5). Our target page does not say which minimum Android version or API level we support, it just says:

Rust will support the most recent Long Term Support (LTS) Android Native Development Kit (NDK). By default Rust will support all API levels supported by the NDK, but a higher minimum API level may be required if deemed necessary.

That's pretty useless as I have no idea how I'd figure out what the "API levels support by the NDK" are.
Cc @chriswailes @jfgoog @maurer @pirama-arumuga-nainar

Fixes rust-lang/miri#5080

@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 15, 2026
@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 6 candidates

@RalfJung

Copy link
Copy Markdown
Member Author

I found https://github.com/android/ndk/wiki/Compatibility which does not mention API level 21. Does that mean we still support Android 5...?

@Joel-Wwalker

Copy link
Copy Markdown
Contributor

The Compatibility page is a "last NDK that supported it" table, so API 21 not appearing there means no NDK has dropped it yet. The place the current floor got set is the r26 changelog: "KitKat (APIs 19 and 20) is no longer supported. The minimum OS supported by the NDK is Lollipop (API level 21)." So the minimum for r26 and everything after is exactly 21, meaning Android 5 is still supported and is the oldest thing that is.

For what Rust actually builds with: the dist images use NDK r26d (src/ci/docker/host-x86_64/dist-android/Dockerfile), which can't target anything below 21 anyway. So assuming linkat here should be safe under the current policy.

@RalfJung

RalfJung commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

API level 20 also doesn't appear on that page so apparently has not been dropped yet? But that contradicts what you quote from the r26 changelog.

How do I find out what the "most recent Long Term Support (LTS) Android Native Development Kit (NDK)" is?

@Joel-Wwalker

Copy link
Copy Markdown
Contributor

API 20 is Android 4.4W, the wearables-only KitKat release (API level table). It never existed as an NDK platform level: meta/platforms.json in both the r26 and r27 release branches has "min": 21 and maps "20": 19 in its alias table. The build system docs spell out the rule: "Not every API level includes new NDK APIs. ... applications with a minSdkVersion of 20 should use API 19 for their NDK target." (API 25 is aliased the same way.) So the Compatibility page has no row for 20 because there was never an NDK level 20 to drop; the r26 changelog's "KitKat (APIs 19 and 20)" is just naming the whole KitKat generation.

For the LTS: the NDK wiki front page lists current releases and support windows. Right now r29 is the newest release and r27d is the LTS ("2024 LTS", "supported until r30 is released"; r30 is in beta). The API 21 floor has been in place since r26, which covers both the r26d that Rust CI builds with and the current LTS.

@RalfJung

RalfJung commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Okay, thanks a lot!

IIUC that means we're good depending on linkat, as the latest LTS release only supports API levels that include linkat.

@maurer

maurer commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Sorry for the slow response, I'm on leave at the moment. @Joel-Wwalker is correct though, API 21 is currently last supported and does support linkat.

Re: compatibility, if you want a less glitzy description of when native APIs were introduced, you can look here
The introduced comment, if present, indicates the version it was added in. If there's no comment, it means it's been there since 21 or earlier, and you can pretend it's always been there. If you see arches listed, it means that support is only available on those arches.

@RalfJung

Copy link
Copy Markdown
Member Author

@the8472 maybe I could get a review from you?

@the8472 the8472 assigned the8472 and unassigned JohnTitor Jul 22, 2026

@the8472 the8472 Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are those miri tests executed anywhere on an android system/emulator?
All the hard_link tests in the std testsuite are guarded with this:

#[cfg_attr(target_os = "android", ignore = "Android SELinux rules prevent creating hardlinks")]

This was introduced in #102757
So we have nominal hardlink support on android but it's not available to regular apps. OS components might be able to use it, but we're not testing that at the moment.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, those tests are only run on Linux natively, and inside Miri on various targets.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So Miri is simulating the android target and the restrictions don't apply, ok.

@the8472

the8472 commented Jul 22, 2026

Copy link
Copy Markdown
Member

It's unfortunate that we don't have test coverage, but on the other hand android is tier2 and from the "android is just a weird linux" angle this PR looks fine. I opened #159739 about reenabling those tests.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 038a55a has been approved by the8472

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 22, 2026
fs::hard_link: use linkat on Android

According to rust-lang@6249cda, `linkat` needs API level 21. That is ancient (2014, Android 5). Our [target page](https://doc.rust-lang.org/rustc/platform-support/android.html) does not say which minimum Android version or API level we support, it just says:

> Rust will support the most recent Long Term Support (LTS) Android Native Development Kit (NDK). By default Rust will support all API levels supported by the NDK, but a higher minimum API level may be required if deemed necessary.

That's pretty useless as I have no idea how I'd figure out what the "API levels support by the NDK" are.
Cc @chriswailes @jfgoog @maurer @pirama-arumuga-nainar

Fixes rust-lang/miri#5080
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 22, 2026
fs::hard_link: use linkat on Android

According to rust-lang@6249cda, `linkat` needs API level 21. That is ancient (2014, Android 5). Our [target page](https://doc.rust-lang.org/rustc/platform-support/android.html) does not say which minimum Android version or API level we support, it just says:

> Rust will support the most recent Long Term Support (LTS) Android Native Development Kit (NDK). By default Rust will support all API levels supported by the NDK, but a higher minimum API level may be required if deemed necessary.

That's pretty useless as I have no idea how I'd figure out what the "API levels support by the NDK" are.
Cc @chriswailes @jfgoog @maurer @pirama-arumuga-nainar

Fixes rust-lang/miri#5080
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 22, 2026
fs::hard_link: use linkat on Android

According to rust-lang@6249cda, `linkat` needs API level 21. That is ancient (2014, Android 5). Our [target page](https://doc.rust-lang.org/rustc/platform-support/android.html) does not say which minimum Android version or API level we support, it just says:

> Rust will support the most recent Long Term Support (LTS) Android Native Development Kit (NDK). By default Rust will support all API levels supported by the NDK, but a higher minimum API level may be required if deemed necessary.

That's pretty useless as I have no idea how I'd figure out what the "API levels support by the NDK" are.
Cc @chriswailes @jfgoog @maurer @pirama-arumuga-nainar

Fixes rust-lang/miri#5080
rust-bors Bot pushed a commit that referenced this pull request Jul 23, 2026
Rollup of 8 pull requests

Successful merges:

 - #159504 (Abort const-eval queries early when there are generics in the type)
 - #159523 (std: fix Xous UDP recv length over-report and OOB panic)
 - #159605 (Add fallback for `intrinsics::fabs`)
 - #159699 (bump std libc to 0.2.189)
 - #159306 (Add new variant to iterating-updating-mutref borrowck test)
 - #159346 (fs::hard_link: use linkat on Android)
 - #159513 (Consider `()` as suspicious only when expecting `!` for runtime symbols)
 - #159734 (Document the link_section attribute)
@rust-bors
rust-bors Bot merged commit 24345c1 into rust-lang:main Jul 23, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 23, 2026
rust-timer added a commit that referenced this pull request Jul 23, 2026
Rollup merge of #159346 - RalfJung:android-linkat, r=the8472

fs::hard_link: use linkat on Android

According to 6249cda, `linkat` needs API level 21. That is ancient (2014, Android 5). Our [target page](https://doc.rust-lang.org/rustc/platform-support/android.html) does not say which minimum Android version or API level we support, it just says:

> Rust will support the most recent Long Term Support (LTS) Android Native Development Kit (NDK). By default Rust will support all API levels supported by the NDK, but a higher minimum API level may be required if deemed necessary.

That's pretty useless as I have no idea how I'd figure out what the "API levels support by the NDK" are.
Cc @chriswailes @jfgoog @maurer @pirama-arumuga-nainar

Fixes rust-lang/miri#5080
moabo3li pushed a commit to moabo3li/miri that referenced this pull request Jul 23, 2026
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#159504 (Abort const-eval queries early when there are generics in the type)
 - rust-lang/rust#159523 (std: fix Xous UDP recv length over-report and OOB panic)
 - rust-lang/rust#159605 (Add fallback for `intrinsics::fabs`)
 - rust-lang/rust#159699 (bump std libc to 0.2.189)
 - rust-lang/rust#159306 (Add new variant to iterating-updating-mutref borrowck test)
 - rust-lang/rust#159346 (fs::hard_link: use linkat on Android)
 - rust-lang/rust#159513 (Consider `()` as suspicious only when expecting `!` for runtime symbols)
 - rust-lang/rust#159734 (Document the link_section attribute)
@RalfJung
RalfJung deleted the android-linkat branch July 24, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some fs functionality is not supported on Android

6 participants