View Issue Details

IDProjectCategoryView StatusLast Update
0001029OpenMPT[All Projects] libopenmptpublic2018-08-26 07:38
ReportermanxAssigned Tomanx 
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version 
Target Versionlibopenmpt 0.4 (goals)Fixed in Versionlibopenmpt 0.4 (goals) 
Summary0001029: WebAssembly support
Description

libopenmpt needs support for compiling to WebAssembly.

TagsNo tags attached.
Has the bug occurred in previous versions?
Tested code revision (in case you know it)

Activities

manx

manx

2017-10-28 09:48

administrator   ~0003317

r9155 adds basic build system support ┬┤make CONFIG=emscripten EMSCRIPTEN_TARGET=wasm┬┤.
No test suite support yet.

manx

manx

2018-04-09 12:42

administrator   ~0003493

r10058 can now run parts of the test suite via emrun.

manx

manx

2018-07-26 15:09

administrator  

emscripten-wasm-v1.patch (9,350 bytes)
Index: README.md
===================================================================
--- README.md	(revision 10620)
+++ README.md	(working copy)
@@ -179,8 +179,8 @@
 
      -  emscripten (on Unix-like systems):
 
-        libopenmpt has been tested and verified to work with emscripten 1.31 or
-        later (earlier versions might or might not work).
+        libopenmpt has been tested and verified to work with emscripten 1.38.1
+        or later (earlier versions might or might not work).
 
         Run:
 
@@ -187,7 +187,7 @@
             make CONFIG=emscripten
 
         Running the test suite on the command line is also supported by using
-        node.js. Version 0.10.25 or greater has been tested. Earlier versions
+        node.js. Version 8.9.1 or greater has been tested. Earlier versions
         might or might not work. Depending on how your distribution calls the
         `node.js` binary, you might have to edit
         `build/make/config-emscripten.mk`.
Index: build/make/config-emscripten.mk
===================================================================
--- build/make/config-emscripten.mk	(revision 10620)
+++ build/make/config-emscripten.mk	(working copy)
@@ -4,7 +4,7 @@
 LD  = em++
 AR  = emar
 
-EMSCRIPTEN_TARGET?=asmjs
+EMSCRIPTEN_TARGET?=default
 
 ifneq ($(STDCXX),)
 CXXFLAGS_STDCXX = -std=$(STDCXX)
@@ -25,47 +25,47 @@
 CXXFLAGS += $(CXXFLAGS_STDCXX)
 CFLAGS += $(CFLAGS_STDC)
 
-ifeq ($(EMSCRIPTEN_TARGET),js)
-
-CPPFLAGS += 
-CXXFLAGS += -fPIC -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
+CPPFLAGS +=
+CXXFLAGS += -fPIC
+CFLAGS   += -fPIC
+LDFLAGS  +=
+LDLIBS   +=
 ARFLAGS  := rcs
 
-# allow growing heap (might be slower, especially with V8 (as used by Chrome))
-#LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
-# limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
-#LDFLAGS += -s TOTAL_MEMORY=67108864
+ifeq ($(EMSCRIPTEN_TARGET),default)
+# emits whatever is emscripten's default, currently (1.38.8) this is native-wasm with a polyfill.
+CPPFLAGS += -DMPT_BUILD_WASM
+CXXFLAGS += -Os
+CFLAGS   += -Os
+LDFLAGS  += -Os
 
-LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
+else ifeq ($(EMSCRIPTEN_TARGET),wasm)
+# emits native wasm AND an emulator for running wasm in asmjs/js with full wasm optimizations.
+CPPFLAGS += -DMPT_BUILD_WASM
+CXXFLAGS += -Os -s WASM=1 -s BINARYEN_METHOD='native-wasm'
+CFLAGS   += -Os -s WASM=1 -s BINARYEN_METHOD='native-wasm'
+LDFLAGS  += -Os -s WASM=1 -s BINARYEN_METHOD='native-wasm'
 
 else ifeq ($(EMSCRIPTEN_TARGET),asmjs)
