emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.41k stars 3.26k forks source link

Failed when using --emit-tsd to generate .d.ts from cpp #22181

Closed wangyuanhao11 closed 5 days ago

wangyuanhao11 commented 2 weeks ago

when i use emcc like this:

emcc E:\test.cpp -o test.js -sMODULARIZE -s EXPORT_ES6=1 -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_ALL=1 -lembin d --emit-tsd test.d.ts

The error message it reports is as follows:

emcc: error: 'tsc --outFile C:\Users\BON0027\AppData\Local\Temp\emscripten_temp_1vipmldr\jsdoc.d.ts --declaration --emitDeclarationOnly --allowJs C:\Users\BON0027\AppData\Local\Temp \emscripten_temp_1vipmldr\jsdoc.js' failed: [WinError 2] The system cannot find the file specified.

What is the cause of this and how can I fix it,?any suggestions would be greatly appreciated!

sbc100 commented 2 weeks ago

You need to have the typescript compiler installed on your system. I think the simplest way is to do npm install --g typescript. @brendandahl is this the recommended command? Should we report a more meaningful error when its not in the path?

brendandahl commented 2 weeks ago

We should show an error if the user doesn't have tsc installed or the npm package doesn't exists. In this case, it seems like something is wrong with the typescript that is currently installed.

sbc100 commented 2 weeks ago

@wangyuanhao11, what happens if you type tsc? How about where tsc?

wangyuanhao11 commented 2 weeks ago

I have installed ts and the where tsc is : C:\Program Files\nodejs\tsc C:\Program Files\nodejs\tsc.cmd

i tried :

docker run --rm -it -v ./src:/src -u $(id -u):$(id -g) \ emscripten/emsdk bash -c "npm i -g typescript && \ emcc hello.cpp -o hello.js -lembind -sEXPORT_ES6=1 --emit-tsd hello.d.ts"

I have tried to follow the official documentation and I think my ts has been installed successfully,But it's the same error. So this error doesn't make sense?

wangyuanhao11 commented 2 weeks ago

I have installed tsc and i tried according to https://github.com/emscripten-core/emscripten/blob/main/site/source/docs/porting/connecting_cpp_and_javascript/embind.rst#typescript-definitions but it doesn't work. How can I solve this problem, any help would be greatly appreciated!@sbc100 @brendandahl

sbc100 commented 2 weeks ago

What happens if you run tsc --version?

sbc100 commented 2 weeks ago

i tried :

docker run --rm -it -v ./src:/src -u (id−u):(id -g) emscripten/emsdk bash -c "npm i -g typescript && emcc hello.cpp -o hello.js -lembind -sEXPORT_ES6=1 --emit-tsd hello.d.ts"

I have tried to follow the official documentation and I think my ts has been installed successfully,But it's the same error. So this error doesn't make sense?

Can you share the full error output of this docker command?

I was able to run a very similar docker command without issue:

sbc.cloudtop (~/dev/wasm/emscripten) (add_missing_dep) $ docker run --rm -it -v $PWD/test:/test -w /test emscripten/emsdk bash -c "npm i -g typescript && emcc hello_world.c -o hello.js -lembind -sEXPORT_ES6=1 --emit-tsd hello.d.ts"

added 1 package in 1s
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice To update run: npm install -g npm@10.8.1
npm notice
cache:INFO: generating system asset: symbol_lists/8dd3d5931e463083fcb91208f818703415533cbe.json... (this will be cached in "/emsdk/upstream/emscripten/cache/symbol_lists/8dd3d5931e463083fcb91208f818703415533cbe.json" for subsequent builds)
cache:INFO:  - ok
wangyuanhao11 commented 2 weeks ago

my tsc version is:Version 5.5.3 and my emsdk is latest:

E:\emsdk\emsdk>emsdk install latest
  Resolving SDK alias 'latest' to '3.1.62'
  Resolving SDK version '3.1.62' to 'sdk-releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit'
  Installing SDK 'sdk-releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit'..
  Skipped installing node-18.20.3-64bit, already installed.
  Skipped installing python-3.9.2-nuget-64bit, already installed.
  Skipped installing java-8.152-64bit, already installed.
  Skipped installing releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit, already installed.
  All SDK components already installed: 'sdk-releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit'.

  E:\emsdk\emsdk>emsdk activate latest
  Resolving SDK alias 'latest' to '3.1.62'
  Resolving SDK version '3.1.62' to 'sdk-releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit'
  Setting the following tools as active:
     node-18.20.3-64bit
     python-3.9.2-nuget-64bit
     java-8.152-64bit
     releases-d52176ac8e07c47c1773bb2776ebd91e3886c3af-64bit

the error :

cache:INFO: generating system asset: symbol_lists/8dd3d5931e463083fcb91208f818703415533cbe.json... (this will be cached in "E:\emsdk\emsdk\upstream\emscripten\cache\symbol_lists\8dd3d5931e463083fcb91208f818703415533cbe.json" for subsequent builds)
cache:INFO:  - ok
emcc: error: 'tsc --outFile C:\Users\BON0027\AppData\Local\Temp\emscripten_temp_1vipmldr\jsdoc.d.ts --declaration --emitDeclarationOnly --allowJs C:\Users\BON0027\AppData\Local\Temp \emscripten_temp_1vipmldr\jsdoc.js' failed: [WinError 2] The system cannot find the file specified.

@sbc100

sbc100 commented 2 weeks ago

Sorry, just to be clear, you can actually run tsc --version from the command line? But when its run from inside of emcc its not working for some reason.

sbc100 commented 2 weeks ago

As an random experiment, can you try install emsdk on the same drive as your node/tsc installation (C:)?

wangyuanhao11 commented 2 weeks ago
E:\emsdk\emsdk>where tsc
E:\emsdk\emsdk\node\18.20.3_64bit\bin\tsc
E:\emsdk\emsdk\node\18.20.3_64bit\bin\tsc.cmd

E:\emsdk\emsdk>tsc -v
Version 5.5.3

I uninstalled nodejs on the c drive. Now there is only nodejs here. I successfully used emit-tsd on Macos system, but failed on both windows systems. @sbc100

ramgalin commented 1 week ago

I receive same issue: emcc: error: 'tsc --outFile C:\Users\ramdau\AppData\Local\Temp\emscripten_temp_2wtbcpfu\jsdoc.d.ts --declaration --emitDeclarationOnly --allowJs C:\Users\ramdau\AppData\Local\Temp\emscripten_temp_2wtbcpfu\jsdoc.js' failed: [WinError 2] The system cannot find the file specified

Tried npm install --g typescript, didnt help

tsc --version Version 5.5.3