emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.73k stars 3.3k forks source link

Compilation error with -sUSE_SDL_TTF=2 and -sMAIN_MODULE=2 #20204

Open hedwigz opened 1 year ago

hedwigz commented 1 year ago

Version of emscripten/emsdk: 3.1.41

Failing command line in full:

$ emcc -pthread -sUSE_SDL=2 -sUSE_SDL_TTF=2 -sMAIN_MODULE=2 main.c
shared:INFO: (Emscripten: Running sanity checks)
cache:INFO: generating system headers: sysroot_install.stamp... (this will be cached in "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/sysroot_install.stamp" for subsequent builds)
cache:INFO:  - ok
ports:INFO: retrieving port: freetype from https://github.com/emscripten-ports/FreeType/archive/version_1.zip
ports:INFO: unpacking port: freetype
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/pic/libfreetype.a... (this will be cached in "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libfreetype.a" for subsequent builds)
system_libs:INFO: compiled 52 inputs
cache:INFO:  - ok
ports:INFO: retrieving port: sdl2 from https://github.com/libsdl-org/SDL/archive/release-2.24.2.zip
ports:INFO: unpacking port: sdl2
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/pic/libSDL2-mt.a... (this will be cached in "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libSDL2-mt.a" for subsequent builds)
system_libs:INFO: compiled 115 inputs
cache:INFO:  - ok
ports:INFO: retrieving port: harfbuzz from https://github.com/harfbuzz/harfbuzz/releases/download/3.2.0/harfbuzz-3.2.0.tar.xz
ports:INFO: unpacking port: harfbuzz
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/pic/libharfbuzz-mt.a... (this will be cached in "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libharfbuzz-mt.a" for subsequent builds)
system_libs:INFO: compiled 55 inputs
cache:INFO:  - ok
ports:INFO: retrieving port: sdl2_ttf from https://github.com/libsdl-org/SDL_ttf/archive/release-2.20.2.zip
ports:INFO: unpacking port: sdl2_ttf
cache:INFO: generating port: sysroot/lib/wasm32-emscripten/pic/libSDL2_ttf.a... (this will be cached in "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/libSDL2_ttf.a" for subsequent builds)
Traceback (most recent call last):
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 4416, in <module>
    sys.exit(main(sys.argv))
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 4409, in main
    ret = run(args)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 1281, in run
    linker_inputs = phase_compile_inputs(options, state, newargs, input_files)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 3062, in phase_compile_inputs
    compile_source_file(i, input_file)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 3040, in compile_source_file
    cmd = get_clang_command(input_file)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 2974, in get_clang_command
    return get_compiler(src_file) + get_cflags(state.orig_args, use_cxx(src_file)) + compile_args + [src_file]
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc.py", line 1018, in get_cflags
    ports.add_cflags(cflags, settings)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/ports/__init__.py", line 415, in add_cflags
    port.get(Ports, settings, shared)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/ports/sdl2.py", line 77, in get
    return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/cache.py", line 139, in get_lib
    return get(name, *args, **kwargs)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/cache.py", line 157, in get
    with lock(shortname):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/cache.py", line 61, in lock
    acquire_cache_lock(reason)
  File "/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/tools/cache.py", line 35, in acquire_cache_lock
    assert 'EM_CACHE_IS_LOCKED' not in os.environ, f'attempt to lock the cache while a parent process is holding the lock ({reason})'
AssertionError: attempt to lock the cache while a parent process is holding the lock (sysroot/lib/wasm32-emscripten/pic/libSDL2.a)
emcc: error: Subprocess 1/1 failed (returned 1)! (cmdline: /Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/emcc -c /Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/ports/sdl2_ttf/SDL_ttf-release-2.20.2/SDL_ttf.c -o /Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/ports-builds/sdl2_ttf/SDL_ttf.c.o -g -sSTRICT -sRELOCATABLE -Werror -O2 -I/Users/amit/dev/rdp-wasm-core/vendor/emsdk/upstream/emscripten/cache/ports/sdl2_ttf/SDL_ttf-release-2.20.2 -DTTF_USE_HARFBUZZ=1 -sUSE_SDL=2 -sUSE_FREETYPE -sUSE_HARFBUZZ)

I am running on Mac M1 and it seems like some combination of settings to emcc cause the above error.
if I omit only -sUSE_SDL_TTF=2, the command works. i.e. the following command does work:

emcc -pthread -sUSE_SDL=2 -sMAIN_MODULE=2 main.c
sbc100 commented 11 months ago

Closing as duplicate of #20214 since it seems to be the same root cause

jfolker commented 11 months ago

Closing as duplicate of #20214 since it seems to be the same root cause

This is definitely not a duplicate of a bug report filed a day later. If you're too backed up to try your hand at it then no problem, and it's not like any of us are paying you for support, but we should at least leave the bug report open as a known bug of emscripten's "package manager".

I would try my hand at fixing it, but I'm ass-deep in alligators myself just trying to solve the problem I was considering emscripten for in the first place (a graphical client for rastering an X-Ray diffractometer). Let's toss this PR back into the pool for a summer intern interested in learning how IPC works.

sbc100 commented 11 months ago

What makes you think its no a duplicate? The root cause looks like the same thing to me.

I did try to fix this a while back and ran into some difficulties although I do think I understand the root cause of the problem pretty well now. IMHO these look the same. What make this you think otherwise?

sbc100 commented 11 months ago

Or is that you think I just chose the wrong one of duplicates to close since this was opened first? I'm happy to close #20214 if you prefer?

jfolker commented 11 months ago

I think there's a misunderstanding here: what I said is that this bug report is the original (i.e. not a duplicate) because #20214 was filed after it.

At least one of the bug reports filed is the original and should not be closed. Because this one was the first one filed, this one should stay open until it is fixed, or a workaround is identified that makes it no longer worth fixing.

I don't care which one stays open, we just can't circularly declare all the bugs are duplicates of one another without pointing to one as the original.

EDIT: P.S. I apologize if my terseness came off as rude. I was only trying to make sure what I say is worded correctly without misunderstanding.