rustwasm/wasm-pack

`wasm-pack` failes with error `Read-only file system (os error 30)` inside nix derivation

Velnbur opened this issue ยท 2 comments

๐Ÿ› Bug description

Currently, I'm trying to build an npm package for nodejs projects using Wasm binaries compiled from Rust. And for packaging automation using wasm-pack, nix flakes, and crane.

But wasm-pack failed with:

Error: Read-only file system (os error 30)
Caused by: Read-only file system (os error 30)

But when using cargo build manually, with wasm-bindgen-cli and self-made scripts to emulate some of the wasm-pack features, everything works fine.

๐Ÿค” Expected Behavior

Work without fail or at least with more reasonable error messages

๐Ÿ‘Ÿ Steps to reproduce

My minimal reproduce setup:

rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;

src = with pkgs; lib.cleanSourceWith {
  src = ./.; # The original, unfiltered source
  filter = path: type:
    # Default filter from crane (allow .rs files)
    (craneLib.filterCargoSources path type)
  ;
};

commonArgs = {
  inherit src;
  pname = "tools";
  nativeBuildInputs = with pkgs; [
    # in future add other deps
  ] ++ lib.optional stdenv.isDarwin [
    libiconv
  ];
};

wasmArgs = commonArgs // {
  inherit src;
  pname = "hardhat-diamond-tools";
  cargoExtraArgs = "--package=diamond-tools-plugin";
  CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
};

wasmArtifacts = craneLib.buildDepsOnly (wasmArgs // {
  doCheck = false; 
});

# Required to not rebuild the artifacts when `.js` files change
pluginSrc = with pkgs; lib.cleanSourceWith {
  src = ./.; # The original, unfiltered source
  filter = path: type:
    (lib.hasSuffix "\.js" path) || # For plugin javascript
    (lib.hasSuffix "\.json" path) || # For package.json
    (lib.hasSuffix "\.sh" path) || # For scripts
    (lib.hasSuffix "\.ts" path) || # For typescript files in plugin
    (lib.hasSuffix "README.md" path) ||
    # Default filter from crane (allow .rs files)
    (craneLib.filterCargoSources path type)
  ;
};

plugin = craneLib.mkCargoDerivation (wasmArgs // rec {
  src = pluginSrc; # replace src with filtered source
  cargoArtifacts = wasmArtifacts;
  cargoExtraArgs = "";
  doCheck = false;

  buildPhaseCargoCommand = ''
    mkdir -p $out/pkg
    wasm-pack --verbose build -t nodejs -m normal --out-dir $out/pkg $src/plugin
  '';

  buildInputs = with pkgs; [
    wasm-pack
    wasm-bindgen-cli
    nodejs
    cargo-generate
    cargo-expand
    binaryen
  ];
});

๐ŸŒ Your environment

Include the relevant details of your environment.

wasm-pack version: 0.11.1 from nixpkgs
rustc version: 1.70.0 (d59363ad0 2023-06-01)

UPD: updated rustc to stable version. Also using Mac as OS

From ipetkov/crane#40 wasm-pack doesn't work without a $HOME directory

Cross linking to the existing discussion: ipetkov/crane#362