diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-06-20 10:23:53 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-06-20 10:23:53 +0200 |
commit | 579e0ecd4bb5cd67debcfee10d69c7bfa37d630c (patch) | |
tree | 35d04bee3f773f2d54f70db4ae597a798d3366ae | |
parent | 6c855f985c7c4d5217ff85382d4f62cdf808507a (diff) |
Adding basic nix files
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .nix/derivation.nix | 29 | ||||
-rw-r--r-- | c++/lights_out.cpp | 9 | ||||
-rw-r--r-- | default.nix | 8 |
4 files changed, 45 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcfc4a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result* diff --git a/.nix/derivation.nix b/.nix/derivation.nix new file mode 100644 index 0000000..c3f76a3 --- /dev/null +++ b/.nix/derivation.nix @@ -0,0 +1,29 @@ +{ lib +, stdenv +}: + +stdenv.mkDerivation { + pname = "kel_lights_out"; + version = "0.0.0"; + + src = ./..; + + dontConfigure = true; + buildPhase = '' + HOME=$(pwd) + emcc c++/lights_out.cpp \ + -s WASM=1 \ + -s EXPORTED_FUNCTIONS='["_fake_main"]' \ + -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \ + -o lights_out.js + ''; + + # Silence the warnings for now + checkPhase = '' + ''; + + installPhase = '' + mkdir -p $out + cp lights_out.{wasm,js} $out/ + ''; +} diff --git a/c++/lights_out.cpp b/c++/lights_out.cpp index 9b8503f..810f403 100644 --- a/c++/lights_out.cpp +++ b/c++/lights_out.cpp @@ -91,8 +91,8 @@ bool lu_decompose_gf2(Mat& R, std::array<size_t,MN>& P){ return true; } - -int main(){ +extern "C"{ +int fake_main(){ Mat A; Vec b{ @@ -169,3 +169,8 @@ int main(){ return 0; } +} + +int main(){ + return fake_main(); +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c2bb53f --- /dev/null +++ b/default.nix @@ -0,0 +1,8 @@ +{ pkgs ? import <nixpkgs> {} +, stdenv ? pkgs.emscriptenStdenv +, ... +}: + +pkgs.callPackage .nix/derivation.nix { + inherit stdenv; +} |