+# emits only asmjs
+CPPFLAGS += -DMPT_BUILD_ASMJS
+CXXFLAGS += -O2 -s WASM=0 -s ASM_JS=1
+CFLAGS   += -O2 -s WASM=0 -s ASM_JS=1
+LDFLAGS  += -O2 -s WASM=0 -s ASM_JS=1
 
-CPPFLAGS += 
-CXXFLAGS += -fPIC -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
-ARFLAGS  := rcs
+else ifeq ($(EMSCRIPTEN_TARGET),js)
+# emits only plain javascript with plain javascript focused optimizations.
+CPPFLAGS += -DMPT_BUILD_ASMJS
+CXXFLAGS += -O2 -s WASM=0 -s ASM_JS=2
+CFLAGS   += -O2 -s WASM=0 -s ASM_JS=2
+LDFLAGS  += -O2 -s WASM=0 -s ASM_JS=2
 
-# allow growing heap (might be slower, especially with V8 (as used by Chrome))
-#LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
-# limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
-#LDFLAGS += -s TOTAL_MEMORY=67108864
+endif
 
-LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
+CXXFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math
+CFLAGS   += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing
+LDFLAGS  += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
 
-else ifeq ($(EMSCRIPTEN_TARGET),wasm)
-
-CPPFLAGS += -DMPT_BUILD_WASM
-CXXFLAGS += -fPIC -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
-ARFLAGS  := rcs
-
 # allow growing heap (might be slower, especially with V8 (as used by Chrome))
 #LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
 # limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
@@ -73,8 +73,6 @@
 
 LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
 
-endif
-
 CFLAGS_SILENT += -Wno-unused-parameter -Wno-unused-function -Wno-cast-qual
 
 CXXFLAGS_WARNINGS += -Wmissing-declarations
@@ -82,23 +80,11 @@
 
 REQUIRES_RUNPREFIX=1
 
-ifeq ($(EMSCRIPTEN_TARGET),wasm)
-
-EXESUFFIX=.html
-SOSUFFIX=.wasm
-SO_LDFLAGS=-s SIDE_MODULE=1
-BIN_LDFLAGS=-s SIDE_MODULE=0
-TEST_LDFLAGS=-s SIDE_MODULE=0 --emrun
-
-else
-
 EXESUFFIX=.js
 SOSUFFIX=.js
 RUNPREFIX=nodejs 
 TEST_LDFLAGS= --pre-js build/make/test-pre.js 
 
-endif
-
 DYNLINK=0
 SHARED_LIB=1
 STATIC_LIB=0
Index: common/CompilerDetect.h
===================================================================
--- common/CompilerDetect.h	(revision 10620)
+++ common/CompilerDetect.h	(working copy)
@@ -193,14 +193,12 @@
 	#define MPT_OS_EMSCRIPTEN 1
 	#if defined(__EMSCRIPTEN_major__) && defined(__EMSCRIPTEN_minor__)
 		#if (__EMSCRIPTEN_major__ > 1)
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 0
-		#elif (__EMSCRIPTEN_major__ == 1) && (__EMSCRIPTEN_minor__ >= 36)
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 0
+			// ok 
+		#elif (__EMSCRIPTEN_major__ == 1) && (__EMSCRIPTEN_minor__ >= 38)
+			// ok 		
 		#else
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 1
+			#error "Emscripten >= 1.38 is required."
 		#endif
-	#else
-		#define MPT_OS_EMSCRIPTEN_ANCIENT 1
 	#endif
 #elif defined(_WIN32)
 	#define MPT_OS_WINDOWS 1
