From 4c25cf3f7cfc83b2d75d8997c70da86a302dc1da Mon Sep 17 00:00:00 2001 From: Robert Aboukhalil Date: Wed, 19 Jul 2023 08:04:39 -0700 Subject: [PATCH] Reset options to 0 so can call main() multiple times in a row --- README.md | 7 +++++++ src/main.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 7871ca84..e21ed9bc 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,13 @@ cross-compilation environment. See also ["Cross compilation"](https://github.com/jqlang/jq/wiki/Cross-compilation) on the wiki. +To compile jq to WebAssembly, install the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html), then: + + git submodule update --init # if building from git to get oniguruma + autoreconf -i # if building from git + emconfigure ./configure --with-oniguruma=builtin --disable-maintainer-mode + emmake make EXEEXT=.js CFLAGS="-O2" LDFLAGS="-s EXPORTED_RUNTIME_METHODS=['callMain']" + # Community diff --git a/src/main.c b/src/main.c index 3c5133d7..49cd0ed1 100644 --- a/src/main.c +++ b/src/main.c @@ -292,6 +292,12 @@ int main(int argc, char* argv[]) { _setmode(fileno(stderr), _O_TEXT | _O_U8TEXT); #endif +#ifdef __EMSCRIPTEN__ + /* When compiling to WebAssembly with Emscripten, reset options to ensure we can + call main() multiple times without reinitializing the WebAssembly module. */ + options = 0; +#endif + if (argc) progname = argv[0]; jq = jq_init();