Skip to content

Compiling ASDF systems with Emscripten

I am trying to follow the guide here: https://gitlab.com/embeddable-common-lisp/ecl/tree/develop/examples/asdf_with_dependence

I am trying to compile :iterate with ECL to target WASM, but it doesn't seem to be covered by the guide.

I know how to compile a singular .lisp file by specifying the compilers to use emcc, but the same does not seem to work with asdf:make-system:

(load "~/quicklisp/setup.lisp")

(ext:install-c-compiler)

(setf c::*cc* "emcc")
(setf c::*ar* "emar")
(setf c::*ranlib* "emranlib")
(setf c::*ecl-include-directory* (namestring (truename "../ecl-emscripten-host/include")))
(setf c::*ecl-library-directory* (namestring (truename "../ecl-emscripten-host/lib")))

(asdf:make-build :iterate
                 :type :static-library
                 :move-here #P"./"
                 :init-name "init_iterate")

(quit)
[daedsidog@DESKTOP-DABGRDU ecl-js-layer]$ ../ecl-emscripten-host/bin/ecl --load build-with-libs.lisp 
;;; Loading #P"/home/daedsidog/test/ecl/ecl-js-layer/build-with-libs.lisp"
;;; Loading #P"/home/daedsidog/quicklisp/setup.lisp"
;;; Loading #P"/home/daedsidog/test/ecl/ecl-emscripten-host/lib/ecl-23.9.9/asdf.fas"
[daedsidog@DESKTOP-DABGRDU ecl-js-layer]$

Builds an iterate.a file, however:

emcc wecl.c iterate.a ../ecl-emscripten/lib/libecl.a ../ecl-emscripten/lib/libeclgc.a ../ecl-emscripten/lib/libeclgmp.a -I../ecl-emscripten/include -o wecl.js -sSTACK_SIZE=1048576 -sEXPORTED_FUNCTIONS=_wecl_eval_cl -sEXPORTED_RUNTIME_METHODS=ccall,cwrap -g0
wasm-ld: warning: iterate.a: archive member 'package.o' is neither Wasm object file nor LLVM bitcode
wasm-ld: warning: iterate.a: archive member 'iterate.o' is neither Wasm object file nor LLVM bitcode
wasm-ld: error: iterate.a(eclinitN5cltL.o): undefined symbol: _ecl1nYn7CL4_B5Q0s071
wasm-ld: error: iterate.a(eclinitN5cltL.o): undefined symbol: _eclnhUZmWM4_qFQ0s071

Seems like it ignores the compiler used? Trying other options, I did notice that it uses gcc for some reason:

[daedsidog@DESKTOP-DABGRDU ecl-js-layer]$ ../ecl-emscripten-host/bin/ecl --load build-with-libs.lisp 
;;; Loading #P"/home/daedsidog/test/ecl/ecl-js-layer/build-with-libs.lisp"
;;; Loading #P"/home/daedsidog/quicklisp/setup.lisp"
;;; Loading #P"/home/daedsidog/test/ecl/ecl-emscripten-host/lib/ecl-23.9.9/asdf.fas"
An error occurred during initialization:
Error code 1 when executing
(EXT:RUN-PROGRAM "gcc" ("-o"
                        "/home/daedsidog/.cache/common-lisp/ecl-23.9.9-758ebc62-linux-x64/home/daedsidog/quicklisp/dists/quicklisp/software/iterate-release-b0f9a9c6-git/iterate--all-systems.so"
                        "-L/home/daedsidog/test/ecl/ecl-emscripten-host/lib/"
                        "-shared" "-m32" "-g" "-O2" "-m32" "-g" "-O2"
                        "/tmp/eclinitr07U8N.o"
                        "/home/daedsidog/.cache/common-lisp/ecl-23.9.9-758ebc62-linux-x64/home/daedsidog/quicklisp/dists/quicklisp/software/iterate-release-b0f9a9c6-git/package.o"
                        "/home/daedsidog/.cache/common-lisp/ecl-23.9.9-758ebc62-linux-x64/home/daedsidog/quicklisp/dists/quicklisp/software/iterate-release-b0f9a9c6-git/iterate.o"
                        "-Wl,--rpath,/home/daedsidog/test/ecl/ecl-emscripten-host/lib/"
                        "-lecl" "-ldl" "-lm")):
/tmp/eclinitr07U8N.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status.

Am I doing something wrong? I know of no other way to add libraries to ECL. Obviously this process works normally if I don't target WASM, but the alternative right now seems to me that I would need to manually compile every library source file individually to get proper .wasm files.

Edited by daedsidog