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": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-ZBQyty6638OHI5UZBk79+VY3LOAO51OexUMn4AQWS3Y=", "narHash": "sha256-ZBQyty6638OHI5UZBk79+VY3LOAO51OexUMn4AQWS3Y=",
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen", "path": "/nix/store/qmv8wrsh9s2i7z7b5a5iak6nark83267-source/nix/wasm-bindgen",
"type": "path" "type": "path"
}, },
"original": { "original": {
"path": "/nix/store/v77iy474167bmkvc9glwhkxhi728nn88-source/nix/wasm-bindgen", "path": "/nix/store/qmv8wrsh9s2i7z7b5a5iak6nark83267-source/nix/wasm-bindgen",
"type": "path" "type": "path"
} }
} }

View File

@@ -31,9 +31,19 @@
]; ];
src = ./.; src = ./.;
wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock { rustPlatform = pkgs.makeRustPlatform {
inherit system; cargo = toolchain;
rustc = toolchain;
};
cargoLockFile = "${src}/Cargo.lock"; cargoLockFile = "${src}/Cargo.lock";
vendor = rustPlatform.importCargoLock {
lockFile = cargoLockFile;
};
wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock {
inherit system cargoLockFile;
sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8="; sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8=";
}; };
in in
@@ -52,7 +62,11 @@
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
export CARGO_HOME=$TMPDIR/.cargo 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 wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
runHook postBuild runHook postBuild
''; '';