Skip to content

Post Link for libraries #24250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ErikSom opened this issue May 3, 2025 · 4 comments · Fixed by #24270
Closed

Post Link for libraries #24250

ErikSom opened this issue May 3, 2025 · 4 comments · Fixed by #24270

Comments

@ErikSom
Copy link

ErikSom commented May 3, 2025

We use --post-link in our build script to do the heavy lifting of compiling Box2D and our glue only once into a bare WASM and then do the cheap part creating a JS library multiple times (ESM / CommonJS).
However a release after 3.1.73 broke --post-link for us. The use-case for libraries might not have been considered with the changes. We now trigger the following error:

if len(options.input_files) != 1:
exit_with_error('--post-link requires a single input file')

This is the command we use to build:
https://github.com/Birch-san/box2d3-wasm/blob/0a839337b041e1de851fc7be9e9a6aae6e4edc4e/box2d3-wasm/shell/1_build_wasm.sh#L143

Any suggestions for us on how to work around the issue, or do you see a way our use case could be considered?

@Birch-san
Copy link

Birch-san commented May 3, 2025

we compile box2d and our glue code to bare wasm like so (this is the slow part, and bare wasm means we only have to do it once):

emcc -lembind \
./csrc/glue.cpp \
./csrc/threading.cpp \
./csrc/debugDraw.cpp \
./enkiTS/src/TaskScheduler.cpp \
./cmake-build-deluxe/src/libbox2dd.a \
-I ./box2d/include \
-I ./enkiTS/src \
-I ./box2cpp/include \
-std=c++20 \
-s MODULARIZE=1 \
-s EXPORT_NAME=Box2D \
-s ALLOW_TABLE_GROWTH=1 \
-s FILESYSTEM=0 \
-s EXPORTED_FUNCTIONS=_malloc,_free \
-s ALLOW_MEMORY_GROWTH=1 \
-msimd128 -msse2 -pthread \
-s USE_PTHREADS=1 \
-s PTHREAD_POOL_SIZE=pthreadCount \
-g3 -gsource-map \
-s ASSERTIONS=2 \
--oformat=bare \
-o ./build/Box2D.deluxe.bare.wasm

we then post-link Box2D.deluxe.bare.wasm like so:

emcc \
-g3 -gsource-map -pthread \
-s USE_PTHREADS=1 \
-s PTHREAD_POOL_SIZE='_emscripten_num_logical_cores()' \
-lembind \
-s ALLOW_MEMORY_GROWTH=1 \
--post-link ./build/Box2D.deluxe.bare.wasm \
-s EXPORT_ES6=1 \
-o ./build/dist/es/deluxe/Box2D.deluxe.mjs \
--emit-tsd ./build/dist/es/deluxe/Box2D.deluxe.d.ts

this used to work in 3.1.73, but now fails (e.g. in 4.0.8), as Erik demonstrated above.

@Birch-san
Copy link

Birch-san commented May 3, 2025

Image

looks like arg parsing failed? -s options got parsed as positional arguments?

@Birch-san
Copy link

you can reproduce in VSCode debugger via:

{
    "configurations": [
        {
            "name": "emcc",
            "type": "debugpy",
            "request": "launch",
            "program": "emcc.py",
            "args": [
                "-g3", "-gsource-map", "-pthread",
                "-s", "USE_PTHREADS=1",
                "-s", "PTHREAD_POOL_SIZE='_emscripten_num_logical_cores()'",
                "-lembind",
                "-s", "ALLOW_MEMORY_GROWTH=1",
                "--post-link", "/Users/birch/git/box2d3-wasm/box2d3-wasm/build/Box2D.deluxe.bare.wasm",
                "-s", "EXPORT_ES6=1",
                "-o", "/Users/birch/git/box2d3-wasm/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.mjs",
                "--emit-tsd",
                "/Users/birch/git/box2d3-wasm/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.d.ts",
            ],
            "console": "integratedTerminal"
        }
    ]
}

it fails during parsing so you don't even need the files on your computer in order to repro

@sbc100
Copy link
Collaborator

sbc100 commented May 5, 2025

Wow, that looks very wrong.

One temporary workaround might be to merge your -s flags in to single arguments like -sALLOW_MEMORY_GROWTH rather than specifying the -s separately. This is the recommended form these days anyway.

Also you can drop USE_PTHREADS=1 since that is implied by -pthread.

Also, for boolean options like -sALLOW_MEMORY_GROWTH there is no need for the extra =1 on the end.

sbc100 added a commit to sbc100/emscripten that referenced this issue May 6, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue May 6, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue May 6, 2025
sbc100 added a commit that referenced this issue May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants