emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.89k stars 3.32k forks source link

MainModuleFactory function implementation missing with embind generated typescript #22657

Open dav1d-wright opened 1 month ago

dav1d-wright commented 1 month ago

I am trying to generate typescript bindings with embind, but getting the following error:

src/autogenerated_types.ts:58:25 - error TS2391: Function implementation is missing or not immediately following the declaration.

58 export default function MainModuleFactory (options?: unknown): Promise<MainModule>;

Is it expected for consumers of these typescript definitions to implement this function, or is this implementation generated automatically by embind in the .js file? I can't find anything regarding this in the documentation, and there isn't anything else that I could find in this repository, or on google. The consumers of this library are expecting a modularized NPM package, so I don't think I can turn off MODULARIZE.

Any help is greatly appreciated!

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.60 (42a6ea2052f19f70d7d994e8c324bcad2f1f8939)
clang version 19.0.0git (https:/github.com/llvm/llvm-project bc9823cf60bf91cc8b45248c4205cd2c67b2a3d5)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/david/projects/pxl_sdk3/thirdparty/emsdk/upstream/bin

Failing command line in full:

npm --loglevel verbose --prefix extras/bindings/wasm/npm-package ci
npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@10.2.5
npm info using node@v20.5.0
npm verb title npm ci
npm verb argv "--loglevel" "verbose" "--prefix" "extras/bindings/wasm/npm-package" "ci"
npm verb logfile logs-max:10 dir:/home/david/.npm/_logs/2024-09-30T08_20_06_751Z-
npm verb logfile /home/david/.npm/_logs/2024-09-30T08_20_06_751Z-debug-0.log
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/fsevents
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/win32-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/win32-ia32
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/win32-arm64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/sunos-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/openbsd-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/netbsd-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-s390x
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-riscv64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-ppc64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-mips64el
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-loong64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-ia32
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-arm64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/linux-arm
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/freebsd-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/freebsd-arm64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/darwin-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/darwin-arm64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/android-x64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/android-arm64
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/android-arm
npm verb reify failed optional dependency /home/david/projects/pxl_sdk3/extras/bindings/wasm/npm-package/node_modules/@esbuild/aix-ppc64
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 391ms
npm http fetch GET 200 https://registry.npmjs.org/xml2js 129ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/phin 144ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/tar 159ms (cache revalidated)
npm info run canvas@2.11.2 install node_modules/canvas node-pre-gyp install --fallback-to-build --update-binary
npm http fetch GET 200 https://registry.npmjs.org/load-bmfont 31ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@mapbox%2fnode-pre-gyp 57ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/parse-bmfont-xml 63ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@jimp%2fplugin-print 67ms (cache revalidated)
npm info run canvas@2.11.2 install { code: 0, signal: null }
npm info run esbuild@0.19.12 postinstall node_modules/esbuild node install.js
npm info run esbuild@0.19.12 postinstall { code: 0, signal: null }

added 176 packages, and audited 177 packages in 2s

34 packages are looking for funding
  run `npm fund` for details

5 moderate severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit` for details.
npm verb exit 0
npm info ok
npm --loglevel verbose --prefix extras/bindings/wasm/npm-package run build
npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@10.2.5
npm info using node@v20.5.0
npm verb title npm run build
npm verb argv "--loglevel" "verbose" "--prefix" "extras/bindings/wasm/npm-package" "run" "build"
npm verb logfile logs-max:10 dir:/home/david/.npm/_logs/2024-09-30T08_20_09_049Z-
npm verb logfile /home/david/.npm/_logs/2024-09-30T08_20_09_049Z-debug-0.log

> @pxlvision/pxl-wasm@0.0.0 build
> tsc && cp src/pxl_sdk_wasm.wasm build/pxl_sdk_wasm.wasm

src/autogenerated_types.ts:58:25 - error TS2391: Function implementation is missing or not immediately following the declaration.

58 export default function MainModuleFactory (options?: unknown): Promise<MainModule>;
                           ~~~~~~~~~~~~~~~~~

Found 1 error in src/autogenerated_types.ts:58

npm verb exit 2
npm verb code 2

em++ invocation:

em++ -fdiagnostics-color=always -O3 -Wall -Wextra -pedantic -Wno-int-in-bool-context -Wno-deprecated-copy -fPIC -fexceptions -pthread -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG -sEXPORTED_FUNCTIONS=['_malloc','_free'] -sINITIAL_MEMORY=512mb -sALLOW_MEMORY_GROWTH -sMODULARIZE -sWASM_ASYNC_COMPILATION=1 -sEXPORT_ES6 -sDISABLE_EXCEPTION_CATCHING=0 -sWASM=1 -pthread -lembind --embind-emit-tsd autogenerated_types.ts --embed-file /home/david/projects/pxl_sdk3/data/models/corner_detection@/data/models/corner_detection extras/bindings/wasm/CMakeFiles/pxl_sdk_wasm.dir/src/main.cpp.o extras/bindings/wasm/CMakeFiles/pxl_sdk_wasm.dir/src/utils.cpp.o -o extras/bindings/wasm/pxl_sdk_wasm.js  ...libs...
brendandahl commented 1 month ago

The TSC definitions should be usable without any extra work. Are you able to attach src/autogenerated_types.ts or attach/link to a way I can reproduce the error?

dav1d-wright commented 3 weeks ago

@brendandahl Thank you for the prompt feedback, I am currently trying to put together an MRE that reproduces this issue. I'm afraid I don't think I can disclose any code as this is protected by IP. My first attempts to reproduce have unfortunately failed, as compilation seems to work. I will get back if I manage to reproduce it.

dav1d-wright commented 3 weeks ago

I did manage to reproduce the issue after all. It seems that the npm build behaves differently depending on whether the file is called autogenerated_types.ts or autogenerated_types.d.ts. The former fails the build, the latter passes the build. As I'm not JS expert, I don't know if this is obvious behaviour or not.

emscripten_mre.zip

I hope this helps. For now this workaround does the trick for us, so no urgency from our side. If there is anything else I can provide, just let me know!

And also: thanks for your work on this project :saluting_face: