Skip to content

Commit

Permalink
Support building some dependencies with Emscripten (#47680)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Huffman authored Feb 10, 2023
1 parent f7875a2 commit a4a148b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion deps/dsfmt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ ifneq ($(USE_BINARYBUILDER_DSFMT),1)

DSFMT_CFLAGS := $(CFLAGS) -DNDEBUG -DDSFMT_MEXP=19937 $(fPIC) -DDSFMT_DO_NOT_USE_OLD_NAMES -DDSFMT_SHLIB $(SANITIZE_OPTS)
DSFMT_CFLAGS += -O3 -finline-functions -fomit-frame-pointer -fno-strict-aliasing \
--param max-inline-insns-single=1800 -Wall -std=c99 -shared
-Wall -std=c99 -shared
ifeq ($(ARCH), x86_64)
DSFMT_CFLAGS += -msse2 -DHAVE_SSE2
endif
ifneq ($(OS), emscripten)
DSFMT_CFLAGS += --param max-inline-insns-single=1800
endif

$(SRCCACHE)/dsfmt-$(DSFMT_VER).tar.gz: | $(SRCCACHE)
$(JLDOWNLOAD) $@ https://github.com/MersenneTwister-Lab/dSFMT/archive/v$(DSFMT_VER).tar.gz
Expand Down
3 changes: 3 additions & 0 deletions deps/gmp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ ifeq ($(BUILD_OS),WINNT)
GMP_CONFIGURE_OPTS += --srcdir="$(subst \,/,$(call mingw_to_dos,$(SRCCACHE)/gmp-$(GMP_VER)))"
endif

ifeq ($(OS),emscripten)
GMP_CONFIGURE_OPTS += CFLAGS="-fPIC"
endif

$(SRCCACHE)/gmp-$(GMP_VER).tar.bz2: | $(SRCCACHE)
$(JLDOWNLOAD) $@ https://gmplib.org/download/gmp/$(notdir $@)
Expand Down
16 changes: 16 additions & 0 deletions deps/libuv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ LIBUV_BUILDDIR := $(BUILDDIR)/$(LIBUV_SRC_DIR)
ifneq ($(CLDFLAGS)$(SANITIZE_LDFLAGS),)
$(LIBUV_BUILDDIR)/build-configured: LDFLAGS:=$(LDFLAGS) $(CLDFLAGS) $(SANITIZE_LDFLAGS)
endif

ifeq ($(OS), emscripten)
$(LIBUV_BUILDDIR)/build-configured: $(SRCCACHE)/$(LIBUV_SRC_DIR)/source-extracted
mkdir -p $(dir $@)
cd $(dir $@) && cmake -E env \
CMAKE_C_FLAGS="-pthread" \
CMAKE_SHARED_LINKER_FLAGS="-sTOTAL_MEMORY=65536000 -pthread" \
CMAKE_EXE_LINKER_FLAGS="-sTOTAL_MEMORY=65536000 -pthread" \
emcmake cmake $(dir $<) $(CMAKE_COMMON) -DBUILD_TESTING=OFF
echo 1 > $@

$(LIBUV_BUILDDIR)/build-compiled: $(LIBUV_BUILDDIR)/build-configured
emmake $(MAKE) -C $(dir $<) $(UV_MFLAGS)
echo 1 > $@
else
$(LIBUV_BUILDDIR)/build-configured: $(SRCCACHE)/$(LIBUV_SRC_DIR)/source-extracted
touch -c $(SRCCACHE)/$(LIBUV_SRC_DIR)/aclocal.m4 # touch a few files to prevent autogen from getting called
touch -c $(SRCCACHE)/$(LIBUV_SRC_DIR)/Makefile.in
Expand All @@ -30,6 +45,7 @@ $(LIBUV_BUILDDIR)/build-configured: $(SRCCACHE)/$(LIBUV_SRC_DIR)/source-extracte
$(LIBUV_BUILDDIR)/build-compiled: $(LIBUV_BUILDDIR)/build-configured
$(MAKE) -C $(dir $<) $(UV_MFLAGS)
echo 1 > $@
endif

$(LIBUV_BUILDDIR)/build-checked: $(LIBUV_BUILDDIR)/build-compiled
ifeq ($(OS),$(BUILD_OS))
Expand Down
3 changes: 3 additions & 0 deletions deps/mpfr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ifeq ($(SANITIZE),1)
MPFR_CONFIGURE_OPTS += --host=none-unknown-linux
endif

ifeq ($(OS),emscripten)
MPFR_CONFIGURE_OPTS += CFLAGS="-fPIC"
endif

$(SRCCACHE)/mpfr-$(MPFR_VER).tar.bz2: | $(SRCCACHE)
$(JLDOWNLOAD) $@ https://www.mpfr.org/mpfr-$(MPFR_VER)/$(notdir $@)
Expand Down
9 changes: 8 additions & 1 deletion deps/pcre.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ ifneq ($(USE_BINARYBUILDER_PCRE),1)
PCRE_CFLAGS := -O3
PCRE_LDFLAGS := $(RPATH_ESCAPED_ORIGIN)

ifeq ($(OS),emscripten)
PCRE_CFLAGS += -fPIC
PCRE_JIT = --disable-jit
else
PCRE_JIT = --enable-jit
endif

$(SRCCACHE)/pcre2-$(PCRE_VER).tar.bz2: | $(SRCCACHE)
$(JLDOWNLOAD) $@ https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$(PCRE_VER)/pcre2-$(PCRE_VER).tar.bz2

Expand All @@ -20,7 +27,7 @@ checksum-pcre: $(SRCCACHE)/pcre2-$(PCRE_VER).tar.bz2
$(BUILDDIR)/pcre2-$(PCRE_VER)/build-configured: $(SRCCACHE)/pcre2-$(PCRE_VER)/source-extracted
mkdir -p $(dir $@)
cd $(dir $@) && \
$(dir $<)/configure $(CONFIGURE_COMMON) --enable-jit --includedir=$(build_includedir) CFLAGS="$(CFLAGS) $(PCRE_CFLAGS) -g -O0" LDFLAGS="$(LDFLAGS) $(PCRE_LDFLAGS)"
$(dir $<)/configure $(CONFIGURE_COMMON) $(PCRE_JIT) --includedir=$(build_includedir) CFLAGS="$(CFLAGS) $(PCRE_CFLAGS) -g -O0" LDFLAGS="$(LDFLAGS) $(PCRE_LDFLAGS)"
echo 1 > $@

$(BUILDDIR)/pcre2-$(PCRE_VER)/build-compiled: $(BUILDDIR)/pcre2-$(PCRE_VER)/build-configured
Expand Down

0 comments on commit a4a148b

Please sign in to comment.