Files
wordle-solver-rs/nix/wordle-solver-wasm.nix
2026-09-08 17:34:07 +02:00

57 lines
1.5 KiB
Nix

{
perSystem = {pkgs, ...}: let
utils = import ./utils.nix;
rust-toolchain = utils.rust-toolchain pkgs;
toolchain-crosspkgs = utils.toolchain-crosspkgs pkgs;
drv = {
rustPlatform,
buildPackages,
lld,
name ? "wordle-solver",
removeReferencesTo,
...
}:
rustPlatform.buildRustPackage {
inherit name;
src = ../.; # Or your source location
cargoLock.lockFile = ../Cargo.lock;
# Disable tests since they can't run on WASM
doCheck = false;
# Required dependencies for WASM builds
depsBuildBuild = [
buildPackages.stdenv.cc
lld # Needed for wasm-ld
];
nativeBuildInputs = [removeReferencesTo];
cargoBuildFlags = [
"--lib"
"--features"
"wasm-bindgen"
];
# Configure rustc for WASM
RUSTFLAGS = ''--cfg=web_sys_unstable_apis -C linker=wasm-ld -C strip=debuginfo -C debuginfo=0'';
# Copy the WASM file to the output
installPhase = ''
mkdir -p $out/lib
cp target/wasm32-unknown-unknown/release/*.wasm $out/lib/
runHook postInstall
'';
# Remove toolchain from closure (store paths are debug artifacts)
postInstall = ''
remove-references-to -t ${rust-toolchain} $out/lib/*.wasm
'';
};
in {
packages.toolchain = rust-toolchain;
packages.wordle-solver-wasm = toolchain-crosspkgs.callPackage drv {};
};
}