-
Hello, We've moved away from In a second time, we would like to use crane to build the WASM REPL as well. Nothing fancy, it's a wrapper crate around the main one, and we must produce a package accessible from JavaScript. However the current build relies on the We're going to investigate more, but in the meantime, is there any obvious solution, or something that is done obviously wrong? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @yannham glad you are appreciating the documentation! It's been a while since I've last used Assuming that fixes any sandbox related issues, I think it should be possible to make a build work. You might have to drop down to using {
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, utils, ... }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import inputs.rust-overlay)
];
};
rust-toolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [
"wasm32-unknown-unknown"
];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust-toolchain;
src = craneLib.cleanCargoSources ./.;
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
cargoExtraArgs = "--target wasm32-unknown-unknown";
doCheck = false;
};
in
rec {
packages.default = craneLib.mkCargoDerivation {
inherit cargoArtifacts src;
buildPhaseCargoCommand = ''
wasm-pack build
'';
installPhaseCommand = ''
# Install whatever is needed
mv pkg $out
'';
nativeBuildInputs = with pkgs; [
binaryen
wasm-bindgen-cli
wasm-pack
];
};
}
);
} |
Beta Was this translation helpful? Give feedback.
-
@ipetkov have been stuck on this.
It seems
I fixed this by setting $HOME='.' before the build
When leaving $HOME as default or setting it to /homeless-shelter wasm build fails. We could add that as an example as well. Because not everyone builds web apps with |
Beta Was this translation helpful? Give feedback.
Hi @yannham glad you are appreciating the documentation!
It's been a while since I've last used
wasm-pack
(especially since the last time I tried using it with Nix too) and I do remember hitting some headaches from it trying to access the network from inside the sandbox. Although it doesn't seem to support an offline mode, I believe it will skip trying to install various tools if they're already on the path (IIRC it needspkgs.binaryen
andpkgs.wasm-bindgen-cli
on thePATH
)Assuming that fixes any sandbox related issues, I think it should be possible to make a build work. You might have to drop down to using
mkCargoDerivation
, here's a quick and dirty example: