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 21, 2023
1 parent 3266e42 commit 4fc7c02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 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, enabled):
if enabled:
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-sjlj.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
4 changes: 2 additions & 2 deletions tools/ports/libpng.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
HASH = '2ce2b855af307ca92a6e053f521f5d262c36eb836b4810cb53c809aa3ea2dcc08f834aee0ffd66137768a54397e28e92804534a74abb6fc9f6f3127f14c9c338'

deps = ['zlib']
variants = {'libpng-mt': {'PTHREADS': 1}}
variants = {'libpng-wasm-sjlj': {'SUPPORT_LONGJMP': 'wasm'}}


def needed(settings):
return settings.USE_LIBPNG


def get_lib_name(settings):
return 'libpng' + ('-mt' if settings.PTHREADS else '') + '.a'
return 'libpng' + ('-wasm-sjlj' if settings.SUPPORT_LONGJMP else '') + '.a'


def get(ports, settings, shared):
Expand Down

0 comments on commit 4fc7c02

Please sign in to comment.