a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

Compiling WebAssembly Build

Open woncheol-kim opened this issue 1 year ago • 2 comments

Hello, although I don't consider myself a developer, I've attempted to compile a WebAssembly build from various source codes, with the aid of Copilot AI.

My question pertains to the possibility of compiling a source code within a-Shell. Specifically, I'm curious about the process of installing wasi-sdk in a-Shell. Despite my attempts to cross-compile in both Linux and macOS environments, I've encountered consistent failures.

Initially, I endeavored to compile from the rclone git source in a Linux terminal. However, upon executing it in a-Shell, I was met with an empty shell devoid of any feedback. Similarly, my subsequent attempt from the macOS terminal yielded identical results.

Subsequently, I tried compiling from the nnn git source in both Linux and macOS terminals, encountering error messages during the build process such as:

/Users/woncheol/Documents/nnn/src/nnn.c:58:10: fatal error: 'sys/sysmacros.h' file not found 58 | #include <sys/sysmacros.h>

/Users/woncheol/Documents/nnn/src/nnn.c:46:10: fatal error: 'sys/resource.h' file not found 46 | #include <sys/resource.h>

My subsequent attempt involved compiling transmission, yet I encountered an overwhelming number of errors.

woncheol-kim avatar May 08 '24 04:05 woncheol-kim

The wasi-sdk is installed by default in a-Shell. If you type clang file.c, the file will be compiled to WebAssembly, and a.out is executable.

However, webAssembly is still limited; rclone and nnn are using features that are not available in our version of wasi-sdk (starting with setjmp/longjmp). I am in the process of upgrading the wasi-sdk to a more recent version, and porting nnn as a test case.

I would suggest starting with smaller projects to get a better understanding of the issues.

holzschu avatar May 08 '24 10:05 holzschu

Thank you for your explanation. Now I believe I grasp the boundaries of what can and cannot be compiled with the wasi-sdk, and it seems the realm of possibility is considerably narrower than I initially imagined. It's quite remarkable that an official build of yt-dlp, functional within a-Shell, can be achieved despite such rigorous constraints.

Apart from a few packages installable via the pkg command, the only one I've managed to install thus far is tldr, which was installed via pip rather than WebAssembly.

woncheol-kim avatar May 09 '24 01:05 woncheol-kim