Properly install wasm-bindgen

This commit is contained in:
Surma
2024-08-14 00:35:27 +01:00
parent a9c16df263
commit e4cec57fe3
3 changed files with 79 additions and 33 deletions

View File

@@ -73,7 +73,8 @@
"inputs": {
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
"nixpkgs": "nixpkgs_2",
"wasm-bindgen": "wasm-bindgen"
}
},
"rust-analyzer-src": {
@@ -107,6 +108,23 @@
"repo": "default",
"type": "github"
}
},
"wasm-bindgen": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1,
"narHash": "sha256-ZBQyty6638OHI5UZBk79+VY3LOAO51OexUMn4AQWS3Y=",
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen",
"type": "path"
},
"original": {
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen",
"type": "path"
}
}
},
"root": "root",

View File

@@ -3,6 +3,11 @@
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 =
{
@@ -10,6 +15,7 @@
nixpkgs,
flake-utils,
fenix,
wasm-bindgen,
}:
flake-utils.lib.eachDefaultSystem (
system:
@@ -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;
{
@@ -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
@@ -75,10 +57,6 @@
runHook postBuild
'';
dontInstall = true;
# installPhase = ''
# mkdir -p $out
# cp -r pkg/* $out
# '';
};
installScript = writeShellScriptBin "install.sh" ''

View File

@@ -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;
};
};
};
}