Make cross compiling work with vendoring

This commit is contained in:
Surma
2024-08-14 10:20:02 +01:00
parent e4cec57fe3
commit d278efb148
2 changed files with 19 additions and 5 deletions

View File

@@ -118,11 +118,11 @@
"locked": {
"lastModified": 1,
"narHash": "sha256-ZBQyty6638OHI5UZBk79+VY3LOAO51OexUMn4AQWS3Y=",
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen",
"path": "/nix/store/qmv8wrsh9s2i7z7b5a5iak6nark83267-source/nix/wasm-bindgen",
"type": "path"
},
"original": {
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen",
"path": "/nix/store/qmv8wrsh9s2i7z7b5a5iak6nark83267-source/nix/wasm-bindgen",
"type": "path"
}
}

View File

@@ -31,9 +31,19 @@
];
src = ./.;
rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
cargoLockFile = "${src}/Cargo.lock";
vendor = rustPlatform.importCargoLock {
lockFile = cargoLockFile;
};
wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock {
inherit system;
cargoLockFile = "${src}/Cargo.lock";
inherit system cargoLockFile;
sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8=";
};
in
@@ -52,7 +62,11 @@
buildPhase = ''
runHook preBuild
export CARGO_HOME=$TMPDIR/.cargo
cargo build --target wasm32-unknown-unknown -r
cargo build \
--config 'source.crates-io.replace-with="vendored-sources"' \
--config 'source.vendored-sources.directory="${vendor}"' \
--offline \
--target ${target} -r
wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
runHook postBuild
'';