From b53da126060cf95c41ea5e49fb966a0dddfa307a Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 1 Apr 2022 20:30:19 +0200 Subject: [PATCH 1/5] make: split global linker and compile flags Future emscripten versions warn if link-only options are set during compilation. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/9b1fc2ebb5857cae8648a11bfe84640dffe291df make: also specify optimisation level for linking With emscripten, LLVM is translated to JS during linking and the optimisation level also has an effect here. This was a regression from 9b1fc2ebb5857cae8648a11bfe84640dffe291df and apart from performance also brings the total size of the distributed files back down to ~7MiB from ~19MiB after the options were split. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/952afbd2f228523fa4c57895b4e7002dfd881be0 --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 281b984b..e21c8fea 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,9 @@ BASE_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) DIST_DIR:=$(BASE_DIR)dist/libraries -GLOBAL_CFLAGS:=-O3 -s ENVIRONMENT=web,webview +GLOBAL_CFLAGS:=-O3 +GLOBAL_LDFLAGS:=-O3 -s ENVIRONMENT=web,webview +export LDFLAGS = $(GLOBAL_LDFLAGS) all: subtitleoctopus @@ -158,7 +160,6 @@ $(DIST_DIR)/lib/libharfbuzz.a: build/lib/freetype/build_hb/dist_hb/lib/libfreety -s NO_EXIT_RUNTIME=1 \ -s MODULARIZE=1 \ " \ - LDFLAGS="" \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ --build=x86_64 \ @@ -292,7 +293,7 @@ src/subtitles-octopus-worker.bc: $(OCTP_DEPS) src/Makefile src/SubtitleOctopus.c # Dist Files EMCC_COMMON_ARGS = \ - $(GLOBAL_CFLAGS) \ + $(GLOBAL_LDFLAGS) \ -s EXPORTED_FUNCTIONS="['_main', '_malloc']" \ -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'getValue', 'FS_createPreloadedFile', 'FS_createPath']" \ -s NO_EXIT_RUNTIME=1 \ From 2294953643a52e1f35258c2f15c495810f47a885 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 1 Apr 2022 20:36:41 +0200 Subject: [PATCH 2/5] make: consolidate link flags All builds but brotli already set NO_EXIT_RUNTIME, and in brotli's case it was probably an oversight for the flag to be missing. All dependencies, but not the final jso linkage also set MODULARIZE, but not -s 'EXPORT_NAME="someting"' as emscripten docs suggest should be done. But since we only use static libs, the final ones are also actually the only linking occuring, so just remove the flag. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/ebcfe368f3c69f020cb75146f6f24fc8318897ca --- Makefile | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Makefile b/Makefile index e21c8fea..5db0671d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ BASE_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) DIST_DIR:=$(BASE_DIR)dist/libraries GLOBAL_CFLAGS:=-O3 -GLOBAL_LDFLAGS:=-O3 -s ENVIRONMENT=web,webview +GLOBAL_LDFLAGS:=-O3 -s ENVIRONMENT=web,webview -s NO_EXIT_RUNTIME=1 export LDFLAGS = $(GLOBAL_LDFLAGS) all: subtitleoctopus @@ -27,9 +27,7 @@ $(DIST_DIR)/lib/libfribidi.a: build/lib/fribidi/configure -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ - -s NO_EXIT_RUNTIME=1 \ -DFRIBIDI_ENTRY=extern \ - -s MODULARIZE=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ @@ -53,8 +51,6 @@ $(DIST_DIR)/lib/libexpat.a: build/lib/expat/configured -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ -DCMAKE_INSTALL_PREFIX=$(DIST_DIR) \ -DEXPAT_BUILD_DOCS=off \ @@ -115,8 +111,6 @@ build/lib/freetype/build_hb/dist_hb/lib/libfreetype.a: $(DIST_DIR)/lib/libbrotli -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ --prefix="$$(pwd)/dist_hb" \ --host=x86-none-linux \ @@ -149,16 +143,12 @@ $(DIST_DIR)/lib/libharfbuzz.a: build/lib/freetype/build_hb/dist_hb/lib/libfreety $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ -DHB_NO_MT \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ CXXFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ -DHB_NO_MT \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ @@ -185,8 +175,6 @@ $(DIST_DIR)/lib/libfreetype.a: $(DIST_DIR)/lib/libharfbuzz.a $(DIST_DIR)/lib/lib -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ -s NO_FILESYSTEM=1 \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ @@ -218,8 +206,6 @@ $(DIST_DIR)/lib/libfontconfig.a: $(DIST_DIR)/lib/libharfbuzz.a $(DIST_DIR)/lib/l -s USE_PTHREADS=0 \ -DEMSCRIPTEN \ $(GLOBAL_CFLAGS) \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ @@ -248,8 +234,6 @@ $(DIST_DIR)/lib/libass.a: $(DIST_DIR)/lib/libfontconfig.a $(DIST_DIR)/lib/libhar CFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_EXIT_RUNTIME=1 \ - -s MODULARIZE=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ @@ -296,7 +280,6 @@ EMCC_COMMON_ARGS = \ $(GLOBAL_LDFLAGS) \ -s EXPORTED_FUNCTIONS="['_main', '_malloc']" \ -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'getValue', 'FS_createPreloadedFile', 'FS_createPath']" \ - -s NO_EXIT_RUNTIME=1 \ --use-preload-plugins \ --preload-file assets/default.woff2 \ --preload-file assets/fonts.conf \ From baa5e18939bb901459b7544a57d440c3db827ac4 Mon Sep 17 00:00:00 2001 From: Oneric Date: Sat, 2 Apr 2022 00:16:12 +0200 Subject: [PATCH 3/5] make: remove filesystem flags from dependency builds It's a link-only setting and since we only build static libs only relevant in the final linking step. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/8d41bd1ae4467626df16505d46b744c957969f3f --- Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Makefile b/Makefile index 5db0671d..bc4b6dd9 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ $(DIST_DIR)/lib/libfribidi.a: build/lib/fribidi/configure CFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ -DFRIBIDI_ENTRY=extern \ " \ --prefix="$(DIST_DIR)" \ @@ -50,7 +49,6 @@ $(DIST_DIR)/lib/libexpat.a: build/lib/expat/configured -DCMAKE_C_FLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ " \ -DCMAKE_INSTALL_PREFIX=$(DIST_DIR) \ -DEXPAT_BUILD_DOCS=off \ @@ -110,7 +108,6 @@ build/lib/freetype/build_hb/dist_hb/lib/libfreetype.a: $(DIST_DIR)/lib/libbrotli CFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ " \ --prefix="$$(pwd)/dist_hb" \ --host=x86-none-linux \ @@ -141,13 +138,11 @@ $(DIST_DIR)/lib/libharfbuzz.a: build/lib/freetype/build_hb/dist_hb/lib/libfreety CFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ -DHB_NO_MT \ " \ CXXFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ -DHB_NO_MT \ " \ --prefix="$(DIST_DIR)" \ @@ -174,7 +169,6 @@ $(DIST_DIR)/lib/libfreetype.a: $(DIST_DIR)/lib/libharfbuzz.a $(DIST_DIR)/lib/lib CFLAGS=" \ -s USE_PTHREADS=0 \ $(GLOBAL_CFLAGS) \ - -s NO_FILESYSTEM=1 \ " \ --prefix="$(DIST_DIR)" \ --host=x86-none-linux \ From 4563c4e1a3dd967dc76ce9de119e4584f224f414 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 1 Apr 2022 20:38:19 +0200 Subject: [PATCH 4/5] make: explicitly target worker environment This is no longer implied in future emscripten versions. Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/6bee3c84d2b6969ff6278c5511c8f8e634322349 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bc4b6dd9..97df4708 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ BASE_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) DIST_DIR:=$(BASE_DIR)dist/libraries GLOBAL_CFLAGS:=-O3 -GLOBAL_LDFLAGS:=-O3 -s ENVIRONMENT=web,webview -s NO_EXIT_RUNTIME=1 +GLOBAL_LDFLAGS:=-O3 -s ENVIRONMENT=web,webview,worker -s NO_EXIT_RUNTIME=1 export LDFLAGS = $(GLOBAL_LDFLAGS) all: subtitleoctopus From f9e43158c42bcff46e8fa70903c2c347b22a14e6 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 1 Apr 2022 20:42:22 +0200 Subject: [PATCH 5/5] Update emscripten 2.0.34 Freetype upstream made changes to remove the need for our fcstat patch, but we actually also need to update emscripten as linking to fstatfs is bugged in our currently used version and will lead to runtime errors. - Since emscripten 2.0.26 unresolved symbols cause errors at link time instead of only at runtime. - The following commit contained in 2.0.27 fixed fstatfs linking: https://github.com/emscripten-core/emscripten/commit/2126d3c1a64c9db2ab390b2c09fd91ef41d05b24 Cherry-picked from: https://github.com/libass/JavascriptSubtitlesOctopus/commit/f92d7cebca558cb0a99688cf1e5e78a80c80d3a2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fd01e480..4f9592d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM emscripten/emsdk:2.0.20 +FROM docker.io/emscripten/emsdk:2.0.34 RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \