Skip to content

Commit

Permalink
Fix libpng and libfreetype port with wasm exceptions are enabled
Browse files Browse the repository at this point in the history
For libpng we simply avoid the use of setjmp/longjmp completely.

For libfreetype the use of setjmp/longjmp is not optional so we build a
variant of the library that uses wasm exceptions for setjmp/longjmp
support.

Fixes: #19001
  • Loading branch information
sbc100 committed Mar 19, 2023
1 parent f51beb1 commit ddefa3d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
15 changes: 15 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ def metafunc(self, wasmfs):
return metafunc


def also_with_wasm_longjmp(f):
def metafunc(self, wasmfs):
if wasmfs:
self.require_wasm_eh()
self.emcc_args.append('-sSUPPORT_LONGJMP=wasm')
f(self)
else:
f(self)

metafunc._parameterize = {'': (False,),
'wasm_longjmp': (True,)}
return metafunc


def wasmfs_all_backends(f):
def metafunc(self, backend):
self.set_setting('WASMFS')
Expand Down Expand Up @@ -2205,6 +2219,7 @@ def test_bzip2(self):
self.do_runf(test_file('bzip2_test.c'), 'usage: unzcrash filename',
emcc_args=['-sUSE_BZIP2', '-Wno-pointer-sign'])

@also_with_wasm_longjmp
def test_freetype(self):
# copy the Liberation Sans Bold truetype file located in the
# <emscripten_root>/test/freetype to the compilation folder
Expand Down
16 changes: 14 additions & 2 deletions tools/ports/freetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
TAG = 'version_1'
HASH = '0d0b1280ba0501ad0a23cf1daa1f86821c722218b59432734d3087a89acd22aabd5c3e5e1269700dcd41e87073046e906060f167c032eb91a3ac8c5808a02783'

variants = {'freetype-wasm-longjmp': {'SUPPORT_LONGJMP': 'wasm'}}


def needed(settings):
return settings.USE_FREETYPE


def get_lib_name(settings):
if settings.SUPPORT_LONGJMP == 'wasm':
return 'libfreetype-wasm-eh.a'
else:
return 'libfreetype.a'


def get(ports, settings, shared):
ports.fetch_project('freetype', f'https://github.com/emscripten-ports/FreeType/archive/{TAG}.zip', sha512hash=HASH)

Expand Down Expand Up @@ -90,13 +99,16 @@ def create(final):
'-pthread'
]

if settings.SUPPORT_LONGJMP == 'wasm':
flags.append('-sSUPPORT_LONGJMP=wasm')

ports.build_port(source_path, final, 'freetype', flags=flags, srcs=srcs)

return [shared.cache.get_lib('libfreetype.a', create, what='port')]
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]


def clear(ports, settings, shared):
shared.cache.erase_lib('libfreetype.a')
shared.cache.erase_lib(get_lib_name(settings))


def process_args(ports):
Expand Down
6 changes: 3 additions & 3 deletions tools/ports/libpng.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,17 @@ def show():
#define PNG_SAVE_INT_32_SUPPORTED
#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SEQUENTIAL_READ_SUPPORTED
#define PNG_SETJMP_SUPPORTED
/*define PNG_SETJMP_SUPPORTED*/
#define PNG_SET_OPTION_SUPPORTED
#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SET_USER_LIMITS_SUPPORTED
#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
#define PNG_SIMPLIFIED_READ_SUPPORTED
/*#define PNG_SIMPLIFIED_READ_SUPPORTED*/
#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
#define PNG_SIMPLIFIED_WRITE_SUPPORTED
/*#define PNG_SIMPLIFIED_WRITE_SUPPORTED*/
#define PNG_STDIO_SUPPORTED
#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_TEXT_SUPPORTED
Expand Down

0 comments on commit ddefa3d

Please sign in to comment.