-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @jyn514 cc @chriswailes |
This looks good to me. It's much cleaner now. |
Let's hold off on merging this until we address the open questions on #102332. |
☔ The latest upstream changes (presumably #103797) made this pull request unmergeable. Please resolve the merge conflicts. |
Small update: #103673 tracks the upgrade to NDK r25b. |
The NDK update has now been re-mereged and is targeted for release in 1.68. |
I don't have time for reviews for the foreseeable future. |
Ping. |
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). |
cfg.compiler(cxx); | ||
true | ||
} else if build.hosts.contains(&target) || build.build == target { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- When cross-compiling the standard library,
get_base_compiler()
returns a working C++ compiler butdefault_compiler()
returns a broken one. - When cross-compiling the standard library and
get_base_compiler()
returnsNone
for the C++ compiler for the target, causing theget_compiler()
call indefault_compiler()
to fail, aborting thebootstrap
program.
Looking at the individual non-Android cases:
openbsd
: in some cases replacesgcc
withegcc
, as well as replacingg++
witheg++
. This seems right, there appears to be a compiler namedeg++
on some versions of OpenBSD. So I suspect this could actually fix (to some degree) cross-compiling to OpenBSD ifeg++
is available as a cross compiler. OpenBSD has a C++ compiler in the base system, so the call toget_compiler()
seems okay.mips*-unknown-linux-musl
replacesgcc
withmips*-linux-musl-gcc
, which will have no effect in the C++ case. Other musl targets replace the compiler withmusl-gcc
regardless of language. This isn't right for C++ and there doesn't seem to be such a thing asmusl-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++, soget_base_compiler()
could fail. The right fix seems to be to guard all of themusl
clauses with a check thatcompiler == Language::C
. That means we will fall back totry_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.
☔ 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.
Ping. |
@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). |
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). |
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? |
☔ The latest upstream changes (presumably #112418) made this pull request unmergeable. Please resolve the merge conflicts. |
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 |
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 |
Created #116998 |
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.
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.