Extending WebAssembly ECL to have emulated sockets/threads
I am working with WebAssembbly and ECL. Right now I have a utility which compiles any arbitrary ASDF system to WASM, which I am then able to link to together with libecl.a
to use them on the web, provided that the underlying functionality of the systems do not rely on features outside the support of the browser.
I am interested to cross-compile swank-protocol
so that I may work remotely with the WASM ECL from the comfort of my SLIME. If I ignore builtin systems in the dependency tree during the building process, sb-bsd-sockets
gets ignored, and the static library swank-protocol.a
is built.
I then have the auto-generated C shim file, which looks like this:
/* Autogenerated on 2024-05-03T17:09:18.224114+03:00. */
#include <emscripten.h>
#include <ecl/ecl.h>
static int ecl_initialized = 0;
extern void init_system_splitsequence(cl_object);
extern void init_system_usocket(cl_object);
extern void init_system_swank(cl_object);
extern void init_system_trivialfeatures(cl_object);
extern void init_system_alexandria(cl_object);
extern void init_system_babel(cl_object);
extern void init_system_swankprotocol(cl_object);
void cleanup(){
if (ecl_initialized){
ecl_initialized = 0;
cl_shutdown();
}
}
cl_object wecl_eval_js(cl_object script){
emscripten_run_script((const char*)script->base_string.self);
return Cnil;
}
void initialize_ecl(int argc, char** argv){
cl_boot(argc, argv);
ecl_init_module(NULL, init_system_splitsequence);
ecl_init_module(NULL, init_system_usocket);
ecl_init_module(NULL, init_system_swank);
ecl_init_module(NULL, init_system_trivialfeatures);
ecl_init_module(NULL, init_system_alexandria);
ecl_init_module(NULL, init_system_babel);
ecl_init_module(NULL, init_system_swankprotocol);
ecl_initialized = 1;
cl_object wecl_eval_js_symbol = c_string_to_object("%WECL-EVAL-JS");
ecl_def_c_function(wecl_eval_js_symbol, (cl_objectfn_fixed)wecl_eval_js, 1);
atexit(cleanup);
}
void wecl_eval_cl(const char* form){
if (!ecl_initialized){
initialize_ecl(0, (char**)&"");
}
cl_eval(c_string_to_object(form));
}
Trying to initialize the systems in the browser, however, results in:
Which is expected.
I don't suppose there is any point in trying to add sb-bsd-sockets
to the build process, as its a specific implementation of the host ECL. I did try it, though, and got some errors about libsocket
.
My question is this: I am interested to implement sockets + threads using Emscripten. Emscripten supports the emulation of posix threads and sockets, so using those directly from C will not require any Javascript from my part. What is the simplest way to do this? I would much prefer to have the ability to extend ECL, instead of rewriting its source files & recompiling.