emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Improve MainModuleFactory type emitted by create_tsd

Open s-h-a-d-o-w opened this issue 7 months ago • 13 comments
trafficstars

This is in accordance with the type on DefinitelyTyped.

s-h-a-d-o-w avatar Apr 10 '25 09:04 s-h-a-d-o-w

Looks you likely need to run some tests with --rebaseline

sbc100 avatar Apr 10 '25 16:04 sbc100

Whoops, should've thought about there being tests for this. Sorry about that.

Since I will need to set up the whole toolchain to run that, it's going to take a bit though.

s-h-a-d-o-w avatar Apr 10 '25 16:04 s-h-a-d-o-w

The way I recommend doing it is emsdk install tot && emsdk activate tot then export EM_CONFIG=/path/to/emsdk/.emscripten

sbc100 avatar Apr 10 '25 16:04 sbc100

Thanks but I'm on windows, without LLVM or clang. :sweat_smile:

s-h-a-d-o-w avatar Apr 10 '25 17:04 s-h-a-d-o-w

Thanks but I'm on windows, without LLVM or clang. 😅

emsdk install tot takes care of installing all that for you at the correct version.

sbc100 avatar Apr 10 '25 17:04 sbc100

I'm happy to do that rebase for you if install emsdk is too much? (But how are you running emscripten then?

sbc100 avatar Apr 10 '25 17:04 sbc100

Nah, it was just a oversight - I forgot to set the env variable like you told me to. It works great!

s-h-a-d-o-w avatar Apr 10 '25 17:04 s-h-a-d-o-w

So... running with --rebaseline logs nothing to the console and changes no files. It also finishes running very quickly. Should it?

I'm not confident that everything works as intended because when I run random tests, many fail, e.g.:

  File "C:\Users\andy\temp\emsdk\python\3.9.2-nuget_64bit\lib\unittest\case.py", line 670, in fail
    raise self.failureException(msg)
AssertionError: either d8 or node >= 24 required to run wasm64 tests.  Use EMTEST_SKIP_WASM64 to skip

Which is interesting given that "Current" node is 23.

Anyway... I only stumbled across this randomly and usually don't use emscripten, so it's probably easiest for both of us if you run that. Thanks for offering that!

s-h-a-d-o-w avatar Apr 10 '25 18:04 s-h-a-d-o-w

Actually I was chatting with @brendandahl and we think maybe the DefinitelyTyped definition is wrong here. We really want something that is a object/dictionary that matches INCOMING_MODULE_JS_API.

sbc100 avatar Apr 10 '25 18:04 sbc100

We can maybe land this for now then move away from it.

BTW, are using using the generated types in combination with DefinitelyTyped somehow? Should we try to update to delete what is stored in DefinitelyTyped?

sbc100 avatar Apr 10 '25 18:04 sbc100

No but thanks for asking!

(Long story: I arrived here from trying to improve the tree sitter TypeScript types, which are currently not in the best shape. I stumbled across this PR and thought that maybe it didn't get any attention because of the missing PR description or maybe because it didn't address the problem at the root, so I tried to. I saw that the factory type in DefinitelyType has existed for at least 5 years and was discussed 5 years ago, so assumed that it was correct. But then I realized that vemoo was right and the types in tree sitter weren't actually generated using emscripten. And that my problem was much simpler anyway and the type problems in tree sitter don't affect me. So I decided to leave these problems be and refocus on my own work.)

s-h-a-d-o-w avatar Apr 12 '25 12:04 s-h-a-d-o-w

@brendandahl should file a bug to have https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts removed? It seems like emscripten-generated types via --emit-tsc are always going to better, and anything checked into DefinitelyTyped likely never going to be up-to-date or match the interface of any specific emscripten output.

sbc100 avatar Apr 14 '25 16:04 sbc100

@brendandahl should file a bug to have https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts removed? It seems like emscripten-generated types via --emit-tsc are always going to better, and anything checked into DefinitelyTyped likely never going to be up-to-date or match the interface of any specific emscripten output.

Yeah, I can do that. It looks like that file as some better typing information for a few interfaces that we could pull over and put in the JS doc comments for the library (which will then generate TS definitions).

brendandahl avatar Apr 14 '25 22:04 brendandahl