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

Improve android-ndk property interface #102994

Closed
wants to merge 1 commit into from
Closed

Conversation

pcc
Copy link
Contributor

@pcc pcc commented Oct 13, 2022

PR #102332 added support for NDK r25b, and removed support for r15. Since the switch to r25b would have broken existing r15 users anyway, let's take the opportunity to make the interface more user friendly.

Firstly move the android-ndk property to [build] instead of the targets. This is possible now that the NDK has obsoleted the concept of target-specific toolchains.

Also make the property take the NDK root directory instead of the "toolchains/llvm/prebuilt/" subdirectory.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Oct 13, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2022
@pcc
Copy link
Contributor Author

pcc commented Oct 13, 2022

r? @jyn514

cc @chriswailes

@chriswailes
Copy link
Contributor

This looks good to me. It's much cleaner now.

@jyn514
Copy link
Member

jyn514 commented Oct 27, 2022

Let's hold off on merging this until we address the open questions on #102332.

@jyn514 jyn514 added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 27, 2022
@bors
Copy link
Contributor

bors commented Oct 31, 2022

☔ The latest upstream changes (presumably #103797) made this pull request unmergeable. Please resolve the merge conflicts.

@jyn514
Copy link
Member

jyn514 commented Nov 17, 2022

Small update: #103673 tracks the upgrade to NDK r25b.

@chriswailes
Copy link
Contributor

The NDK update has now been re-mereged and is targeted for release in 1.68.

@rustbot rustbot added the A-testsuite Area: The testsuite used to check the correctness of rustc label Jan 24, 2023
@jyn514
Copy link
Member

jyn514 commented Jan 24, 2023

I don't have time for reviews for the foreseeable future.

r? @Mark-Simulacrum

@rustbot rustbot assigned Mark-Simulacrum and unassigned jyn514 Jan 24, 2023
@pcc
Copy link
Contributor Author

pcc commented Feb 15, 2023

Ping.

@jyn514
Copy link
Member

jyn514 commented Feb 19, 2023

@pcc this is marked as blocked on #103673 which is why you haven't gotten a review yet. Has something changed there?

@pcc
Copy link
Contributor Author

pcc commented Mar 2, 2023

This is no longer blocked on #103673; I just updated that bug to state that we've already moved to r25b and accepted the breakage. So I think we can remove the blocking label (I don't think I have permission to do it myself).

@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Mar 2, 2023
cfg.compiler(cxx);
true
} else if build.hosts.contains(&target) || build.build == target {
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum Mar 4, 2023

Choose a reason for hiding this comment

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

I'm trying to confirm whether the removal of this if condition (to default_compiler above) is intentional - it seems like it would change behavior for at least some targets? Can you comment on your rationale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's needed to keep the tests passing on Android, because it turns out that $CXX needs to be set correctly for the issue-36710 test to pass. If I bring back something like the original logic like so:

diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs
index 7b84e990ae5..714ec6284c1 100644
--- a/src/bootstrap/cc_detect.rs
+++ b/src/bootstrap/cc_detect.rs
@@ -125,8 +125,12 @@ pub fn find(build: &mut Build) {
             .and_then(|c| c.cxx.clone())
             .or_else(|| default_compiler(&mut cfg, Language::CPlusPlus, target, build))
         {
-            cfg.compiler(cxx);
-            true
+            if build.hosts.contains(&target) || build.build == target {
+                cfg.compiler(cxx);
+                true
+            } else {
+                cfg.try_get_compiler().is_ok()
+            }
         } else {
             // Use an auto-detected compiler (or one configured via `CXX_target_triple` env vars).
             cfg.try_get_compiler().is_ok()

And run the tests like so (with #102757 patched in to make the std tests pass):

python3 x.py test --target aarch64-linux-android --exclude src/tools/linkchecker --exclude tests/debuginfo --force-rerun

I see a failure later:

--- stdout -------------------------------
aarch64-linux-android-clang++ -DANDROID -ffunction-sections -fdata-sections -fPIC -c -o /mnt/disk2/pcc/rust3/build/x86_64-unknown-linux-gnu/test/run-make/issue-36710/issue-36710/libfoo.o foo.cpp
------------------------------------------
--- stderr -------------------------------
/bin/dash: 1: aarch64-linux-android-clang++: not found
make: *** [Makefile:17: /mnt/disk2/pcc/rust3/build/x86_64-unknown-linux-gnu/test/run-make/issue-36710/issue-36710/libfoo.o] Error 127
------------------------------------------

This change makes the compiler detection for C++ consistent with C, which also first tries the logic in default_compiler() to find the compiler in all cases and then tries cc::Build::get_base_compiler() via try_get_compiler() if that fails. Previously for C++ the default_compiler() (previously set_compiler()) call would be omitted for targets that are cross-compiling the standard library, leading to the test failure on Android.

I think the circumstances where this change would break a build are:

  1. When cross-compiling the standard library, get_base_compiler() returns a working C++ compiler but default_compiler() returns a broken one.
  2. When cross-compiling the standard library and get_base_compiler() returns None for the C++ compiler for the target, causing the get_compiler() call in default_compiler() to fail, aborting the bootstrap program.

Looking at the individual non-Android cases:

  • openbsd: in some cases replaces gcc with egcc, as well as replacing g++ with eg++. This seems right, there appears to be a compiler named eg++ on some versions of OpenBSD. So I suspect this could actually fix (to some degree) cross-compiling to OpenBSD if eg++ is available as a cross compiler. OpenBSD has a C++ compiler in the base system, so the call to get_compiler() seems okay.
  • mips*-unknown-linux-musl replaces gcc with mips*-linux-musl-gcc, which will have no effect in the C++ case. Other musl targets replace the compiler with musl-gcc regardless of language. This isn't right for C++ and there doesn't seem to be such a thing as musl-g++ in a normal musl installation (at least the musl sources don't mention it) and it seems plausible that a musl installation would support C but not C++, so get_base_compiler() could fail. The right fix seems to be to guard all of the musl clauses with a check that compiler == Language::C. That means we will fall back to try_get_compiler() for C++ musl targets, as we were doing before.

I've made the proposed fix for musl targets in the latest update of the PR.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2023
@bors
Copy link
Contributor

bors commented Mar 12, 2023

☔ The latest upstream changes (presumably #109056) made this pull request unmergeable. Please resolve the merge conflicts.

PR rust-lang#105716 added support for NDK r25b, and removed support for r15. Since
the switch to r25b would have broken existing r15 users anyway, let's
take the opportunity to make the interface more user friendly.

Firstly move the android-ndk property to [build] instead of the
targets. This is possible now that the NDK has obsoleted the concept of
target-specific toolchains.

Also make the property take the NDK root directory instead of the
"toolchains/llvm/prebuilt/<host tag>" subdirectory.
@pcc
Copy link
Contributor Author

pcc commented Apr 22, 2023

Ping.

@Mark-Simulacrum
Copy link
Member

@rustbot ready (this is something you can do as well, otherwise it's in waiting-on-author and I don't see it in my queue).

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 22, 2023
@Mark-Simulacrum
Copy link
Member

r=me with a note added to the bootstrap changelog about this change, also marking as relnotes so we can include in compat notes there. (This helps give people an explanation for the change rather than an opaque error about unknown fields in config.toml).

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. relnotes Marks issues that should be documented in the release notes of the next release. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2023
@slanterns
Copy link
Contributor

Does it mean we should add a note to https://github.com/rust-lang/rust/blob/master/src/bootstrap/CHANGELOG.md first, then it can be merged?

@bors
Copy link
Contributor

bors commented Jun 14, 2023

☔ The latest upstream changes (presumably #112418) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

@pcc

ping from triage - can you post your status on this PR? There hasn't been an update in a few months. Thanks!

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks

@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 7, 2023
@Dylan-DPC Dylan-DPC closed this Oct 8, 2023
@pcc
Copy link
Contributor Author

pcc commented Oct 20, 2023

Created #116998

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2023
Improve android-ndk property interface

Re-creating rust-lang#102994 which was closed.

---
PR rust-lang#105716 added support for NDK r25b, and removed support for r15. Since the switch to r25b would have broken existing r15 users anyway, let's take the opportunity to make the interface more user friendly.

Firstly move the android-ndk property to [build] instead of the targets. This is possible now that the NDK has obsoleted the concept of target-specific toolchains.

Also make the property take the NDK root directory instead of the "toolchains/llvm/prebuilt/<host tag>" subdirectory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc relnotes Marks issues that should be documented in the release notes of the next release. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants