-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix for bootstrapping on NixOS #39578
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
Conversation
NixOS puts Linux's dynamic loader in wierd place. Detect when we're on NixOS and patch the downloaded bootstrap executables appropriately.
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
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.
LGTM from a Python programmer's perspective, although I can't test this. Take care of the portability and this should be good to merge!
|
||
default_encoding = sys.getdefaultencoding() | ||
try: | ||
ostype = subprocess.check_output(['uname', '-s']).strip().decode(default_encoding) |
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.
Use platform.system()
instead (with appropriate import added to the top). uname
is not present on Windows and this gets executed before we know the OS type.
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 was aware of platform.system()
but I copied what was done here because I figured there must be a reason for it. This shouldn't break on windows because the fix_executable
function just returns without doing anything if something goes wrong.
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.
Well, yeah. Didn't see that WindowsError
right below. Although IMO the uname
calls are only there for consistency with the configure
logic.
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.
Could this deduplicate between here and the other location?
src/bootstrap/bootstrap.py
Outdated
@@ -89,7 +89,6 @@ def verify(path, sha_path, verbose): | |||
" expected: {}".format(found, expected)) | |||
return verified | |||
|
|||
|
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.
Style cleanup is best done in a separate commit.
src/bootstrap/bootstrap.py
Outdated
return | ||
|
||
# At this point we're pretty sure the user is running NixOS | ||
print("Info: you seem to be running NixOS. Attempting to patch " + fname) |
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.
FWIW we're using all-lowercase messages in rustbuild, and this Info
should be lower-cased too.
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.
(agreed)
src/bootstrap/bootstrap.py
Outdated
interpreter = subprocess.check_output(["patchelf", "--print-interpreter", fname]) | ||
interpreter = interpreter.strip().decode(default_encoding) | ||
except subprocess.CalledProcessError as e: | ||
print("Warning: failed to call patchelf: %s" % e) |
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.
So should this Warning
and some others below.
r? @brson |
@canndrew could you describe why this is necessary, and why we should do it as part of the build system? This seems like a lot of brittle logic easily broken for something that I'd naively consider to be a local problem, but I'm sure I'm not aware of all the details! |
I think this is a reasonable workaround, but it's a little weird - if you happen to be running on nix, it changes what it does to the outputs. In other words, one still can't build for NixOS generally, but if you happen to be building on Nix you get a Nix-compatible binary. |
@alexcrichton @brson |
Thanks for the explanation @canndrew! |
It might be a good idea to see what other NixOS users think of this. Maybe @Ericson2314 has an opinion? I'm not sure who else uses NixOS. |
Granted, I'm a little out of date on this stuff as I mainly just patch the pre-compiled binaries, and then that stopped working great because the Cargo ones moved. But I thought at least the official nixpkgs rustc package downloads the bootstrap binaries on rustbuild's behalf? In any event, I think this stuff can go away once the cargo integration with out build systems + distributed cache stuff is figured out, and stdlib-aware Cargo is implemented. Then we can build rustc like any other binary very nicely. So hopefully this would be a temporary thing for less than the year 🤞. |
src/bootstrap/bootstrap.py
Outdated
if ostype != "Linux": | ||
return | ||
|
||
if not os.path.exists("/nix/store"): |
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.
Any NixOS system has /etc/NIXOS
(nixos-rebuild
/ the activation scripts check for its existence and refuse to run without it), so that's probably a better test.
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.
Good point. Thanks.
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.
@edef1c's recommendation was for /etc/NIXOS
, and I believe one could have a NixOS installation without /etc/nixos
.
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.
Oh, I was wondering why he wrote it in uppercase. I didn't realize that file existed.
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.
for the record, s/he/they/
Instead of patching the rustc binary itself, change bootstrap logic to invoke rustc with |
@nagisa If this is implemented we'd want to change rustup as well, as one can |
@nagisa What's the advantage of doing it like that? From my point of view, the precompiled rustc binaries are just broken for NixOS - they point to a file that doesn't exist. So why not just fix the problem directly? |
This is also the standard way to fix binaries on NixOS. |
@bors: r+ |
📌 Commit 5e324bd has been approved by |
Fix for bootstrapping on NixOS NixOS puts Linux's dynamic loader in wierd place. Detect when we're on NixOS and patch the downloaded bootstrap executables appropriately.
☀️ Test successful - status-appveyor, status-travis |
NixOS puts Linux's dynamic loader in wierd place. Detect when we're on NixOS and patch the downloaded bootstrap executables appropriately.