feat: add hacky wasm-pkg nix package
This commit is contained in:
@@ -36,6 +36,27 @@
|
||||
}: let
|
||||
# Use rust-bin to generate the toolchain from rust-toolchain.toml
|
||||
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
rustPlatform = pkgs.makeRustPlatform {
|
||||
cargo = rust-toolchain;
|
||||
rustc = rust-toolchain;
|
||||
};
|
||||
rust-toolchain-pkgs = pkgs.extend (_: _: {
|
||||
inherit rustPlatform;
|
||||
});
|
||||
wasm-bindgen = with rust-toolchain-pkgs;
|
||||
buildWasmBindgenCli rec {
|
||||
src = fetchCrate {
|
||||
pname = "wasm-bindgen-cli";
|
||||
version = "0.2.127";
|
||||
hash = "sha256-di+qBAdd7pENLiIB9CoZoab+W5xeDoByMREcCGTSzWo=";
|
||||
};
|
||||
|
||||
cargoDeps = rustPlatform.fetchCargoVendor {
|
||||
inherit src;
|
||||
inherit (src) pname version;
|
||||
hash = "sha256-FTv2GZIAQs0ePdIZXIXil7JbZ6kIT05VG6vqC1qNFxQ=";
|
||||
};
|
||||
};
|
||||
|
||||
buildRustCrateForPkgs = _:
|
||||
pkgs.buildRustCrate.override {
|
||||
@@ -49,6 +70,15 @@
|
||||
src = ./.;
|
||||
};
|
||||
|
||||
cross-pkgs2 = inputs.nixpkgs.legacyPackages.${system}.pkgsCross.wasm32-unknown-none;
|
||||
cross-pkgs = import pkgs.path {
|
||||
inherit (pkgs) system;
|
||||
crossSystem =
|
||||
pkgs.lib.systems.examples.wasm32-unknown-none
|
||||
// {
|
||||
rust.rustcTargetSpec = "wasm32-unknown-unknown";
|
||||
};
|
||||
};
|
||||
cargoNix = import generatedCargoNix {
|
||||
inherit pkgs buildRustCrateForPkgs;
|
||||
};
|
||||
@@ -60,6 +90,53 @@
|
||||
};
|
||||
|
||||
packages = {
|
||||
wordle-solver-wasm = cross-pkgs2.callPackage (
|
||||
{
|
||||
rustPlatform,
|
||||
buildPackages,
|
||||
lld,
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "wordle-solver";
|
||||
version = "0.1.0";
|
||||
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
|
||||
];
|
||||
|
||||
cargoBuildFlags = [
|
||||
"--lib"
|
||||
"--features"
|
||||
"wasm-bindgen"
|
||||
];
|
||||
|
||||
# Configure rustc for WASM
|
||||
env = {
|
||||
RUSTFLAGS = ''--cfg=web_sys_unstable_apis -C linker=wasm-ld'';
|
||||
};
|
||||
|
||||
# Copy the WASM file to the output
|
||||
installPhase = ''
|
||||
mkdir -p $out/lib
|
||||
cp target/wasm32-unknown-unknown/release/*.wasm $out/lib/
|
||||
'';
|
||||
}
|
||||
) {};
|
||||
wordle-solver-wasm-pkg = pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "wordle-solver-wasm-pkg";
|
||||
nativeBuildInputs = [wasm-bindgen];
|
||||
unpackPhase = "true";
|
||||
buildPhase = ''
|
||||
wasm-bindgen --target bundler --out-dir $out ${self'.packages.wordle-solver-wasm}/lib/wordle_solver.wasm
|
||||
'';
|
||||
};
|
||||
wordle-solver = cargoNix.rootCrate.build;
|
||||
default = self'.packages.wordle-solver;
|
||||
};
|
||||
@@ -67,10 +144,11 @@
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
rust-toolchain
|
||||
wasm-bindgen
|
||||
pkgs.wasm-pack
|
||||
pkgs.nodejs
|
||||
pkgs.typescript-language-server
|
||||
pkgs.vscode-langservers-extracted
|
||||
pkgs.wasm-bindgen-cli
|
||||
pkgs.wasm-pack
|
||||
pkgs.yarn
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user