Merge branch 'emscripten-shared-library-build' into 'develop'

Improvements for emscripten target

See merge request embeddable-common-lisp/ecl!321
This commit is contained in:
Daniel Kochmański 2024-02-25 10:19:15 +00:00 committed by Marius Gerbershagen
commit 1621f57cd9
9 changed files with 37 additions and 18 deletions

14
INSTALL
View file

@ -127,9 +127,6 @@ Emscripten target is a little fickle so keep in mind that:
- to build emscripten you need to use their SDK that provides the toolchain, and
set the environment variable EMSDK_PATH
- the optimization level -O0 is forced because otherwsise binaryen miscompiles
ECL
1. Build the host ECL
#+begin_src shell-script
@ -166,21 +163,20 @@ After that activate the toolchain and configure build flags:
--build=x86_64-pc-linux-gnu \
--with-cross-config=`pwd`/src/util/wasm32-unknown-emscripten.cross_config \
--prefix=`pwd`/ecl-emscripten \
--disable-shared \
--with-tcp=no \
--with-cmp=no
emmake make && emmake make install
# some files need to be copied manually
cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/bin
cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/
#+end_src
4. ECL may be hosted on a web page. Assuming that you have quicklisp installed:
#+begin_src shell-script
export WEBSERVER=`pwd`/src/util/webserver.lisp
pushd ecl-emscripten/bin
pushd ecl-emscripten/
lisp --load $WEBSERVER
# After the server is loaded run:
# firefox localhost:8888/ecl.html
@ -190,12 +186,12 @@ After that activate the toolchain and configure build flags:
If the output does not show on the webpage then open the javascript console.
This is a default html website produced by emscripten.
5. Build an external program linked against libecl.a
5. Build an external program linked against libecl.so
The default stack size proposed by emscripten is 64KB. This is too little for
ECL, so when you build a program that is linked against libecl.a, then it is
ECL, so when you build a program that is linked against libecl.so, then it is
imoprtant to specify a different size. For example:
#+begin_src shell-script
emcc program.c -sSTACK_SIZE=1048576 lib/*.a -I./include -o program.o
emcc program.c -sSTACK_SIZE=1048576 libecl.so -I./ -o program.o
#+end_src

View file

@ -77,6 +77,8 @@ INSTALL_TARGET = @INSTALL_TARGET@
install: build/Makefile
cd build; $(MAKE) $(INSTALL_TARGET)
flatinstall: build/Makefile
cd build; $(MAKE) flatinstall
uninstall:
cd build; $(MAKE) uninstall

View file

@ -274,6 +274,7 @@ compile.lsp: bare.lsp $(srcdir)/compile.lsp.in Makefile
"@LDFLAGS@" "$(LDFLAGS)" \
"@SHARED_LDFLAGS@" "$(SHARED_LDFLAGS)" \
"@BUNDLE_LDFLAGS@" "$(SHARED_LDFLAGS)" \
"@PROGRAM_LDFLAGS@" "" \
"@CLIBS@" "$(CLIBS)" \
"@STATICLIBS@" "$(STATICLIBS)" \
"@LIBS@" "$(LIBS)" \
@ -316,6 +317,7 @@ cmp/cmpdefs.lsp: $(srcdir)/cmp/cmpdefs.lsp Makefile
"@LDFLAGS@" "$(LDFLAGS)" \
"@SHARED_LDFLAGS@" "$(SHARED_LDFLAGS)" \
"@BUNDLE_LDFLAGS@" "$(SHARED_LDFLAGS)" \
"@PROGRAM_LDFLAGS@" "" \
"@CLIBS@" "$(CLIBS)" \
"@STATICLIBS@" "$(STATICLIBS)" \
"@OBJEXT@" "obj" \

5
src/aclocal.m4 vendored
View file

@ -533,6 +533,11 @@ case "${host}" in
enable_threads='no'
enable_libffi='no'
enable_gmp='portable'
with_c_gmp=yes
SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}"
BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}"
PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}"
INSTALL_TARGET='flatinstall'
;;
esac

View file

@ -103,7 +103,9 @@ the environment variable TMPDIR to a different value." template))
#+msvc
(defun linker-cc (o-pathname object-files &key
(type :program)
(ld-flags (split-program-options *ld-flags*))
(ld-flags (split-program-options (if (eq type :program)
*ld-program-flags*
*ld-flags*)))
(ld-libs (split-program-options *ld-libs*)))
(safe-run-program
*ld*
@ -126,7 +128,9 @@ the environment variable TMPDIR to a different value." template))
#-msvc
(defun linker-cc (o-pathname object-files &key
(type :program)
(ld-flags (split-program-options *ld-flags*))
(ld-flags (split-program-options (if (eq type :program)
*ld-program-flags*
*ld-flags*)))
(ld-libs (split-program-options *ld-libs*)))
(declare (ignore type))
(safe-run-program

View file

@ -57,6 +57,7 @@ coprocessor).")
(defvar *ld-shared-flags* "@SHARED_LDFLAGS@ @LDFLAGS@")
#+dlopen
(defvar *ld-bundle-flags* "@BUNDLE_LDFLAGS@ @LDFLAGS@")
(defvar *ld-program-flags* "@PROGRAM_LDFLAGS@ @LDFLAGS@")
(defvar +shared-library-prefix+ "@SHAREDPREFIX@")
(defvar +shared-library-extension+ "@SHAREDEXT@")

View file

@ -95,7 +95,9 @@
c::*ld-shared-flags*
"@SHARED_LDFLAGS@ @LDFLAGS@"
c::*ld-bundle-flags*
"@BUNDLE_LDFLAGS@ @LDFLAGS@")
"@BUNDLE_LDFLAGS@ @LDFLAGS@"
c::*ld-program-flags*
"@PROGRAM_LDFLAGS@ @LDFLAGS@")
;;; FIXME: The nonstop platform does not support soname
#+(and :wants-dlopen nonstop)
(setf c::*ld-libs*
@ -182,7 +184,7 @@
(push "@LIBPREFIX@eclgmp.@LIBEXT@" extra-args)))
(print extra-args)
(c::shared-cc (compile-file-pathname "ecl" :type :dll)
(list* "c/main.@OBJEXT@"
(list* #-emscripten "c/main.@OBJEXT@"
"c/all_symbols2.@OBJEXT@"
"@LIBPREFIX@lsp.@LIBEXT@"
"@LIBPREFIX@eclmin.@LIBEXT@"

16
src/configure vendored
View file

@ -739,6 +739,7 @@ LIBRARIES
SUBDIRS
TARGETS
EXTRA_OBJS
PROGRAM_LDFLAGS
BUNDLE_LDFLAGS
SHARED_LDFLAGS
CORE_LIBS
@ -3692,7 +3693,7 @@ test -z "${ecldir}" && ecldir="${libdir}/ecl-${PACKAGE_VERSION}"
boehm_configure_flags=""
TARGETS='bin/ecl$(EXE)'
TARGETS='bin/ecl$(EXE)'
SUBDIRS='c doc'
LSP_FEATURES='*features*'
@ -5052,11 +5053,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5
printf %s "checking for $CXX option to enable C++11 features... " >&6; }
if test ${ac_cv_prog_cxx_11+y}
if test ${ac_cv_prog_cxx_cxx11+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_11=no
ac_cv_prog_cxx_cxx11=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@ -5098,11 +5099,11 @@ if test x$ac_prog_cxx_stdcxx = xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5
printf %s "checking for $CXX option to enable C++98 features... " >&6; }
if test ${ac_cv_prog_cxx_98+y}
if test ${ac_cv_prog_cxx_cxx98+y}
then :
printf %s "(cached) " >&6
else $as_nop
ac_cv_prog_cxx_98=no
ac_cv_prog_cxx_cxx98=no
ac_save_CXX=$CXX
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@ -6233,6 +6234,11 @@ LSP_FEATURES="(cons :android ${LSP_FEATURES})"
enable_threads='no'
enable_libffi='no'
enable_gmp='portable'
with_c_gmp=yes
SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}"
BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}"
PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}"
INSTALL_TARGET='flatinstall'
;;
esac

View file

@ -317,6 +317,7 @@ AC_SUBST(CORE_LIBS, []) dnl Locally compiled libs to link into
dnl ecl/ecl_min/libecl.so and nowhere else.
AC_SUBST(SHARED_LDFLAGS) dnl Flags for shared libraries linker
AC_SUBST(BUNDLE_LDFLAGS) dnl Flags for FASL files linker
AC_SUBST(PROGRAM_LDFLAGS) dnl Flags for executable program linker
AC_SUBST(EXTRA_OBJS) dnl Extra *.o files to be compiled into libecl.a
AC_SUBST(TARGETS, ['bin/ecl$(EXE)'])dnl Versions of ECL to be built
AC_SUBST(SUBDIRS, ['c doc']) dnl Subdirectories that make should process