Skip to content

Commit

Permalink
Properly build wasm-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Aug 13, 2024
1 parent 15df976 commit a9c16df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
35 changes: 1 addition & 34 deletions codecs/resize/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions codecs/resize/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
nixpkgs.url = "github:nixos/nixpkgs/24.05";
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
naersk.url = "github:nix-community/naersk";
};
outputs =
{
self,
nixpkgs,
flake-utils,
fenix,
naersk,
}:
flake-utils.lib.eachDefaultSystem (
system:
Expand All @@ -25,14 +23,29 @@
stable.cargo
targets.${target}.stable.rust-std
];
naersk' = pkgs.callPackage naersk {
rustc = toolchain;
cargo = toolchain;
};
src = ./.;

cargoLock = pkgs.lib.importTOML "${src}/Cargo.lock";
wasm-bindgen-version =
(pkgs.lib.lists.findFirst (x: x.name == "wasm-bindgen") null cargoLock.package).version;
wasm-bindgen-src = pkgs.fetchCrate {
pname = "wasm-bindgen-cli";
version = wasm-bindgen-version;
sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8=";
};
wasm-bindgen = pkgs.rustPlatform.buildRustPackage {
name = "wasm-bindgen-cli";
buildInputs = [
pkgs.curl
pkgs.darwin.apple_sdk.frameworks.Security
];
src = wasm-bindgen-src;
# cargoSha256 = "sha256-I6fsBSyqiubbMKyxXhMebKnpRZdB6bHHSB+NyrrqSnY=";
cargoLock = {
lockFile = "${wasm-bindgen-src}/Cargo.lock";
};
doCheck = false;
};
in
with pkgs;
{
Expand All @@ -47,18 +60,18 @@
curl
iconv
# wasm-pack
# wasm-bindgen-cli
wasm-bindgen
];
dontConfigure = true;
postUnpack = ''
export CARGO_HOME=$TMPDIR/.cargo
cargo install -f wasm-bindgen-cli --version ${wasm-bindgen-version}
'';
# postUnpack = ''
# export CARGO_HOME=$TMPDIR/.cargo
# cargo install -f wasm-bindgen-cli --version ${wasm-bindgen-version}
# '';
buildPhase = ''
runHook preBuild
export CARGO_HOME=$TMPDIR/.cargo
cargo build --target wasm32-unknown-unknown -r
$CARGO_HOME/bin/wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
runHook postBuild
'';
dontInstall = true;
Expand Down

0 comments on commit a9c16df

Please sign in to comment.