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

Compiling inside a nix-shell does not work #970

Closed
iFreilicht opened this issue Feb 9, 2021 · 4 comments
Closed

Compiling inside a nix-shell does not work #970

iFreilicht opened this issue Feb 9, 2021 · 4 comments

Comments

@iFreilicht
Copy link

iFreilicht commented Feb 9, 2021

🐛 Bug description

When trying to compile my rust library using wasm-pack inside a nix shell, I get errors about glibc missing, despite it being installed via nix. I do not get those errors when compiling other libraries to my native target.

$ nix-shell --pure
$ cd iris-hub
$ ldd --version
ldd (GNU libc) 2.32
[...]
$ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/[USERNAME]/repos/iris-rs/iris-hub/Cargo.toml
workspace: /home/[USERNAME]/repos/iris-rs/Cargo.toml
   Compiling proc-macro-error v1.0.4
   Compiling serde v1.0.121
   Compiling wasm-bindgen v0.2.69
   Compiling palette v0.5.0
error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/[USERNAME]/repos/iris-rs/target/release/deps/libwasm_bindgen_macro-3a22ad8fd558cc68.so)
  --> /home/felix/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-0.2.69/src/lib.rs:53:13
   |
53 |     pub use wasm_bindgen_macro::__wasm_bindgen_class_marker;
   |             ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

[more errors like this, all with the same error message]

error: aborting due to previous error

error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

🤔 Expected Behavior

I get those same errors when trying to compile with the natively installed cargo, where my glibc is severely outdated, but I would expect the compilation to work inside the isolated environment of nix.

So this may be an issue with Ubuntu 18.04LTS, where ldd is ldd (Ubuntu GLIBC 2.27-3ubuntu1.3) 2.27 from 2018.
This may also be an issue with the nix-package itself, I created an issue for that as well.

👟 Steps to reproduce

Optional: Install nix as single-user install. This is easily reversible by sudo rm -rf /nix; rm -rf ~/.nix-profile.
Only do this if you want to reproduce this inside the nix environment.

sh <(curl -L https://nixos.org/nix/install) # Install nix as single-user install (easily reversible)

Log out and back in.

Clone the repo and try to build.

git clone [email protected]:iFreilicht/iris-rs.git # or https://github.com/iFreilicht/iris-rs.git
cd iris-rs
nix-shell --pure  # Skip if reproducing without nix
cd iris-hub
wasm-pack build

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: wasm-pack 0.9.1
rustc version: rustc 1.49.0 (e1884a8e3 2020-12-29)
OS: Ubuntu 18.04LTS

@ghost
Copy link

ghost commented Mar 15, 2021

Try using the following shell.nix after creating a rust-toolchain file in your checkout that declares the rust version you are using: https://gitlab.com/sequoia-pgp/sequoia/-/blob/main/README.md#nixos

I had similar glibc errors but from using rustup to manage Rust toolchains on nixOS.

@listx
Copy link

listx commented Mar 19, 2021

Does rust-lang/futures-rs#2242 (comment) help?

@iFreilicht
Copy link
Author

iFreilicht commented Mar 21, 2021

@efx Holy shit, that worked perfectly! I started with your shell.nix and stripped out everything I didn't need. For everyone stumbling over this in the future, this is my final shell.nix that works perfectly for building any wasm-pack crate inside a pure nix shell:

# 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
  ];
}

And my rust-toolchain:

[toolchain]
channel = "stable"
components = [ "rust-src" ]
targets = [ "x86_64-unknown-linux-gnu", "wasm32-unknown-unknown" ]

@iFreilicht
Copy link
Author

@listx I'm not on NixOS, I'm using the Nix package manager on Ubuntu and Manjaro. I did try fully re-installing everything relating to Rust, but as opposed to NixOS, that doesn't change anything about what glibc version is installed, so I didn't help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants