-
Notifications
You must be signed in to change notification settings - Fork 3
Actually use our linker as the linker for sample/fastLinkJS. #47
Conversation
5a392db
to
4d9423d
Compare
We will need the Wasm backend to be built for 2.12.x in order to load it as a true linker from the sbt build.
This way, we do not depend on Scala.js-specific APIs.
An `OutputDirectory` is not supposed to be shared.
And delete stray files in the output directories, as is mandated by the contract of a linker backend.
This follows the architecture of the Scala.js linker.
In addition to emitting the `.wasm` and `.wat` files in the output directory, we now also emit emit the internal `__loader.js` file, and the public module specified by the `ModuleSet`, such as `main.js`. We embed the content of the loader as a constant string in the backend, so that it works both on the JVM and on JS. Eventually, we will probably generate it more dynamically from `backend.javascript.Trees` anyway, so this not really a big deal. This change requires to adapt the loading mechanism to force URL resolution against the base directory of the `loader.js` file, rather than the working directly. We do this thanks to `import.meta.url`, which is also available in browsers. As is, this change destroys the semantics of top-level exported `var`s. Mutations performed after the module initializers have completed will not be reflected in the exports of `main.js`. We will need to revisit this later on, with a technique similar to the one used by the JS backend. With these changes, our linker backend actually abides by the specification of a `LinkerBackend`, which means we will be able to directly use it from sbt.
4d9423d
to
073715d
Compare
Rebased on top of #50. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one comment, but otherwise looks good to me, great job!
feel free to merge this PR once you address the comment (if it's required)
cli/src/main/scala/Main.scala
Outdated
val linker = WebAssemblyLinkerImpl.linker(linkerConfig) | ||
val outputDir = "./target/sample/" | ||
createDir(outputDir) | ||
val output = NodeOutputDirectory(outputDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else
branch is no longer needed. When we run sample/fastLinkJS
, it's going to be handled by WasmLInkerPlugin
.
Maybe we can remove this branch? I was a bit confused why sample/fastLinkJS
doesn't generate output under ./target/sample
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I removed it.
Now, `sample/fastLinkJS` uses our WebAssembly linker, and `sample/run` actually executes the `main` method of the sample project, linked to WebAssembly.
073715d
to
b1b51ed
Compare
Draft, just to get the CI to run.Main changes:
wasm
project.Compiler
into a linker that actually implements theLinker
andLinkerBackend
interfaces of Scala.js.sample
project to use our WebAssembly linker insample/fastLinkJS
(and therefore insample/run
).