build wasm

This commit is contained in:
Michael Zhang 2023-11-10 19:21:37 -06:00
parent 0171ce2c7e
commit 9745267487
3 changed files with 30 additions and 3 deletions

5
.gitignore vendored
View file

@ -1 +1,4 @@
.direnv
.direnv
/triangle
/triangle.wasm
/result*

View file

@ -5,10 +5,16 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
flakePkgs = { triangle = pkgs.callPackage ./. { }; };
flakePkgs = {
triangle = pkgs.callPackage ./. { };
triangle-wasm = pkgs.callPackage ./wasm.nix { };
};
in {
packages = flakePkgs;
devShell = pkgs.mkShell { packages = with pkgs; [ nixfmt ]; };
devShell = pkgs.mkShell {
inputsFrom = with flakePkgs; [ triangle ];
packages = with pkgs; [ nixfmt emscripten ];
};
});
}

18
wasm.nix Normal file
View file

@ -0,0 +1,18 @@
{ buildEmscriptenPackage }:
buildEmscriptenPackage {
name = "triangle";
src = ./.;
configurePhase = "";
buildPhase = ''
export EM_CACHE=/tmp/em-cache
emcc -o triangle triangle.c
'';
checkPhase = "";
installPhase = ''
mkdir -p $out
ls -al
mv triangle triangle.wasm $out
'';
}