Skip to content

--extern-pre-js no longer accessible in Workers #22012

Closed

Description

@dchengTSC

I have a javascript library (tensorflow.js) that I want to be able to access from a worker in C++ code. Previously (3.1.51), if I used --extern-pre-js to prepend this to the main js file, this worked.

It seems that after #21701 , extern-pre-js'es are no longer accessible from workers. If I modify the generated main.js file to always include the extern-pre-js (remove the check if (!isPthread)), things work like they did before.

If I use --pre-js instead of --extern-pre-js, I get an error because the acorn optimization fails on the js file that I pass in.

Is there some other way I should be making external javascript libraries accessible to Workers?

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.60 (42a6ea2)
clang version 19.0.0git (https:/github.com/llvm/llvm-project bc9823cf60bf91cc8b45248c4205cd2c67b2a3d5)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/d.cheng/projects/emsdk/upstream/bin

Full link command and output with -v appended:
(Note: I formatted the output some, removed some verbose output and renamed my project name to asdf)

[1/1] : && /Users/d.cheng/projects/emsdk/upstream/emscripten/em++
-sUSE_BOOST_HEADERS=1
-sUSE_GIFLIB=1
-sUSE_LIBPNG
-sUSE_SDL=2
-pthread
-sNO_DISABLE_EXCEPTION_CATCHING
-sNO_DISABLE_EXCEPTION_CATCHING
-sUSE_ZLIB=1
-DBOOST_NO_CXX98_FUNCTION_BASE
-fexperimental-library
-g2
--embind-emit-tsd=asdf.d.ts
-g
-sUSE_BOOST_HEADERS=1
-sUSE_GIFLIB=1
-sUSE_LIBPNG
-sUSE_SDL=2
-pthread
-sNO_DISABLE_EXCEPTION_CATCHING
-sNO_DISABLE_EXCEPTION_CATCHING
-sUSE_ZLIB=1
--bind
-sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency
-sNO_DISABLE_EXCEPTION_CATCHING
-sWASM_BIGINT
-sOFFSCREENCANVAS_SUPPORT=1
-sFULL_ES3=1
-sMODULARIZE
-sEXPORT_NAME="CreateAsdf"
-sUSE_ES6_IMPORT_META=0
-sEXPORTED_RUNTIME_METHODS=["FS"]
-sENVIRONMENT=web,worker
-sEXPORT_ES6=1
-v
-sINITIAL_MEMORY=268435456
-sASSERTIONS=0
--extern-pre-js /Users/d.cheng/projects/CommonCpp/asdf-wasm/JSDependencyBuilder/build/external-library.js

*** a bunch of --embed-file ***
*** a bunch of .o files ***
*** a bunch of .a files ***

em++: warning: --embind-emit-tsd is deprecated. Use --emit-tsd instead. [-Wdeprecated]
/Users/d.cheng/projects/emsdk/upstream/bin/clang --version
/Users/d.cheng/projects/emsdk/upstream/emscripten/tools/file_packager bin/asdf.data --from-emcc --embed *** a bunch of files to embed *** --no-node --obj-output=/var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/emscripten_temp_ajcbzrag/embedded_files.o
/Users/d.cheng/projects/emsdk/upstream/bin/wasm-ld @/var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/emscripten_5fqvg2za.rsp.utf-8
/Users/d.cheng/projects/emsdk/upstream/bin/llvm-objcopy bin/asdf.wasm bin/asdf.wasm --remove-section=producers
/Users/d.cheng/projects/emsdk/node/18.20.3_64bit/bin/node /Users/d.cheng/projects/emsdk/upstream/emscripten/src/compiler.mjs /var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/tmpm_edp739.json
/Users/d.cheng/projects/emsdk/node/18.20.3_64bit/bin/node /Users/d.cheng/projects/emsdk/upstream/emscripten/src/compiler.mjs /var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/tmpd4rrb3gn.json
/Users/d.cheng/projects/emsdk/node/18.20.3_64bit/bin/node /var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/emscripten_temp_ajcbzrag/tsgen_a.out.js
tsc --outFile /var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/emscripten_temp_ajcbzrag/jsdoc.d.ts --declaration --emitDeclarationOnly --allowJs /var/folders/_6/dll3kgx93qz05hvnymcr5jzh0000gp/T/emscripten_temp_ajcbzrag/jsdoc.js

Activity

  1. sbc100 commented on May 29, 2024

    @sbc100
    Collaborator

    That does sounds like an unintended regression in #21701... I can't quite remember why it was important not to run those extern files in pthreads, so I will run tests to find out.

  2. added 2 commits that reference this issue on May 29, 2024
    e59abc0
    b528d41
  3. added a commit that references this issue on May 30, 2024
    845ad34
  4. added a commit that references this issue on Jun 4, 2024
    d59d380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions