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

Porting to webassembly #8

Open
saolsen opened this issue Dec 4, 2022 · 86 comments
Open

Porting to webassembly #8

saolsen opened this issue Dec 4, 2022 · 86 comments
Labels
browser Web browser, JavaScript, and WASM integration enhancement New feature or request

Comments

@saolsen
Copy link

saolsen commented Dec 4, 2022

Hey,

I'm thinking about trying to get blink running in the browser (via webassembly). My goal isn't just to run c code in the browser (could just use emscripten for that) but to actually run ape x64 executables in an interpreter where I can build a debugger and some visualization tools to see what's happening. (Similar to what blink already does).
I'm wondering if anybody has tried to compile blink for webassembly or what you think some of the challenges would be.

@jart
Copy link
Owner

jart commented Dec 4, 2022

Sounds awesome. I haven't tried it myself. I imagine the only major obstacle might be 32-bit. JavaScript only supports 32-bit integers. Blink runs on i386 and other 32-bit CPUs, and is regularly tested on them. However Blink was created in a 64-bit world, and as such, Blink has a 64-bit bias, therefore, you might not get optimal performance out of Blink in your 32-bit environments.

@unicomp21
Copy link

This would be awesome!!!

@unicomp21
Copy link

unicomp21 commented Jan 4, 2023

WebAssembly/tail-call#15 (comment)

We're still waiting on tail calls for webassembly, lol. Wish there was another performant option.

@unicomp21
Copy link

Someday we'll be able to use co_await in webassembly, hope I'm still around to see it happen, lol.

WebAssembly/tail-call#14 (comment)

@unicomp21
Copy link

@jart
Copy link
Owner

jart commented Jan 4, 2023

Blink doesn't need tail calls.

Also, good news! Blink is now stable on 32-bit platforms. I don't know if webassembly is multi-core, but the threading issues Blink was having earlier on 32-bit have been resolved.

Your biggest obstacle is most likely going to be completely replacing everything in blink/syscall.c so it interfaces with WASI or something similar instead.

@unicomp21
Copy link

@unicomp21
Copy link

unicomp21 commented Jan 4, 2023

@GorNishanov @tlively @madmongo1 @tomoliv30 any ideas on easiest way to implement linux syscall.c for webassembly?

#8 (comment)

WebKit/WebKit#2065

@unicomp21
Copy link

unicomp21 commented Jan 4, 2023

Dumb/crazy question, what sort of perf hit if blink runs nested within itself? I'm wondering if the outer vm could implement syscall.c for the inner vm? And handle threading etc. using co_await? Then outer vm could provide stupid simple interfaces for tunneling packets, etc.?

@jart
Copy link
Owner

jart commented Jan 4, 2023

It's possible to run Blink within Blink. There's noticeable slowdown, but it's not a showstopper. There's caveats, such as you can only have a single of the nested Blink instances make use of the linear memory optimization. The other nestings need to pass blink -m to turn it off, otherwise the memory allocations will collide.

@Vogtinator
Copy link
Contributor

any ideas on easiest way to implement linux syscall.c for webassembly?

emscripten provides a surprisingly wide set of runtime APIs which might even be enough to "just work" already.

@Vogtinator
Copy link
Contributor

Also, good news! Blink is now stable on 32-bit platforms. I don't know if webassembly is multi-core, but the threading issues Blink was having earlier on 32-bit have been resolved.

With web workers and SharedArrayBuffers it's possibly to effectively have threads and emscripten even exposes those through pthreads as much as possible.

any ideas on easiest way to implement linux syscall.c for webassembly?

emscripten provides a surprisingly wide set of runtime APIs which might even be enough to "just work" already.

I gave it a quick try and it does almost build out-of-the-box with just emmake make -j8. It just complains about sa_len and wait4 missing. With those worked around I get a blink.wasm of unknown quality, not tested.

@jart
Copy link
Owner

jart commented Jan 4, 2023

I got it to compile too. When I tried to run Blink in Node, this happened, and I have no idea what it means.

master jart@turfwar:~/blink$ node o//blink/blink
/home/jart/blink/o/blink/blink:2148
  function ___invoke_$struct_Machine*_$struct_System*_$struct_Machine*(
                                    ^

SyntaxError: Unexpected token '*'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

I configured the Makefile to build an HTML file and ran it in the browser. I got the same thing.

image

I'm going to push the fixes I made right now. Could you please help me figure out what's wrong?

@Vogtinator
Copy link
Contributor

You might need newer LLVM or emscripten: emscripten-core/emscripten#12551

I'm using emscripten main with clang 15.0.6 (should be 16 mmeanwhile, but it works 🤷)

@Vogtinator
Copy link
Contributor

Works!

/tmp/blink> node o/blink/blink -m /cwd/third_party/cosmo/tinyhello.elf
hello world

The WASM page size is 64KiB, which means that #14 happens, but by doing the awful hack of just pretending that it's actually 4096 it can even run busybox-static from the host here:

/tmp/blink> (cd /usr/bin; node /tmp/blink/o/blink/blink -m /cwd/busybox-static sh -c "echo Hello world!")
I2023-01-04T19:25:47.197000:blink/syscall.c:2610:42 missing syscall 0x111
I2023-01-04T19:25:47.198000:blink/syscall.c:2610:42 missing syscall 0x14e
warning: unsupported syscall: __syscall_prlimit64

I2023-01-04T19:25:47.200000:blink/syscall.c:1857:42 getrandom() flags not supported yet
Hello world!

It did require some hacks and workarounds though:

  • Expose the working directory in the virtual filesystem below /cwd
  • emscripten does not pass envp to main, use environ instead (crashes in LoadArgv otherwise)
diff --git a/blink/blink.c b/blink/blink.c
index f6c0506..a241fd0 100644
--- a/blink/blink.c
+++ b/blink/blink.c
@@ -155,8 +155,10 @@ static void HandleSigs(void) {
   unassert(!sigaction(SIGSEGV, &sa, 0));
 #endif
 }
-
+#include <emscripten.h>
 int main(int argc, char *argv[], char **envp) {
+  EM_ASM({FS.mkdir('/cwd'); FS.mount(NODEFS, {root : '.'}, '/cwd');});
+  if(!envp) envp = environ;
   g_blink_path = argc > 0 ? argv[0] : 0;
   GetOpts(argc, argv);
   if (optind_ == argc) PrintUsage(argc, argv, 48, 2);
  • Function pointers work differently, they don't really contain an address so comparing > 4096 fails:
diff --git a/blink/debug.h b/blink/debug.h
index a996413..5e64aa9 100644
--- a/blink/debug.h
+++ b/blink/debug.h
@@ -10,7 +10,7 @@
 #define IB(x)                      \
   __extension__({                  \
     __typeof__(x) x_ = (x);        \
-    unassert((intptr_t)x_ > 4096); \
+    unassert((intptr_t)x_ > 0); \
     x_;                            \
   })
 #else
  • emscripten's mmap does not support address hints:
diff --git a/blink/memorymalloc.c b/blink/memorymalloc.c
index 3d0113b..b0b9266 100644
--- a/blink/memorymalloc.c
+++ b/blink/memorymalloc.c
@@ -64,6 +64,10 @@ void FreeBig(void *p, size_t n) {
 
 void *AllocateBig(size_t n) {
   void *p;
+#ifdef __EMSCRIPTEN__
+  p = Mmap(NULL, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0, "big");
+  return p != MAP_FAILED ? p : 0;
+#endif
   u8 *brk;
   if (!(brk = atomic_load_explicit(&g_allocator.brk, memory_order_relaxed))) {
     // we're going to politely ask the kernel for addresses starting

I built it with emmake make -j8 && emcc -g o//blink/blink.o o//blink/blink.a -lm -pthread -lrt -o o//blink/blink -s INITIAL_MEMORY=1073741824 -s EXIT_RUNTIME=1 -lnodefs.js

@jart
Copy link
Owner

jart commented Jan 4, 2023

Wow. I'm still catching up. Quick question. Did you have any problems with wait4? My build is complaining about that being undefined.

@jart
Copy link
Owner

jart commented Jan 4, 2023

I made a bunch more changes and I'm now blocked on this error.

master jart@turfwar:~/blink$ node o//blink/blink
requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag
(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)
/home/jart/blink/o/blink/blink:163
      throw ex;
      ^

Error: bad memory
    at Object.<anonymous> (/home/jart/blink/o/blink/blink:820:13)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
$?=7 master jart@turfwar:~/blink$ type node
node is hashed (/home/jart/vendor/emsdk/node/14.18.2_64bit/bin/node)

I got a little further in the browser. Not sure what to do next.

image

jart added a commit that referenced this issue Jan 4, 2023
@Vogtinator
Copy link
Contributor

Wow. I'm still catching up. Quick question. Did you have any problems with wait4? My build is complaining about that being undefined.

Yeah, I had to stub that out. FWICT that's a bug in emscripten in some way, as it's available in the system headers and there's also a stub for __syscall_wait4

I made a bunch more changes and I'm now blocked on this error.

Might just be the version of node, it might not support SharedArrayBuffer backed memory for WASM. I'm using v19.3.0 here.

I got a little further in the browser. Not sure what to do next.

That's where the "fun" part starts: Somehow making use of blink.js in the web page. Here's a minimal PoC:

pre.js:

function fileLoad(event, filename) {
    var file = event.target.files[0];
    var reader = new FileReader();
    reader.onloadend = function(event) {
      if(event.target.readyState == FileReader.DONE)
        FS.writeFile(filename, new Uint8Array(event.target.result), {encoding: 'binary'});
    };
    reader.readAsArrayBuffer(file);
}

let fileInput = document.createElement("input");
fileInput.setAttribute("type", "file");
fileInput.onchange = () => { fileLoad(event, "executable"); };
document.body.appendChild(fileInput);

let button = document.createElement("button");
button.innerText = "Start";
button.onclick = () => { Module.callMain(["executable"]); };
document.body.appendChild(button);

Build with emcc o//blink/blink.o o//blink/blink.a -lm -pthread -lrt -o o//blink/blink.html -s INVOKE_RUN=0 -s EXPORTED_RUNTIME_METHODS=callMain -s INITIAL_MEMORY=1073741824 -s EXIT_RUNTIME=1 --emrun --pre-js pre.js

At some point the best option is probably to expose some kind of API to JS, depending on what the actual use cases are.

@unicomp21
Copy link

@Vogtinator @jart you guys are amazing. This is great!

@ghost
Copy link

ghost commented Jan 5, 2023

Well done guys! Very Cool!

@Rucadi
Copy link

Rucadi commented Jan 5, 2023

This is awesome, WILL hack with this :D

@pannous
Copy link

pannous commented Jan 6, 2023

please someone host their compiled blink.wasm !

@ghost
Copy link

ghost commented Jan 6, 2023

please someone host their compiled blink.wasm !

Hmmmmm........

@Vogtinator
Copy link
Contributor

I pushed a github workflow for emscripten HTML builds: https://github.com/Vogtinator/blink/actions/workflows/emscripten.yml

To build for node instead, uncomment the NODEFS mounting in blink/web.h and build with emcc -O2 o//blink/blink.o o//blink/blink.a -lm -pthread -lrt -o o//blink/blink -s INITIAL_MEMORY=1073741824 -s EXIT_RUNTIME=1 -lnodefs.js.

@unicomp21
Copy link

@derekcollison I'm wondering if there could be implications/synergy here for nats? ie tunneling tcp syscalls, etc.?

@derekcollison
Copy link

@derekcollison I'm wondering if there could be implications/synergy here for nats? ie tunneling tcp syscalls, etc.?

How so? Maybe running a nats-server in the browser?

@unicomp21
Copy link

Yes, or the networking layer for many vm's running in browsers?

@trungnt2910
Copy link
Collaborator

please someone host their compiled blink.wasm !

You might want to try this, based on Vogtinator's workflow.

@jart
Copy link
Owner

jart commented Jan 13, 2023

Tweeted https://mobile.twitter.com/JustineTunney/status/1613895681038770182

@trungnt2910 @Vogtinator Would you both be interested in upstreaming your work? I've just added support for GitHub Actions today. We could add a WASM workflow for example.

One thing I'd especially like to see, is some kind of ANSI code support, so we can render the Blinkenlights TUI in the browser so that people don't need to run it locally to use it.

@duaneking
Copy link

I think that's everything I can give you. If you need anything else, just let me know.

@jart
Copy link
Owner

jart commented Jan 14, 2023

Thank you for the readelf output. What will most likely get you working locally right away is building Blink using our musl-cross-make toolchain. You can do that by running:

make -j8 o//x86_64/blink/blink

That will build it exactly the same way it builds on my machine. In this case, at HEAD you should see:

$ o//x86_64/blink/blink duaneking-hello.elf
I2023-01-13T17:04:59.550113:blink/syscall.c:2951:36025 missing syscall 0x111
I2023-01-13T17:04:59.550187:blink/syscall.c:2951:36025 missing syscall 0x14e
Hello World!

As for these:

I2023-01-13T15:41:18.582101:blink/syscall.c:1960:9325 getrandom() flags not supported yet
I2023-01-13T15:41:18.583009:blink/xlat.c:524:9325 atf 4096 not supported yet

I've just pushed a few changes adding support for fstatat(AT_EMPTY_PATH) and I've suppressed the getrandom() flags warning.

@trungnt2910
Copy link
Collaborator

You can #include <emscripten.h> and use EM_ASM(console.trace()); to print a backtrace.

Might it be useful to add this to the existing PrintBacktrace function?

@Vogtinator
Copy link
Contributor

With -sASYNCIFY and some hacks (Vogtinator@12e08b8) I was able to get blinkenlights.html to work somewhat:

https://vogtinator.github.io/blink/blinkenlights.html

Screenshot_20230115_230159

By applying similar hacks to some syscalls (following commits on the master branch), interactive programs such as vi and sh work in blink.html as well to some extent:

https://vogtinator.github.io/blink/blink.html

Screenshot_20230115_231948

Screenshot_20230115_232027

@duaneking
Copy link

Just pulled the most recent changes and updated locally;

I'm loving that the only error output I get is the 0x14e syscall.

I think on linux that might be the compat_sendmmsg syscall?

Either way, Thanks for the fast update.

I reused the old client binaries with the new updated blink build, so nothing in terms of test input has changed outside of the upgrade.

$ o/blink/blink -m ~/a.out
I2023-01-15T14:23:39.729686:blink/syscall.c:3265:28627 missing syscall 0x14e
Hello World!

@jart
Copy link
Owner

jart commented Jan 15, 2023

Wow I'm really impressed to see Vi running in Blink in the browser. I'd love to be able to tweet that, once we get it up on https://jart.github.io/blink/blink.html

Since you're using BusyBox, I'd like to give you something even better. Here's what I call the "Blink Software Pack" which contains Actually Portable Executables from the Cosmopolitan project that are known to work well under Blink (because Blink was designed primarily with Cosmopolitan in mind). The listing is:

  • qjs.com: Fabrice Bellard's QuickJS interpreter
  • sqlite3.com: Standard SQLite command
  • redbean.com: HTTP/HTTPS server with Lua and SQLite baked-in
  • lua.com: Standard Lua interpreter with Redbean's UNIX module
  • printimage.com: Renders GIF/JPG/PNG in terminal as XTERM UNICODE block characters
  • finger.com: Finger protocol client, e.g. ./finger.com [email protected]
  • curl.com: Lightweight replacement for the curl HTTP client command
  • unbourne.com: Fork of the Almquist shell with Bestline, a BSD-licensed GNU Readline replacement
  • uname.com: Invokes the uname(2) system call
  • ttyinfo.com: Interactive troubleshooting tool for ANSI escape codes
  • sysinfo.com: Invokes the sysinfo(2) system call
  • kilo.com: Antirez's famous 1000 LOC text editor
  • hangman.com: The famous text-based game from UNIX Seventh Edition
  • tidy.com: The HTML5 Tidy command
  • ctags.com: Exuberant Ctags
  • make.com: GNU Make w/ Justine's Landlock LSM security extensions
  • python.com: Cosmopolitan's Python 3.6 interpreter in a single file
  • awk.com: The One True Awk
  • sha256sum.com: Replacement for the sha256sum command that goes 2x faster on modern x86
  • mkdeps.com: Fast tool for generating Makefile code based on header file dependencies
  • gzip.com: Compresses files using Zlib's DEFLATE implementation
  • echo.com: Tool that writes a line of text to standard output
  • rm.com: Tool for removing files
  • mkdir.com: Tool for making directories
  • pwd.com: Tool for printing current directory
  • touch.com: Tool for updating timestamps on files
  • cp.com: Tool for copying files
  • dd.com: Tool for transferring blocks of data between files
  • printf.com: Tool that formats a line of text to standard output
  • chmod.com: Tool for changing file permissions

You can download the software pack here:

https://justine.lol/blinkenlights/blink-software-pack.tar.gz

One issue you may encounter with WASM in the browser, is many Cosmopolitan binaries assume they have the ability to open(argv[0]) so the WASM runtime should provide the executable access to read its own content. Otherwise programs like python.com won't be able to read the ZIP files contained within the executable.

@unicomp21
Copy link

Wow, you guys are amazing!

@duaneking
Copy link

I suggest that a sub-project be made to allow such software packs but as a more formal release, perhaps something such as blinkOS? ;)

@unicomp21
Copy link

I can't wait to see what happens w/ blinkOS, should be interesting!

@unicomp21
Copy link

Not sure if it's applicable here, but I know the leaningtech guys are pretty excited about having tail calls for webvm. Looks like they will land soon in both chrome and safari.

WebAssembly/tail-call#15 (comment)

@jart
Copy link
Owner

jart commented Jan 15, 2023

I'm loving that the only error output I get is the 0x14e syscall. I think on linux that might be the compat_sendmmsg syscall?

That's rseq which is a deeply-Linux threading-related system call introduced a couple years ago that every Glibc binary seems to need. It doesn't have a man page aside this https://lwn.net/Articles/774098/ We should examine Glibc to confirm it has a fallback path for us returning ENOSYS, in which case we can suppress the warning.

https://github.com/jart/cosmopolitan/blob/be3e109309d7adc0824b8c22cf4fca3aa6433baa/libc/sysv/syscalls.sh#L370

@duaneking
Copy link

I'm loving that the only error output I get is the 0x14e syscall. I think on linux that might be the compat_sendmmsg syscall?

That's rseq which is a deeply-Linux threading-related system call introduced a couple years ago that every Glibc binary seems to need. It doesn't have a man page aside this https://lwn.net/Articles/774098/ We should examine Glibc to confirm it has a fallback path for us returning ENOSYS, in which case we can suppress the warning.

https://github.com/jart/cosmopolitan/blob/be3e109309d7adc0824b8c22cf4fca3aa6433baa/libc/sysv/syscalls.sh#L370

Yeah I was thinking an older version; https://thevivekpandey.github.io/posts/2017-09-25-linux-system-calls.html

Good catch.

@duaneking
Copy link

duaneking commented Jan 16, 2023

Linux rseq link for Reference: https://github.com/torvalds/linux/blob/master/kernel/rseq.c

I'm idling through code to see what I can find.

So it seems https://www.gnu.org/software/libc/manual/html_node/Restartable-Sequences.html confirms "The GNU C Library sets the cpu_id field to RSEQ_CPU_ID_REGISTRATION_FAILED if registration failed or was explicitly disabled." so I'm looking and https://github.com/torvalds/linux/blob/master/include/uapi/linux/rseq.h says thats defaulted to -2 currently.

This looks interesting:

https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=e3e589829d16af9f7e73c7b70f74f3c5d5003e45

@duaneking
Copy link

duaneking commented Jan 16, 2023

For future reference, a rseq search of the glibc code: https://sourceware.org/git/?p=glibc.git&a=search&h=HEAD&st=commit&s=rseq

@duaneking
Copy link

duaneking commented Jan 16, 2023

If its required is set by a value in the code as its checking ATTR_FLAG_DO_RSEQ, but of its needed and then doesn't init correctly, glibc calls __libc_fatal ,

https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_create.c;hb=569cfcc6bf35c28112ca8d7112e9eb4a22bed5b8#l376

@unicomp21
Copy link

"if" we'll soon have tail calls, which means emscripten will then support co_await and co_yield? Along with the compiler level optimizations they both provide? Does the need for emscripten "asyncify" go away?

#8 (comment)

@unicomp21
Copy link

actually, maybe only co_await requires tail calls? and co_yield already works? @tlively

@Niek
Copy link

Niek commented Jan 16, 2023

Running busybox and vim is very impressive, a minimal Alpine would be even cooler (similar to https://bellard.org/jslinux/ / TinyEMU). Or is that out of scope of this project?

@unicomp21
Copy link

There are images here too ...
https://github.com/copy/v86

@beriberikix
Copy link

Wow I'm really impressed to see Vi running in Blink in the browser. I'd love to be able to tweet that, once we get it up on https://jart.github.io/blink/blink.html

Since you're using BusyBox, I'd like to give you something even better. Here's what I call the "Blink Software Pack" which contains Actually Portable Executables from the Cosmopolitan project that are known to work well under Blink (because Blink was designed primarily with Cosmopolitan in mind). The listing is:

  • qjs.com: Fabrice Bellard's QuickJS interpreter
  • sqlite3.com: Standard SQLite command
  • redbean.com: HTTP/HTTPS server with Lua and SQLite baked-in
  • lua.com: Standard Lua interpreter with Redbean's UNIX module
  • printimage.com: Renders GIF/JPG/PNG in terminal as XTERM UNICODE block characters
  • finger.com: Finger protocol client, e.g. ./finger.com [email protected]
  • curl.com: Lightweight replacement for the curl HTTP client command
  • unbourne.com: Fork of the Almquist shell with Bestline, a BSD-licensed GNU Readline replacement
  • uname.com: Invokes the uname(2) system call
  • ttyinfo.com: Interactive troubleshooting tool for ANSI escape codes
  • sysinfo.com: Invokes the sysinfo(2) system call
  • kilo.com: Antirez's famous 1000 LOC text editor
  • hangman.com: The famous text-based game from UNIX Seventh Edition
  • tidy.com: The HTML5 Tidy command
  • ctags.com: Exuberant Ctags
  • make.com: GNU Make w/ Justine's Landlock LSM security extensions
  • python.com: Cosmopolitan's Python 3.6 interpreter in a single file
  • awk.com: The One True Awk
  • sha256sum.com: Replacement for the sha256sum command that goes 2x faster on modern x86
  • mkdeps.com: Fast tool for generating Makefile code based on header file dependencies
  • gzip.com: Compresses files using Zlib's DEFLATE implementation
  • echo.com: Tool that writes a line of text to standard output
  • rm.com: Tool for removing files
  • mkdir.com: Tool for making directories
  • pwd.com: Tool for printing current directory
  • touch.com: Tool for updating timestamps on files
  • cp.com: Tool for copying files
  • dd.com: Tool for transferring blocks of data between files
  • printf.com: Tool that formats a line of text to standard output
  • chmod.com: Tool for changing file permissions

You can download the software pack here:

https://justine.lol/blinkenlights/blink-software-pack.tar.gz

One issue you may encounter with WASM in the browser, is many Cosmopolitan binaries assume they have the ability to open(argv[0]) so the WASM runtime should provide the executable access to read its own content. Otherwise programs like python.com won't be able to read the ZIP files contained within the executable.

Curious if anyone has tried these lately. They all are erroring for me, albeit is slightly different ways.

@trungnt2910
Copy link
Collaborator

Due to certain bugs in the CI process, the WASM preview has not been updated for a long time. You might have better luck trying a local build.

@RNRetailer
Copy link

Hi.

I'm trying to run a Linux binary in the browser.

It's written in Golang.

I can't compile for WASM because it has so many Linux dependencies.

I tried to run it here: https://trungnt2910.com/blink/blink.html

However, I got this error:
"Uncaught RuntimeError: Aborted(Cannot enlarge memory arrays to size 1073811456 bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value 1073741824, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0)"

Does this mean that emscripten must be compiled with -sALLOW_MEMORY_GROWTH?

I can pay if someone wants to help.

Thanks

@jart
Copy link
Owner

jart commented Apr 23, 2024

@RNRetailer If you can help fund further development on WASM integration, then please contact me by email.

@trungnt2910
Copy link
Collaborator

trungnt2910 commented Apr 23, 2024

I can pay if someone wants to help.

I'm one of the authors of the WASM port and the owner of the page you mentioned. The page on my fork is a bit outdated compared to the official one, which itself has also been abandoned for quite a long time.

If you need my help updating the WASM version and fixing specific bugs, please reach out to me [at] trungnt2910.com or through my Discord.

@Vogtinator
Copy link
Contributor

Does this mean that emscripten must be compiled with -sALLOW_MEMORY_GROWTH?

No, just build blink with one of the options.

However:

I can't compile for WASM because it has so many Linux dependencies.

Depending on the dependencies you might have to spend more time getting those to work with blink wasm. With the additional layer in between you'll also significantly lose performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser Web browser, JavaScript, and WASM integration enhancement New feature or request
Projects
None yet
Development

No branches or pull requests