Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exception handler #2

Open
wants to merge 1 commit into
base: wasm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,5 @@ endif

include mk/lib.mk

GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++2a -I src \
# -isystem /nix/store/9x6jfl84234im3f4gsrl1js3zyqz76jd-nlohmann_json-3.11.2/include \
# -isystem /nix/store/hl5lsmyf6alwj91nv8kmg2iz1lbnxym9-curl-7.86.0-dev/include \
# -isystem /nix/store/hyxa8plwvgbj16fi2rlvm2sy6idlkab1-libsodium-1.0.18-dev/include \
# -isystem /nix/store/ppqyr8qzdswkswcyb7214y9qg8cr7dnn-sqlite-3.39.4-dev/include \
# -isystem /nix/store/6015i0n0wxgqyg5ranqkdv9rbhyyqb4g-lowdown-0.9.0-dev/include \
# -isystem /nix/store/68pwg680mq51rlw5bkpii4hbbabzwl2b-editline-1.17.1-dev/include \
# -isystem /nix/store/f95kxwhnr2bazy7nl6wzwjiak02dlp9v-openssl-3.0.7-dev/include \
# -isystem /nix/store/vvfcnmqni2ijgzs9pcb3szx0axdmvjda-libarchive-3.6.1-dev/include \
# -isystem /nix/store/75j80ikwsw1qkb4171kspshqyc239p2h-brotli-1.0.9-dev/include \
-sUSE_BOOST_HEADERS=1 \
-sUSE_SQLITE3=1
GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++2a -I src -fwasm-exceptions
GLOBAL_LDFLAGS += -DEXCEPTION_DEBUG -fexceptions -sASSERTIONS=1 -fwasm-exceptions
22 changes: 22 additions & 0 deletions README-emscripten.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# nix-instantiate (emscripten WASM build)

git clone https://github.com/flox/nix/tree/wasm
cd nix
nix build .#d.nix -L

This will create a results folder where you can start a webserver in:

python3 -m http.server

This creates a port on localhost:8000 which can be opened in the webbrowser:

localhost:8000

Inside this webbrowser press `F12` for the `javascript console` and then evaluate this code:

try {Module.ccall("main_nix_instantiate2","string",["string"],["let\n c = 2; in { inherit c; c = 2;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };

try {Module.ccall("main_nix_instantiate2","string",["string"],["let c = 2; in { inherit c;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };

try {Module.ccall("main_nix_instantiate2","string",["string"],["let\n c = 2; in { inherit c; f = builtins.readDir ./.;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# nix-instantiate (emscripten WASM build)

See [README-emscripten.md](README-emscripten.md)

# Nix

[![Open Collective supporters](https://opencollective.com/nixos/tiers/supporter/badge.svg?label=Supporters&color=brightgreen)](https://opencollective.com/nixos)
Expand Down
77 changes: 53 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
# Forward from the previous stage as we don’t want it to pick the lowdown override
nixUnstable = prev.nixUnstable;

nix =
nix =
with final;
with commonDeps {
inherit pkgs;
Expand Down Expand Up @@ -553,7 +553,6 @@

sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile


rm -rf test/t*
'';

Expand Down Expand Up @@ -585,50 +584,49 @@
# fi
# echo "================= /testing zlib using node ================="
'';

# postPatch = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
# substituteInPlace configure \
# --replace '/usr/bin/libtool' 'ar' \
# --replace 'AR="libtool"' 'AR="ar"' \
# --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
# '';
});

nix = stdenv.mkDerivation {
nix = stdenv.mkDerivation {
name = "emscripten-nix";
nativeBuildInputs = [ jq emscripten pkg-config autoconf autoreconfHook automake autoconf-archive ];
nativeBuildInputs = [
jq
emscripten
pkg-config
autoconf
autoreconfHook
automake
autoconf-archive
];
buildInputs = [
boost
pkgconfig bzip2 zlib libtool bison flex curl git file
pkgconfig
bzip2
zlib
libtool
bison
flex
curl
git
file
nlohmann_json
libsodium
lsof
lowdown-nix
editline
libarchive
brotli
# openssl
openssl-wasm
sqlite-wasm
];
# NIX_PREFIX="/nix/store";
# NIX_PREFIX=\"$(prefix)\" \
# NIX_STORE_DIR=\"$(storedir)\" \
# NIX_DATA_DIR=\"$(datadir)\" \
# NIX_STATE_DIR=\"$(localstatedir)/nix\" \
# NIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
# NIX_CONF_DIR=\"$(sysconfdir)/nix\" \
# NIX_BIN_DIR=\"$(bindir)\" \
# NIX_MAN_DIR=\"$(mandir)\" \
src = builtins.path {
path = ./.;
name = "source";
filter = path: type: ! builtins.elem path [ (self.outPath + "/flake.nix")];
};
# OPENSSL_CFLAGS="-I ${openssl.dev}/include";
# OPENSSL_LIBS="-L${openssl-wasm}/lib -lcrypto";
configurePhase = ''
HOME=$TMPDIR
mkdir -p .emscriptencache
export EM_CACHE=$HOME/.emscriptencache
mkdir -p cache/sysroot/include/bits
mkdir -p cache/sysroot/include/SDL
emconfigure ./configure \
Expand All @@ -650,11 +648,42 @@
cp src/nix-instantiate/*.{wasm,js,html} $out
'';
checkPhase = ''

# try {Module.ccall("main_nix_instantiate2","string",["string"],["let\n c = 2; in { inherit c; c = 2;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };
# try {Module.ccall("main_nix_instantiate2","string",["string"],["let c = 2; in { inherit c;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };
# try {Module.ccall("main_nix_instantiate2","string",["string"],["let\n c = 2; in { inherit c; f = builtins.readDir ./.;}"]);} catch (e) { console.log(getExceptionMessage(e).toString()); };

'';
};
nixTestWASM = stdenv.mkDerivation {
name = "emscripten-nix-WASM-test";
nativeBuildInputs = [
nix
];
buildInputs = [];
src = builtins.path {
path = ./.;
name = "source";
filter = path: type: ! builtins.elem path [ (self.outPath + "/flake.nix")];
};
configurePhase = ''

'';
buildPhase = ''

'';
installPhase = ''

'';
checkPhase = ''
'';
};

};




# A Nixpkgs overlay that overrides the 'nix' and
# 'nix.perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv);
Expand Down
5 changes: 2 additions & 3 deletions src/nix-instantiate/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ nix-instantiate.html_LDFLAGS = \
-sNO_EXIT_RUNTIME=1 \
-sALLOW_MEMORY_GROWTH=1 \
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,UTF8ToString,ptrToString,allocateUTF8,UTF32ToString \
-sEXPORTED_FUNCTIONS=_processExpr,_main_nix_instantiate2
# -sUSE_SQLITE3=1 \
# -sUSE_BOOST_HEADERS=1 \
-sEXPORTED_FUNCTIONS=_processExpr,_main_nix_instantiate2 \
-sEXPORT_EXCEPTION_HANDLING_HELPERS

src/libexpr/parser-tab.cc src/libexpr/parser-tab.hh: src/libexpr/parser.y
$(trace-gen) bison -v -o src/libexpr/parser-tab.cc $< -d
Expand Down