+/tetris
my tetris implementation
git clone https://git.julia.blue/+/tetris
5700970
wasm
1{ 2description = "tetris and related tools" ; 3inputs = { 4nixpkgs . url = "github:NixOS/nixpkgs/nixpkgs-unstable" ; 5flake-utils . url = "github:numtide/flake-utils" ; 6crane . url = "github:ipetkov/crane" ; 7rust-overlay . url = "github:oxalica/rust-overlay" ; 8rust-overlay . inputs . nixpkgs . follows = "nixpkgs" ; 9}; 10 11outputs = { self , nixpkgs , flake-utils , crane , rust-overlay , ...} : 12flake-utils . lib . eachDefaultSystem ( system :let 13pkgs = import nixpkgs { 14inherit system ; 15overlays = [ ( import rust-overlay ) ]; 16}; 17craneLib = ( crane . mkLib pkgs ). overrideToolchain ( p : 18p . rust-bin . stable . latest . default . override { 19targets = [ "wasm32-unknown-unknown" ]; 20}); 21inherit ( pkgs ) lib ; 22 23darwinArgs = { 24# `coreaudio-sys` calls `bindgen` at build time _always_ 😞 25LIBCLANG_PATH = " ${ pkgs . llvmPackages . libclang . lib } /lib" ; 26# might still need to set COREAUDIO_SDK_PATH to $SDK_ROOT? 27}; 28 29addBindgenEnvVar = base :base . overrideAttrs ( old :{ 30# (the above fixes for the macOS framework paths do not seem to be 31# enough anymore; poking at `cbindgen` reveals that it now seems to 32# "sanitize" our NIX_CFLAGS_COMPILE injected `-iframework` includes 33# and turn them into regular `-isystem` includes, breaking 34# framework headers. to get around this we use the inelegant 35# "big hammer" solution below: forcibly reintroducing our 36# `-iframework` flags to `cbindgen`'s list of flags passed to 37# `libclang`): 38preBuild = ( old . preBuild or "" ) + 39pkgs . lib . optionalString ( pkgs . stdenv . isDarwin ) '' 40export BINDGEN_EXTRA_CLANG_ARGS="$NIX_CFLAGS_COMPILE" 41'' ; 42}); 43 44src = let 45kdlFilter = path :_type :builtins . match ".*kdl$" path != null ; 46kdlOrCargo = path :type : 47( kdlFilter path type ) || ( craneLib . filterCargoSources path type ); 48in lib . cleanSourceWith { src = ./. ; filter = kdlOrCargo ; name = "source" ; }; 49 50commonArgs = { 51inherit src ; 52strictDeps = true ; 53 54nativeBuildInputs = lib . optionals pkgs . stdenv . isLinux ( with pkgs ; [ 55pkg-config makeWrapper 56]); 57 58buildInputs = with pkgs ; [ libiconv openssl ] ++ 59( lib . optional ( stdenv . isLinux ) alsa-lib ) ++ 60( lib . optional ( stdenv . isDarwin ) pkgs . xcbuild ); 61} // ( pkgs . lib . optionalAttrs ( pkgs . stdenv . isDarwin ) darwinArgs ); 62 63cargoArtifacts = addBindgenEnvVar ( craneLib . buildDepsOnly commonArgs ); 64 65tetris = craneLib . buildPackage ( commonArgs // { 66inherit cargoArtifacts ; 67doCheck = false ; # there's a separate check for that 68} // { 69cargoExtraArgs = "-p cli" ; 70postInstall = '' 71mv $out/bin/cli $out/bin/tetris 72'' + ( pkgs . lib . optionalString ( pkgs . stdenv . isLinux ) '' 73wrapProgram $out/bin/tetris \ 74--set-default "ALSA_PLUGIN_DIR" " ${ pkgs . alsa-plugins } /lib/alsa-lib" 75'' ); 76}); 77 78# jstrisSprint = pkgs.writeShellApplication { 79# name = "jstris-sprint"; 80# runtimeInputs = jjstrisScriptDeps; 81# text = ./jstris-sprint.sh; 82# }; 83 84jstrisScriptDeps = with pkgs ; [ 85xh pup jq bc sd choose moreutils gnuplot 86( python3 . withPackages ( pp :with pp ;[ matplotlib ])) 87]; 88 89in { 90packages . default = tetris ; 91 92checks = { 93build = tetris ; 94test = craneLib . cargoNextest ( commonArgs // { 95inherit cargoArtifacts ; 96cargoNextestExtraArgs = "--workspace" ; 97}); 98clippy = addBindgenEnvVar ( craneLib . cargoClippy ( commonArgs // { 99inherit cargoArtifacts ; 100cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings" ; 101})); 102doc = craneLib . cargoDoc ( commonArgs // { 103inherit cargoArtifacts ; 104cargoDocExtraArgs = "--no-deps -p tetris" ; 105}); 106}; 107 108devShells . default = craneLib . devShell { 109inputsFrom = [ tetris ]; 110checks = self . checks .${ system }; 111packages = with pkgs ; [ 112rust-analyzer 113wasm-pack static-web-server 114] ++ jstrisScriptDeps ; 115}; 116} 117); 118}