From 974526748731dd7fadbfc3a8188a73f5782f03cb Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 10 Nov 2023 19:21:37 -0600 Subject: [PATCH] build wasm --- .gitignore | 5 ++++- flake.nix | 10 ++++++++-- wasm.nix | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 wasm.nix diff --git a/.gitignore b/.gitignore index ff51edf..094c23e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.direnv \ No newline at end of file +.direnv +/triangle +/triangle.wasm +/result* diff --git a/flake.nix b/flake.nix index 9a6d5b0..893752b 100644 --- a/flake.nix +++ b/flake.nix @@ -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 ]; + }; }); } diff --git a/wasm.nix b/wasm.nix new file mode 100644 index 0000000..c51e758 --- /dev/null +++ b/wasm.nix @@ -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 + ''; +}