dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.38k stars 192 forks source link

[NativeAOT LLVM] Integrate dotnet.js into ILCompiler.LLVM #2453

Closed maraf closed 8 months ago

maraf commented 8 months ago
SingleAccretion commented 8 months ago

A couple general questions, to start things off.

1) What is the general code flow (dependency graph) of the JS code? For example, here's the detailed graph for the current runtime:

Emscripten-generated code (host)
  [Emscripten ABI]
    Native entry point from bootstrapper.cpp
      <application code>
      [Emscripten ABI]
        pal_random.js; --js-library
        emscripten_get_callstack; Emscripten-provided system function

This needn't be as detailed, I am just looking for what the major components are, what their responsibilities are, and where they live (/how the functions they consist of are called).

2) What are the components in the build process of JS components? What is the build flow? How do you debug that build? Any common gotchas/known issues w.r.t. local development? We spend a very good chunk of our time fixing or altering the build in one way or another on this branch, so it's important to know how it works.

pavelsavara commented 8 months ago
    pal_random.js; --js-library

this doesn't exist anymore. It's moved into src\mono\wasm\runtime\crypto.ts

SingleAccretion commented 8 months ago

this doesn't exist anymore. It's moved into src\mono\wasm\runtime\crypto.ts

Yes; we restored it in this branch for the time being.

SingleAccretion commented 8 months ago

Add sample running main with dotnet.js

This should be added as a smoke test under src/tests/nativeaot/SmokeTests/HelloWasm.

pavelsavara commented 8 months ago

FYI https://github.com/dotnet/runtime/pull/95775 we are refactoring those proj quite often. I'm not sure that optimizing it here makes ton of sense from merging perspective.

SingleAccretion commented 8 months ago

I'm not sure that optimizing it here makes ton of sense from merging perspective.

Since we decided to keep a copy (of the compiler options-related MSBuild things), there is no conflict risk. There is still the problem of keeping the copy up-to-date, but it's the same whether we simplify it or not. And a number of these options have to be rewritten in any case.

maraf commented 8 months ago

1) What is the general code flow (dependency graph) of the JS code?

In browser case and the new smoke test concretely, it is

2) What are the components in the build process of JS components? What is the build flow? How do you debug that build? Any common gotchas/known issues w.r.t. local development? We spend a very good chunk of our time fixing or altering the build in one way or another on this branch, so it's important to know how it works.

Typescript is built using rollup. In debug build we get unminified version. In release they are minified. In both cases there are source maps pointing to original typescript definitions.

Does it answer the questions?

SingleAccretion commented 8 months ago

Does it answer the questions?

Yes, thank you.

yowl commented 8 months ago

Very interesting, great work. Is it too early to add anything to the docs, like adding this to your project file if you want to use it

<DotNetJsApi>true</DotNetJsApi>

Are people going to think that [JSImport]/[JSExport] are supported with this change in NativeAOT-LLVM ?

maraf commented 8 months ago

Are people going to think that [JSImport]/[JSExport] are supported with this change in NativeAOT-LLVM ?

JS interop is tracked here https://github.com/dotnet/runtimelab/issues/2434. I'll make it work as separated PRs. All that's working now is (synchronously) calling Main

Very interesting, great work. Is it too early to add anything to the docs, like adding this to your project file if you want to use it

I would wait a bit until there are more features working