-
Notifications
You must be signed in to change notification settings - Fork 891
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
Warn when running under Rosetta emulation #3068
Conversation
7731ebd
to
48387a9
Compare
I still see people caught by this gotcha. Can someobody review the PR? @hi-rustin? |
Thanks for your patch! |
cargo build --target=x86_64-apple-darwin
mv ./target/x86_64-apple-darwin/debug/rustup-init ./rustup
./rustup show |
I've added the warning to Currently unit tests seem to fail on an unrelated issue:
|
Tested on my computer. It works! |
It may be that our shell checker is updated, I'll fix it later. |
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.
Looks good to me!
But I am not sure does it is OK to print this warning in all these commands and checks.
@rbtcollins Could you please take a look? Thanks!
Users are still hitting this gotcha. It'd be nice if you could expedite releasing this warning. |
Hi. I don't have Apple silicon available to test this. Can you please describe the situations where this will output the warning, and maybe some screen shots or something to reason about the UX here? I appreciate that the intended situation is existing home-dirs moved to a new machine. But do we handle the new-install case correctly yet? e.g. calling Unless I misunderstand, it is also the case that rustc / cargo etc will have errors, and non-rustup toolchains will fail too. Do you happen to know what approach is being taken in that part of the ecosystem? That said, this situation is the same as running under qemu on a Linux machine, or a 32-bit rustup on a 64-bit OS that has compat libraries present, including either Windows or Linux. And we don't warn in that situation, even though we could detect it. I think the only warning situation today is installing a toolchain that doesn't match the detected architecture, though thats based on that of rustup itself. |
This problem could in theory happen to other toolkits (e.g.). I've based my detection code on existing implementation in LLVM/clang. However, in practice the footgun is unique to The footgun happens when user installs Rust on an Intel Mac, and then uses Apple Migration Assistant or Time Machine to move their files to an Apple Silicon Mac. This is a pretty common upgrade path now. macOS on Apple Silicon has Rosetta which runs x86-64 executables almost transparently, and reasonably quickly, so Intel-only Rust on ARM appears to work fine on the first glance, despite thinking it's running on x86_64 platform when it's not. Due to emulation, Rust thinks it's running on x86-64, assumes the host OS is x86-64, produces x86-64 code, and gives linking instructions for linking x86-64 libraries. This error happens to be forgiven in simple cases, because core macOS libraries are Universal and contain code for both x86-64 and ARM. Thanks to this and the emulation the x86-64 Rust is able to build, link, and run a "Hello World" executable for x86-64 on an ARM Mac. However, this confused installation eventually breaks when Rust is told to use any library that isn't Universal. Because the host is actually Apple Silicon, the host libraries may contain code for ARM only. In that case Rust generates x86-64 object files and gives instruction to link x86-64 object files with aarch64-only libraries, causing ugly and confusing linker errors. Specifically, this happens once user updates their Homebrew installation and Homebrew-managed libraries are upgraded to ARM-only versions. All -sys crates using such libraries will end up thinking the host is x86-64-apple-darwin, but pkg-config will find aarch64-apple-darwin libraries. This change does not affect new installations of Rust/ Note that this is essentially a broken installation. It's not a long-term issue, because eventually there will be no more Intel Macs to upgrade from. This is about alerting people that their Rust is a broken junk they have to delete. The goal is to make people aware that their rustup installation is invalid, rather than let them waste time debugging very weird and seemingly paradoxical compilation errors coming from super-long In terms of UX, a warning is probably a bit too gentle. A better solution could be to uninstall rustup immediately and make people install the correct version. |
ping? |
Thank you for the great details. Is it possible to teach 'rustup self update' to install the correct non-emulated binary (even if there isn't a new rustup version to update to)? I think we'd also need to change the default target in the rustup config, since that will be intel rather than aarch64 too. I'm not sure UX wise whether doing it silently is sensible. I worry about IDE integrations. What about this as a proposal:
I'm not suggesting deleting toolchains because that gets into rapidly mounting complexity: cross.rs for instance wants lots of non-native toolchains present, linked toolchains can be wrong too and we don't have their arch etc. Changing the defaults and overrides will cause implicit installation of the rewritten toolchain specifications automatically at next use. |
Personally I would consider rustup's host detection to be buggy in this scenario. I would expect rustup to detect the actual host triple regardless of what emulation it is running under (the same way we detect 64-bit windows, even when rustup itself was compiled for 32-bit). Rustup should function the same whether it's running under emulation or not (the warning may still make sense, but it would simply be warning that rustup itself is emulated). |
Could this be merged first, so at least users get any indication of a problem? I agree this could be solved in some more clever ways. However, I'm worried that development of better solutions will delay this even further. I'm trying to get this bare harmless MVP merged for 6 months! I'm worried that development of a clever update mechanism, change of default triple that could have compatibility consequences, etc. can delay this by even longer. |
I believe this is happening due to compile time injected env variable which is read by |
That's not my call, but yeah it totally makes sense to merge this first. |
Right now we're just finalising a release, and this isn't a release blocker, so not going to merge it on that basis. @kornelski I'm sorry you've had a poor experience contributing here. Rustup had a significant period of under-availability of maintainers, which we only sorted out just recently (and even now its still operating on a shoestring). We're all volunteering in our personal time (as I presume you are), but that means our time is spread out across all of the issues, and because of the period of underavailability we're very much in a catchup situation. Please have patience with us, and we'll zero in on what to do here quite quickly I think. @Diggsey yes thats another approach we could take, and I'd be equally happy with that if it was only at install time. The problem is that the scenario is different to that of Windows - if we just fixed the native platform detection we'd still have users with the default written to disk and having these errors that they may not even see with IDEs in the picture. We could perhaps take the approach of requiring an explicit flag combined with fixing the native detection, but make the rustup binary type irrelevant as you suggest. |
The arm7 build failure is unrelated: Error: API rate limit exceeded for 40.77.45.158. |
@rbtcollins I think I agree with others that adding this is a step forward even if it doesn't address the IDE integration use case well. As a Rust-Analyzer on VS Code user (which I feel like is a pretty common case), I manage toolchain updates "manually" from the CLI, and I imagine there are quite a few users like me in that regard. It doesn't seem like there's any downside to adding this warning, even if it doesn't address the full use case? Would it help unblock this to write up some follow-up issues? |
1 year anniversary of this PR is coming. Please, can someone make an executive decision to either merge it or close it? |
@kornelski Sorry for such a long delay! This PR is on my watch list and I personally would like to merge it by the next release. |
I think it will definitely help. |
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.
These changes look good to me!
@kornelski Would you mind rebasing this PR before we get this merged? Again I feel very sorry for your bad experience so far 🙇
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.
Now that we're tracking follow-up improvements in #3514, I think we should land this.
@kornelski thanks and sorry for the slow feedback cycle!
(For those interested, release planning is happening in #3501.)
I've noticed there's a footgun on macOS: if an existing Intel Rust installation has been migrated to a new ARM Mac, it keeps thinking it's running on an
x86_64-apple-darwin
target, because it's being automatically emulated by Rosetta.This happens to work most of the time, except that it badly breaks builds using
openssl
and a few other C libraries, because on aarch64 Macs they aren't available in x64_64 versions, and users get super confusing linker errors.I've added a check of
sysctl.proc_translated
(LLVM uses it too) and warnings torustup default
,rustup update
, andrustup self update
that the host triple Rustup thinks it's using is an emulated one.