Index: common/mptBaseUtils.h
===================================================================
--- common/mptBaseUtils.h	(revision 10620)
+++ common/mptBaseUtils.h	(working copy)
@@ -581,13 +581,7 @@
 {
 
 	// C++11 std::round
-#if (MPT_OS_EMSCRIPTEN && MPT_OS_EMSCRIPTEN_ANCIENT)
-	// Certain emscripten versions and/or combinations with nodejs (at least the following combination: emscripten 1.34.8, clang 3.7.0, nodejs 0.10.38) fail assert(std::round(1.5)==2.0). The work-around always works.
-	inline double round(double val) {if(val >= 0.0) return std::floor(val + 0.5); else return std::ceil(val - 0.5);}
-	inline float round(float val) {if(val >= 0.0f) return std::floor(val + 0.5f); else return std::ceil(val - 0.5f);}
-#else
 	using std::round;
-#endif
 
 	// Rounds given double value to nearest integer value of type T.
 	// Out-of-range values are saturated to the specified integer type's limits.
Index: libopenmpt/dox/changelog.md
===================================================================
--- libopenmpt/dox/changelog.md	(revision 10620)
+++ libopenmpt/dox/changelog.md	(working copy)
@@ -56,6 +56,8 @@
  *  [**Regression**] Support for Clang 3.4, 3.5 has been removed.
  *  [**Regression**] Building with Android NDK older than NDK r16b is not
     supported any more.
+ *  [**Regression**] Support for Emscripten versions older than 1.38.1 has been
+    removed.
  *  [**Regression**] Support for libmpg123 older than 1.14.0 has been removed.
  *  [**Regression**] Using MediaFoundation to decode MP3 samples is no longer
     supported. Use libmpg123 or minimp3 instead.
Index: libopenmpt/dox/dependencies.md
===================================================================
--- libopenmpt/dox/dependencies.md	(revision 10620)
+++ libopenmpt/dox/dependencies.md	(working copy)
@@ -15,7 +15,7 @@
      *  **MinGW-W64 4.8** or higher (it is recommended to preferably use
         posix threading model as opposed to win32 threading model, or at least
         have mingw-std-threads available otherwise)
-     *  **emscripten 1.31** or higher
+     *  **emscripten 1.38.1** or higher
      *  any other **C++11 compliant** compiler (full standard compliant mode is
         known to work with GCC >= 5.1 and Clang)
         
Index: test/test.cpp
===================================================================
--- test/test.cpp	(revision 10620)
+++ test/test.cpp	(working copy)
@@ -685,12 +685,7 @@
 	VERIFY_EQUAL(mpt::fmt::flt(6.12345, 3), "6.12");
 	VERIFY_EQUAL(mpt::fmt::fix(6.12345, 3), "6.123");
 	VERIFY_EQUAL(mpt::fmt::flt(6.12345, 4), "6.123");
-	#if !(MPT_OS_EMSCRIPTEN && MPT_OS_EMSCRIPTEN_ANCIENT)
 	VERIFY_EQUAL(mpt::fmt::fix(6.12345, 4), "6.1235");
-	#else
-	// emscripten(1.21)/nodejs(v0.10.25) print 6.1234 instead of 6.1235 for unknown reasons.
-	// As this test case is not fatal, ignore it for now in order to make the test cases pass.
-	#endif
 
 #if MPT_WSTRING_FORMAT
 	VERIFY_EQUAL(mpt::wfmt::flt(6.12345, 3), L"6.12");
emscripten-wasm-v1.patch (9,350 bytes)
manx

manx

2018-07-26 15:13

administrator   ~0003583

The patch modifies EMSCRIPTEN_TARGET=wasm to EMSCRIPTEN_TARGET=[default|wasm|asmjs|js] modes and requires Emscripten 1.38.1. Emscripten 1.38.1 emit WebAssembly by default and also emits a WebAssembly interpreter, running in asm.js or plain JavaScript depending on what is available. That's at least the situation as I understand it. It is unclear which mode node.js will actually use for the test suite.
Also, for Emscripten after 1.37.0, we do not need PRECISE_F32=1 any more, which should speed up runtime on Chrome and node.js (for floating-point heavy code paths) according to Emscripten documentation.

manx

manx

2018-08-01 16:54

administrator   ~0003584

Utilizing emscripten's combined output methods is not recommended and has blocking bugs. See <https://kripken.github.io/emscripten-site/docs/compiling/WebAssembly.html> and <https://github.com/kripken/emscripten/issues/6926>.
This still leaves he question as to in which way we should provide compiled artifacts for the web platform. We could either include all three of them in a single archive with different names, or provide three separate archives or just provide a single archive with only one variant (which will have sub-optimal performance or just not work in some cases).

manx

manx

2018-08-01 16:55

administrator  

emscripten-wasm-v4.patch (11,250 bytes)
Index: Makefile
===================================================================
--- Makefile	(revision 10647)
+++ Makefile	(working copy)
@@ -905,15 +905,23 @@
 MISC_OUTPUTS += libopenmpt$(SOSUFFIX)
 MISC_OUTPUTS += bin/.docs
 MISC_OUTPUTS += bin/libopenmpt_test$(EXESUFFIX)
+MISC_OUTPUTS += bin/libopenmpt_test.wasm
 MISC_OUTPUTS += bin/libopenmpt_test.js.mem
 MISC_OUTPUTS += bin/made.docs
 MISC_OUTPUTS += bin/$(LIBOPENMPT_SONAME)
+MISC_OUTPUTS += bin/libopenmpt.wasm
 MISC_OUTPUTS += bin/libopenmpt.js.mem
+MISC_OUTPUTS += bin/libopenmpt_example_c.wasm 
 MISC_OUTPUTS += bin/libopenmpt_example_c.js.mem 
+MISC_OUTPUTS += bin/libopenmpt_example_c_mem.wasm 
 MISC_OUTPUTS += bin/libopenmpt_example_c_mem.js.mem 
+MISC_OUTPUTS += bin/libopenmpt_example_c_pipe.wasm
 MISC_OUTPUTS += bin/libopenmpt_example_c_pipe.js.mem
+MISC_OUTPUTS += bin/libopenmpt_example_c_probe.wasm
 MISC_OUTPUTS += bin/libopenmpt_example_c_probe.js.mem
+MISC_OUTPUTS += bin/libopenmpt_example_c_stdout.wasm
 MISC_OUTPUTS += bin/libopenmpt_example_c_stdout.js.mem
+MISC_OUTPUTS += bin/libopenmpt_example_c_unsafe.wasm
 MISC_OUTPUTS += bin/libopenmpt_example_c_unsafe.js.mem
 MISC_OUTPUTS += bin/openmpt.a
 #old
@@ -930,7 +938,9 @@
 DIST_OUTPUTS += bin/dist-zip.tar
 DIST_OUTPUTS += bin/dist-doc.tar
 DIST_OUTPUTS += bin/dist-autotools.tar
-DIST_OUTPUTS += bin/dist-js.tar   
+DIST_OUTPUTS += bin/dist-wasm.tar
+DIST_OUTPUTS += bin/dist-asmjs.tar
+DIST_OUTPUTS += bin/dist-js.tar
 DIST_OUTPUTS += bin/made.docs
 
 DIST_OUTPUTDIRS += bin/dist
@@ -938,6 +948,8 @@
 DIST_OUTPUTDIRS += bin/dist-tar
 DIST_OUTPUTDIRS += bin/dist-zip
 DIST_OUTPUTDIRS += bin/dist-autotools
+DIST_OUTPUTDIRS += bin/dist-wasm
+DIST_OUTPUTDIRS += bin/dist-asmjs
 DIST_OUTPUTDIRS += bin/dist-js
 DIST_OUTPUTDIRS += bin/docs
 
Index: README.md
===================================================================
--- README.md	(revision 10647)
+++ README.md	(working copy)
@@ -179,8 +179,8 @@
 
      -  emscripten (on Unix-like systems):
 
-        libopenmpt has been tested and verified to work with emscripten 1.31 or
-        later (earlier versions might or might not work).
+        libopenmpt has been tested and verified to work with emscripten 1.38.1
+        or later. Earlier versions are not supported.
 
         Run:
 
@@ -187,7 +187,7 @@
             make CONFIG=emscripten
 
         Running the test suite on the command line is also supported by using
-        node.js. Version 0.10.25 or greater has been tested. Earlier versions
+        node.js. Version 8.9.1 or greater has been tested. Earlier versions
         might or might not work. Depending on how your distribution calls the
         `node.js` binary, you might have to edit
         `build/make/config-emscripten.mk`.
Index: build/make/config-emscripten.mk
===================================================================
--- build/make/config-emscripten.mk	(revision 10647)
+++ build/make/config-emscripten.mk	(working copy)
@@ -4,7 +4,7 @@
 LD  = em++
 AR  = emar
 
-EMSCRIPTEN_TARGET?=asmjs
+EMSCRIPTEN_TARGET?=default
 
 ifneq ($(STDCXX),)
 CXXFLAGS_STDCXX = -std=$(STDCXX)
@@ -25,47 +25,52 @@
 CXXFLAGS += $(CXXFLAGS_STDCXX)
 CFLAGS += $(CFLAGS_STDC)
 
-ifeq ($(EMSCRIPTEN_TARGET),js)
-
-CPPFLAGS += 
-CXXFLAGS += -fPIC -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -O2 -s ASM_JS=2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
+CPPFLAGS +=
+CXXFLAGS += -fPIC
+CFLAGS   += -fPIC
+LDFLAGS  +=
+LDLIBS   +=
 ARFLAGS  := rcs
 
-# allow growing heap (might be slower, especially with V8 (as used by Chrome))
-#LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
-# limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
-#LDFLAGS += -s TOTAL_MEMORY=67108864
+CXXFLAGS += -Os
+CFLAGS   += -Os
+LDFLAGS  += -Os
 
-LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
+ifeq ($(EMSCRIPTEN_TARGET),default)
+# emits whatever is emscripten's default, currently (1.38.8) this is the same as "wasm" below.
+CPPFLAGS += -DMPT_BUILD_WASM
+CXXFLAGS += 
+CFLAGS   += 
+LDFLAGS  += 
 
+else ifeq ($(EMSCRIPTEN_TARGET),wasm)
+# emits native wasm AND an emulator for running wasm in asmjs/js with full wasm optimizations.
+# as of emscripten 1.38, this is equivalent to default.
+CPPFLAGS += -DMPT_BUILD_WASM
+CXXFLAGS += -s WASM=1 -s BINARYEN_METHOD='native-wasm'
+CFLAGS   += -s WASM=1 -s BINARYEN_METHOD='native-wasm'
+LDFLAGS  += -s WASM=1 -s BINARYEN_METHOD='native-wasm'
+
 else ifeq ($(EMSCRIPTEN_TARGET),asmjs)
+# emits only asmjs
+CPPFLAGS += -DMPT_BUILD_ASMJS
+CXXFLAGS += -s WASM=0 -s ASM_JS=1
+CFLAGS   += -s WASM=0 -s ASM_JS=1
+LDFLAGS  += -s WASM=0 -s ASM_JS=1
 
-CPPFLAGS += 
-CXXFLAGS += -fPIC -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s PRECISE_F32=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
-ARFLAGS  := rcs
+else ifeq ($(EMSCRIPTEN_TARGET),js)
+# emits only plain javascript with plain javascript focused optimizations.
+CPPFLAGS += -DMPT_BUILD_ASMJS
+CXXFLAGS += -s WASM=0 -s ASM_JS=2 -s LEGACY_VM_SUPPORT=1
+CFLAGS   += -s WASM=0 -s ASM_JS=2 -s LEGACY_VM_SUPPORT=1
+LDFLAGS  += -s WASM=0 -s ASM_JS=2 -s LEGACY_VM_SUPPORT=1
 
-# allow growing heap (might be slower, especially with V8 (as used by Chrome))
-#LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
-# limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
-#LDFLAGS += -s TOTAL_MEMORY=67108864
+endif
 
-LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
+CXXFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math
+CFLAGS   += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing
+LDFLAGS  += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
 
-else ifeq ($(EMSCRIPTEN_TARGET),wasm)
-
-CPPFLAGS += -DMPT_BUILD_WASM
-CXXFLAGS += -fPIC -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math 
-CFLAGS   += -fPIC -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -ffast-math -fno-strict-aliasing 
-LDFLAGS  += -Os -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s EXPORT_NAME="'libopenmpt'"
-LDLIBS   += 
-ARFLAGS  := rcs
-
 # allow growing heap (might be slower, especially with V8 (as used by Chrome))
 #LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
 # limit memory to 64MB, faster but loading modules bigger than about 16MB will not work
@@ -73,8 +78,6 @@
 
 LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
 
-endif
-
 CFLAGS_SILENT += -Wno-unused-parameter -Wno-unused-function -Wno-cast-qual
 
 CXXFLAGS_WARNINGS += -Wmissing-declarations
@@ -82,23 +85,11 @@
 
 REQUIRES_RUNPREFIX=1
 
-ifeq ($(EMSCRIPTEN_TARGET),wasm)
-
-EXESUFFIX=.html
-SOSUFFIX=.wasm
-SO_LDFLAGS=-s SIDE_MODULE=1
-BIN_LDFLAGS=-s SIDE_MODULE=0
-TEST_LDFLAGS=-s SIDE_MODULE=0 --emrun
-
-else
-
 EXESUFFIX=.js
 SOSUFFIX=.js
 RUNPREFIX=nodejs 
 TEST_LDFLAGS= --pre-js build/make/test-pre.js 
 
-endif
-
 DYNLINK=0
 SHARED_LIB=1
 STATIC_LIB=0
Index: common/CompilerDetect.h
===================================================================
--- common/CompilerDetect.h	(revision 10647)
+++ common/CompilerDetect.h	(working copy)
@@ -193,14 +193,12 @@
 	#define MPT_OS_EMSCRIPTEN 1
 	#if defined(__EMSCRIPTEN_major__) && defined(__EMSCRIPTEN_minor__)
 		#if (__EMSCRIPTEN_major__ > 1)
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 0
-		#elif (__EMSCRIPTEN_major__ == 1) && (__EMSCRIPTEN_minor__ >= 36)
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 0
+			// ok 
+		#elif (__EMSCRIPTEN_major__ == 1) && (__EMSCRIPTEN_minor__ >= 38)
+			// ok 		
 		#else
-			#define MPT_OS_EMSCRIPTEN_ANCIENT 1
+			#error "Emscripten >= 1.38 is required."
 		#endif
-	#else
-		#define MPT_OS_EMSCRIPTEN_ANCIENT 1
 	#endif
 #elif defined(_WIN32)
 	#define MPT_OS_WINDOWS 1
Index: common/mptBaseUtils.h
===================================================================
--- common/mptBaseUtils.h	(revision 10647)
+++ common/mptBaseUtils.h	(working copy)
@@ -581,13 +581,7 @@
 {
 
 	// C++11 std::round
-#if (MPT_OS_EMSCRIPTEN && MPT_OS_EMSCRIPTEN_ANCIENT)
-	// Certain emscripten versions and/or combinations with nodejs (at least the following combination: emscripten 1.34.8, clang 3.7.0, nodejs 0.10.38) fail assert(std::round(1.5)==2.0). The work-around always works.
-	inline double round(double val) {if(val >= 0.0) return std::floor(val + 0.5); else return std::ceil(val - 0.5);}
-	inline float round(float val) {if(val >= 0.0f) return std::floor(val + 0.5f); else return std::ceil(val - 0.5f);}
-#else
 	using std::round;
-#endif
 
 	// Rounds given double value to nearest integer value of type T.
 	// Out-of-range values are saturated to the specified integer type's limits.
Index: libopenmpt/dox/changelog.md
===================================================================
--- libopenmpt/dox/changelog.md	(revision 10647)
+++ libopenmpt/dox/changelog.md	(working copy)
@@ -56,6 +56,8 @@
  *  [**Regression**] Support for Clang 3.4, 3.5 has been removed.
  *  [**Regression**] Building with Android NDK older than NDK r16b is not
     supported any more.
+ *  [**Regression**] Support for Emscripten versions older than 1.38.1 has been
+    removed.
  *  [**Regression**] Support for libmpg123 older than 1.14.0 has been removed.
  *  [**Regression**] Using MediaFoundation to decode MP3 samples is no longer
     supported. Use libmpg123 or minimp3 instead.
Index: libopenmpt/dox/dependencies.md
===================================================================
--- libopenmpt/dox/dependencies.md	(revision 10647)
+++ libopenmpt/dox/dependencies.md	(working copy)
@@ -15,7 +15,7 @@
      *  **MinGW-W64 4.8** or higher (it is recommended to preferably use
         posix threading model as opposed to win32 threading model, or at least
         have mingw-std-threads available otherwise)
-     *  **emscripten 1.31** or higher
+     *  **emscripten 1.38.1** or higher
      *  any other **C++11 compliant** compiler (full standard compliant mode is
         known to work with GCC >= 5.1 and Clang)
         
Index: test/test.cpp
===================================================================
--- test/test.cpp	(revision 10647)
+++ test/test.cpp	(working copy)
@@ -685,12 +685,7 @@
 	VERIFY_EQUAL(mpt::fmt::flt(6.12345, 3), "6.12");
 	VERIFY_EQUAL(mpt::fmt::fix(6.12345, 3), "6.123");
 	VERIFY_EQUAL(mpt::fmt::flt(6.12345, 4), "6.123");
-	#if !(MPT_OS_EMSCRIPTEN && MPT_OS_EMSCRIPTEN_ANCIENT)
 	VERIFY_EQUAL(mpt::fmt::fix(6.12345, 4), "6.1235");
-	#else
-	// emscripten(1.21)/nodejs(v0.10.25) print 6.1234 instead of 6.1235 for unknown reasons.
-	// As this test case is not fatal, ignore it for now in order to make the test cases pass.
-	#endif
 
 #if MPT_WSTRING_FORMAT
 	VERIFY_EQUAL(mpt::wfmt::flt(6.12345, 3), L"6.12");
emscripten-wasm-v4.patch (11,250 bytes)
manx

manx

2018-08-26 07:37

administrator   ~0003606

We package 4 different builds in the single dev.js package:

  • wasm: WebAssembly
  • asmjs128m: asm.js with 128MB memory (no dynamic memory growth because that is deprecated, removed from the standard, and not supported by modern asm.js implementations)
  • asmjs: asm.js with default memory configuration (16MB with current emscripten versions)
  • js: plan JavaScript with explicit support and workarounds for older VMs

Implemented in r10713.

Issue History

Date Modified Username Field Change
2017-09-22 12:50 manx New Issue
2017-09-22 12:50 manx Status new => assigned
2017-09-22 12:50 manx Assigned To => manx
2017-10-28 09:48 manx Note Added: 0003317
2018-04-09 12:42 manx Note Added: 0003493
2018-07-26 15:09 manx File Added: emscripten-wasm-v1.patch
2018-07-26 15:13 manx Note Added: 0003583
2018-08-01 16:54 manx Note Added: 0003584
2018-08-01 16:55 manx File Added: emscripten-wasm-v4.patch
2018-08-26 07:37 manx Note Added: 0003606
2018-08-26 07:38 manx Status assigned => resolved
2018-08-26 07:38 manx Resolution open => fixed
2018-08-26 07:38 manx Fixed in Version => libopenmpt 0.4 (goals)