-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Building rust lib with wasm-pack is not reproducible #112535
Comments
I've looked into this issue further and it seems that neither $ ldd /nix/store/az7jkjqz9mp7pcxpax7x7q00364x62qh-wasm-pack-0.9.1/bin/wasm-pack
linux-vdso.so.1 (0x00007fff33fa5000)
libssl.so.47 => /nix/store/m0b1iw8dpqsf6h6x7jbhrjrpgi9idx11-libressl-3.0.2/lib/libssl.so.47 (0x00007f81f78b9000)
libcrypto.so.45 => /nix/store/m0b1iw8dpqsf6h6x7jbhrjrpgi9idx11-libressl-3.0.2/lib/libcrypto.so.45 (0x00007f81f76b7000)
libc.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libc.so.6 (0x00007f81f74f6000)
/nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/ld-linux-x86-64.so.2 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib64/ld-linux-x86-64.so.2 (0x00007f81f8033000)
libgcc_s.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libgcc_s.so.1 (0x00007f81f74dc000)
libpthread.so.0 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libpthread.so.0 (0x00007f81f74bb000)
libm.so.6 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libm.so.6 (0x00007f81f7378000)
libdl.so.2 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/libdl.so.2 (0x00007f81f7371000)
librt.so.1 => /nix/store/gafigwfaimlziam6qhw1m8dz4h952g1n-glibc-2.32-35/lib/librt.so.1 (0x00007f81f7366000) I tried to do the same for cargo and rustc, which are installed as part of the
So there's nothing I can really investigate there, but I have a feeling this is where the problem is. I also found this SE thread about using patchelf which seems to touch on a similar problem. However, I don't know which binary actually uses the wrong libc, so I can |
It also seems like rustc will override the linker for wasm, see #89426. |
Ok, I found a workaround for this, but maybe there's a better solution. From what I understand, Rust builds with nix aren't reproducible at all, unless you're using an overlay that specifically re-packages Rust and Cargo and handles the toolchain management. There's two options here: the mozilla overlay and the oxalica overlay. The latter is specifically geared to be 100% reproducible, while the former actually pulls package hashes on-demand as I understand it, meaning you need a network connection to build. So for my setup, I went with the latter. This is my minimal # Use nixpkgs with oxalica rust-bin overlay
let
rust_overlay = import (builtins.fetchTarball
"https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
nixpkgs = import <nixpkgs> { overlays = [ rust_overlay ]; };
rust_channel = nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
in
# Avoid typing `nixpkgs.` before each package name
with nixpkgs;
# Define the shell
pkgs.mkShell {
nativeBuildInputs = [
rust_channel # Full rust from overlay, includes cargo
nodePackages.npm # For all node packages
wasm-pack # Compiling to WASM and packing with web-stuff
];
} So this is great, but I wonder if maybe something like this overlay should be the default way to install rust tooling. |
I marked this as stale due to inactivity. → More info |
Came here to report basically the same issue. Using strace I was able to figure out that while the rustup package installs a rustc in the nix store, that's just a wrapper that invokes a rustc outside the store - in my case inside ~/.rustup. That toolchain is patched to link against nix libraries, but since it is not itself versioned in the nix store, they're not necessarily the right versions. In my case the version in ~/.rustup was hard-linked against glibc 2.33, which was causing problems from a nix shell that was using glibc 2.35. I was able to work around the issue by setting the |
@iFreilicht maybe it would help to change the name of this issue? I happened to also run into it while trying to do something with wasm-pack, but I agree that it looks like a general issue with the rustup package. |
Demo: Initial setup of what's expected to be a pure shell environment:
We use
In the last In my case, this happens to be one that was installed from an older nix environment; it is hard-linked against a glibc 2.33 in the nix store:
This is surprising and problematic since the glibc in the current
If I override RUSTUP_HOME to force a fresh toolchain install, I get one linked against glibc 2.35 as expected.
The last bit seems to fix the wasm-pack link errors for me, though I'm a bit unclear why; maybe rustc is hard-coded to link target binaries against the same glibc that it itself was linked against? In any case though, the root of the problem seems to be that the |
Describe the bug
Trying to build my rust lib with
wasm-pack
inside a pure nix shell, I get the following error, which seems to be caused by wasm-pack trying to use my systems glibc (which is severly outdated) instead of the one installed inside the nix shell.To Reproduce
Steps to reproduce the behavior:
In more detail:
Expected behavior
I would expect wasm-pack to successfully build the library and not be dependent on the glibc version installed on my OS.
Additional context
This build also fails when I run it outside the machine, with the exact same errors. So
Notify maintainers
@dhl
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.Maintainer information:
The text was updated successfully, but these errors were encountered: