Skip to content

Commit

Permalink
Properly install wasm-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Aug 13, 2024
1 parent a9c16df commit e4cec57
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 33 deletions.
20 changes: 19 additions & 1 deletion codecs/resize/flake.lock

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

42 changes: 10 additions & 32 deletions codecs/resize/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
nixpkgs.url = "github:nixos/nixpkgs/24.05";
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
wasm-bindgen = {
url = "../../nix/wasm-bindgen";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
fenix,
wasm-bindgen,
}:
flake-utils.lib.eachDefaultSystem (
system:
Expand All @@ -25,27 +31,11 @@
];
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;
wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock {
inherit system;
cargoLockFile = "${src}/Cargo.lock";
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 @@ -55,18 +45,10 @@
name = "squoosh-resize";
inherit src;
nativeBuildInputs = [
#naersk'
toolchain
curl
iconv
# wasm-pack
wasm-bindgen
wasm-bindgen-bin
];
dontConfigure = true;
# postUnpack = ''
# export CARGO_HOME=$TMPDIR/.cargo
# cargo install -f wasm-bindgen-cli --version ${wasm-bindgen-version}
# '';
buildPhase = ''
runHook preBuild
export CARGO_HOME=$TMPDIR/.cargo
Expand All @@ -75,10 +57,6 @@
runHook postBuild
'';
dontInstall = true;
# installPhase = ''
# mkdir -p $out
# cp -r pkg/* $out
# '';
};

installScript = writeShellScriptBin "install.sh" ''
Expand Down
50 changes: 50 additions & 0 deletions nix/wasm-bindgen/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
outputs =
{ self, nixpkgs }:
{
lib = {
build =
{
system,
version,
sha256,
}:
let
pkgs = nixpkgs.legacyPackages.${system};
wasm-bindgen-src = pkgs.fetchCrate {
pname = "wasm-bindgen-cli";
inherit version sha256;
};
in
pkgs.rustPlatform.buildRustPackage {
name = "wasm-bindgen-cli";
buildInputs = [
pkgs.curl
pkgs.darwin.apple_sdk.frameworks.Security
];
src = wasm-bindgen-src;
cargoLock = {
lockFile = "${wasm-bindgen-src}/Cargo.lock";
};
doCheck = false;
};

buildFromCargoLock =
{
system,
cargoLockFile,
sha256,
}:
let
pkgs = nixpkgs.legacyPackages.${system};
cargoLock = pkgs.lib.importTOML cargoLockFile;
wasm-bindgen-version =
(pkgs.lib.lists.findFirst (x: x.name == "wasm-bindgen") null cargoLock.package).version;
in
self.lib.build {
inherit system sha256;
version = wasm-bindgen-version;
};
};
};
}

0 comments on commit e4cec57

Please sign in to comment.