emscripten: add hack to prevent ERRNO_CODES from being optimized away

This commit is contained in:
Toad King 2019-08-07 22:07:09 -05:00
parent 05fecc4e15
commit 618da66073
3 changed files with 20 additions and 1 deletions

View File

@ -42,7 +42,8 @@ LIBS := -s USE_ZLIB=1
LDFLAGS := -L. --no-heap-copy -s USE_ZLIB=1 -s TOTAL_MEMORY=$(MEMORY) -s NO_EXIT_RUNTIME=0 -s FULL_ES2=1 \
-s EXPORTED_FUNCTIONS="['_main', '_malloc', '_cmd_savefiles', '_cmd_save_state', '_cmd_load_state', '_cmd_take_screenshot']" \
--js-library emscripten/library_rwebaudio.js \
--js-library emscripten/library_rwebcam.js
--js-library emscripten/library_rwebcam.js \
--js-library emscripten/library_errno_codes.js
ifneq ($(PTHREAD), 0)
LDFLAGS += -s USE_PTHREADS=$(PTHREAD) -s PTHREAD_POOL_SIZE=2
endif

View File

@ -0,0 +1,15 @@
//"use strict";
// HACK: This is a dummy library that forces ERRNO_CODES to be used, so it's not optimized away.
// Needed for BrowserFS.
var LibraryErrnoCodes = {
dummyErrnoCodes__deps: ['$ERRNO_CODES'],
dummyErrnoCodes: function() {
if (!ERRNO_CODES) {
console.error("ERRNO_CODES not imported!");
}
}
};
mergeInto(LibraryManager.library, LibraryErrnoCodes);

View File

@ -47,6 +47,7 @@
#include "../../file_path_special.h"
void RWebAudioRecalibrateTime(void);
void dummyErrnoCodes(void);
static unsigned emscripten_fullscreen_reinit;
static unsigned emscripten_frame_count = 0;
@ -226,6 +227,8 @@ int main(int argc, char *argv[])
{
EMSCRIPTEN_RESULT r;
dummyErrnoCodes();
emscripten_set_canvas_element_size("#canvas", 800, 600);
emscripten_set_element_css_size("#canvas", 800.0, 600.0);
emscripten_set_main_loop(emscripten_mainloop, 0, 0);