This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually use our linker as the linker for
sample/fastLinkJS
.
Now, `sample/fastLinkJS` uses our WebAssembly linker, and `sample/run` actually executes the `main` method of the sample project, linked to WebAssembly.
- Loading branch information
Showing
6 changed files
with
103 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package build | ||
|
||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
import org.scalajs.linker._ | ||
import org.scalajs.linker.interface.{ModuleKind, _} | ||
|
||
import org.scalajs.sbtplugin._ | ||
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ | ||
|
||
object WasmLinkerPlugin extends AutoPlugin { | ||
override lazy val requires = ScalaJSPlugin | ||
|
||
/** A `LinkerImpl` that reflectively loads our `WebAssemblyLinkerImpl`. */ | ||
private class WasmLinkerImpl(base: LinkerImpl.Reflect) | ||
extends LinkerImpl.Forwarding(base) { | ||
|
||
private val loader = base.loader | ||
|
||
private val clearableLinkerMethod = { | ||
Class.forName("wasm.WebAssemblyLinkerImpl", true, loader) | ||
.getMethod("clearableLinker", classOf[StandardConfig]) | ||
} | ||
|
||
override def clearableLinker(config: StandardConfig): ClearableLinker = | ||
clearableLinkerMethod.invoke(null, config).asInstanceOf[ClearableLinker] | ||
} | ||
|
||
override def projectSettings: Seq[Setting[_]] = Def.settings( | ||
// Use a separate cache box for the LinkerImpl in this project (don't use the Global one) | ||
scalaJSLinkerImplBox := new CacheBox, | ||
|
||
// Use our custom WasmLinkerImpl as the linker implementation used by fast/fullLinkJS | ||
scalaJSLinkerImpl := { | ||
val cp = (scalaJSLinkerImpl / fullClasspath).value | ||
scalaJSLinkerImplBox.value.ensure { | ||
new WasmLinkerImpl(LinkerImpl.reflect(Attributed.data(cp))) | ||
} | ||
}, | ||
|
||
// Automatically install all the configs required by the Wasm backend | ||
scalaJSLinkerConfig ~= { prev => | ||
prev | ||
.withModuleKind(ModuleKind.ESModule) | ||
.withSemantics(_.optimized) | ||
.withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs")) | ||
.withOptimizer(false) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters