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

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

Open
Velnbur opened this issue Aug 4, 2023 · 2 comments

Comments

@Velnbur
Copy link

Velnbur commented Aug 4, 2023

🐛 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

@Velnbur
Copy link
Author

Velnbur commented Sep 11, 2023

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

@ipetkov
Copy link

ipetkov commented Nov 5, 2023

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

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