158 lines
4.6 KiB
Nix
158 lines
4.6 KiB
Nix
{
|
|
description = "Wordle-Solver";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
crate2nix = {
|
|
url = "github:nix-community/crate2nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = inputs @ {
|
|
flake-parts,
|
|
crate2nix,
|
|
rust-overlay,
|
|
...
|
|
}:
|
|
flake-parts.lib.mkFlake {inherit inputs;} {
|
|
systems = [
|
|
"aarch64-linux"
|
|
"aarch64-darwin"
|
|
"x86_64-darwin"
|
|
"x86_64-linux"
|
|
];
|
|
|
|
perSystem = {
|
|
pkgs,
|
|
system,
|
|
self',
|
|
...
|
|
}: 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 {
|
|
rustc = rust-toolchain; # Use rustc from toolchain
|
|
cargo = rust-toolchain; # Use cargo from toolchain
|
|
};
|
|
|
|
# Cargo.nix for IFD
|
|
generatedCargoNix = crate2nix.tools.${system}.generatedCargoNix {
|
|
name = "rustnix";
|
|
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;
|
|
};
|
|
in {
|
|
# Overlay pkgs with rust-bin
|
|
_module.args.pkgs = import inputs.nixpkgs {
|
|
inherit system;
|
|
overlays = [(import rust-overlay)];
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
buildInputs = [
|
|
rust-toolchain
|
|
wasm-bindgen
|
|
pkgs.wasm-pack
|
|
pkgs.nodejs
|
|
pkgs.typescript-language-server
|
|
pkgs.vscode-langservers-extracted
|
|
pkgs.yarn
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|