From 11bbc2de38178951d6d8be7f1a30fb336b100805 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 21:41:16 +0200 Subject: [PATCH 1/7] test passes --- cli/src/org/scalajs/cli/Scalajsld.scala | 32 +++++++++- .../src/org/scalajs/cli/tests/Tests.scala | 60 +++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/cli/src/org/scalajs/cli/Scalajsld.scala b/cli/src/org/scalajs/cli/Scalajsld.scala index 4daac42..b5ee220 100644 --- a/cli/src/org/scalajs/cli/Scalajsld.scala +++ b/cli/src/org/scalajs/cli/Scalajsld.scala @@ -54,7 +54,8 @@ object Scalajsld { jsHeader: String = "", logLevel: Level = Level.Info, importMap: Option[File] = None, - longRunning: Boolean = false + longRunning: Boolean = false, + emitWasm: Boolean = false ) private def moduleInitializer( @@ -238,6 +239,9 @@ object Scalajsld { opt[Unit]("longRunning") .action { (_, c) => c.copy(longRunning = true) } .text("Run linking incrementally every time a line is printed to stdin") + opt[Unit]("emitWasm") + .action { (_, c) => c.copy(emitWasm = true) } + .text("Run linking incrementally every time a line is printed to stdin") opt[Unit]('d', "debug") .action { (_, c) => c.copy(logLevel = Level.Debug) } .text("Debug mode: Show full log") @@ -277,13 +281,32 @@ object Scalajsld { } } } - val allValidations = Seq(outputCheck, importMapCheck) + + val wasEsModule = c.emitWasm match { + case true => + if (c.moduleKind != ModuleKind.ESModule) { + failure("Wasm can only be emitted with module kind EsModule") + } else success + case false => success + } + + val wasmFewestModules = c.emitWasm match { + case true => { + if (c.moduleSplitStyle != ModuleSplitStyle.FewestModules.toString) { + failure("Wasm can only be emitted with module split style FewestModules") + } else success + } + case false => success + } + + val allValidations = Seq(outputCheck, importMapCheck, wasEsModule, wasmFewestModules) allValidations.forall(_.isRight) match { case true => success case false => failure(allValidations.filter(_.isLeft).map(_.left.get).mkString("\n\n")) } } + override def showUsageOnError = Some(true) } @@ -319,6 +342,10 @@ object Scalajsld { .withBatchMode(true) .withJSHeader(options.jsHeader) .withMinify(options.fullOpt) + .withExperimentalUseWebAssembly(options.emitWasm) + + println(options) + println(config) val linker = StandardImpl.linker(config) val logger = new ScalaConsoleLogger(options.logLevel) @@ -347,6 +374,7 @@ object Scalajsld { logger ) case (None, Some(outputDir)) => + println(outputDir.toPath()) linker.link( irImportMappedFiles, moduleInitializers, diff --git a/tests/test/src/org/scalajs/cli/tests/Tests.scala b/tests/test/src/org/scalajs/cli/tests/Tests.scala index 8a4bc84..e1b9f66 100644 --- a/tests/test/src/org/scalajs/cli/tests/Tests.scala +++ b/tests/test/src/org/scalajs/cli/tests/Tests.scala @@ -498,4 +498,64 @@ class Tests extends munit.FunSuite { val rawJs = os.read.lines(dir / "out" / "main.js") assert(rawJs(1).contains(substTo)) } + + + test("wasm flag emits wasm") { + val dir = os.temp.dir() + os.write( + dir / "foo.scala", + """object Foo { + | def main(args: Array[String]): Unit = { + | println("Hello") + | } + | + |} + |""".stripMargin + ) + + val scalaJsLibraryCp = getScalaJsLibraryCp(dir) + + os.makeDir.all(dir / "bin") + os.proc( + "cs", + "launch", + "scalac:2.13.15", + "--", + "-classpath", + scalaJsLibraryCp, + s"-Xplugin:${getScalaJsCompilerPlugin(dir)}", + "-d", + "bin", + "foo.scala" + ).call(cwd = dir, stdin = os.Inherit, stdout = os.Inherit) + + os.makeDir.all(dir / "out") + val res = os + .proc( + launcher, + "--stdlib", + scalaJsLibraryCp, + "-s", + "--emitWasm", + "--moduleKind", + "ESModule", + "--moduleSplitStyle", + "FewestModules", + "--outputDir", + "out", + "-mm", + "Foo.main", + "bin" + ) + .call(cwd = dir, mergeErrIntoOut = true) + + os.walk(dir).foreach(println) + val testSize = os.size(dir / "out" / "main.wasm") + val testMapSize = os.size(dir / "out" / "main.wasm.map") + assert(testSize > 0) + assert(testMapSize > 0) + + val res2 = os.proc("node", "--experimental-wasm-exnref", "main.js").call(cwd = dir / "out", check = true, stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit) + println(res2.out) + } } From acd7f06cd247894d07bcedc866b8114148996703 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 21:45:04 +0200 Subject: [PATCH 2/7] remove printlns --- cli/src/org/scalajs/cli/Scalajsld.scala | 5 +---- tests/test/src/org/scalajs/cli/tests/Tests.scala | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cli/src/org/scalajs/cli/Scalajsld.scala b/cli/src/org/scalajs/cli/Scalajsld.scala index b5ee220..0701dd7 100644 --- a/cli/src/org/scalajs/cli/Scalajsld.scala +++ b/cli/src/org/scalajs/cli/Scalajsld.scala @@ -344,9 +344,6 @@ object Scalajsld { .withMinify(options.fullOpt) .withExperimentalUseWebAssembly(options.emitWasm) - println(options) - println(config) - val linker = StandardImpl.linker(config) val logger = new ScalaConsoleLogger(options.logLevel) val cache = StandardImpl.irFileCache().newCache @@ -374,7 +371,7 @@ object Scalajsld { logger ) case (None, Some(outputDir)) => - println(outputDir.toPath()) + linker.link( irImportMappedFiles, moduleInitializers, diff --git a/tests/test/src/org/scalajs/cli/tests/Tests.scala b/tests/test/src/org/scalajs/cli/tests/Tests.scala index e1b9f66..e61ea17 100644 --- a/tests/test/src/org/scalajs/cli/tests/Tests.scala +++ b/tests/test/src/org/scalajs/cli/tests/Tests.scala @@ -555,7 +555,7 @@ class Tests extends munit.FunSuite { assert(testSize > 0) assert(testMapSize > 0) - val res2 = os.proc("node", "--experimental-wasm-exnref", "main.js").call(cwd = dir / "out", check = true, stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit) - println(res2.out) + os.proc("node", "--experimental-wasm-exnref", "main.js").call(cwd = dir / "out", check = true, stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit) + } } From f32f242f5e9fa20da5d337354a668a1a79c4473c Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 21:46:39 +0200 Subject: [PATCH 3/7] fix cli doc --- cli/src/org/scalajs/cli/Scalajsld.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/org/scalajs/cli/Scalajsld.scala b/cli/src/org/scalajs/cli/Scalajsld.scala index 0701dd7..e288f4a 100644 --- a/cli/src/org/scalajs/cli/Scalajsld.scala +++ b/cli/src/org/scalajs/cli/Scalajsld.scala @@ -241,7 +241,7 @@ object Scalajsld { .text("Run linking incrementally every time a line is printed to stdin") opt[Unit]("emitWasm") .action { (_, c) => c.copy(emitWasm = true) } - .text("Run linking incrementally every time a line is printed to stdin") + .text("If present, use the _experimental_ web assembly backend in the linker") opt[Unit]('d', "debug") .action { (_, c) => c.copy(logLevel = Level.Debug) } .text("Debug mode: Show full log") From 9d96630547f4a99e313a6638808fc788a45bf671 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 21:53:53 +0200 Subject: [PATCH 4/7] Node 22. Hail mary. --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08cc7d8..49c5592 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,9 @@ jobs: - uses: VirtusLab/scala-cli-setup@9bc68588ab2d49dae03e5395a5f411e20914f97e with: jvm: "temurin:17" + - uses: actions/setup-node@v2 + with: + node-version: '22' - name: Test CLI run: ./mill -i 'tests.test' From 53f5bf18b54f129f42a63126fa4d0aa78b34f1c8 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 21:54:35 +0200 Subject: [PATCH 5/7] . --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49c5592..243c93e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - uses: VirtusLab/scala-cli-setup@9bc68588ab2d49dae03e5395a5f411e20914f97e with: jvm: "temurin:17" - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '22' - name: Test CLI From 3beff49de06ed4e5b56850be347b2dda2ee277a8 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 25 Oct 2024 22:15:52 +0200 Subject: [PATCH 6/7] mode node 22 --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 243c93e..98ceea2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,9 @@ jobs: - uses: coursier/setup-action@v1.2.0-M3 with: jvm: temurin:17 + - uses: actions/setup-node@v4 + with: + node-version: '22' - run: | ./mill -i "native.writeNativeImageScript" generate.sh "" && \ ./generate.sh && \ @@ -101,6 +104,9 @@ jobs: - uses: coursier/setup-action@v1.2.0-M3 with: jvm: temurin:17 + - uses: actions/setup-node@v4 + with: + node-version: '22' - run: | ./mill -i "native-static.writeNativeImageScript" generate.sh "" && \ ./generate.sh && \ @@ -131,6 +137,9 @@ jobs: - uses: coursier/setup-action@v1.2.0-M3 with: jvm: temurin:17 + - uses: actions/setup-node@v4 + with: + node-version: '22' - run: | ./mill -i "native-mostly-static.writeNativeImageScript" generate.sh "" && \ ./generate.sh && \ From 752bb110d0d454a0ade0ccbe0f551fca7c2cf0ee Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Sat, 26 Oct 2024 18:07:01 +0200 Subject: [PATCH 7/7] remove internal validations --- cli/src/org/scalajs/cli/Scalajsld.scala | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/cli/src/org/scalajs/cli/Scalajsld.scala b/cli/src/org/scalajs/cli/Scalajsld.scala index e288f4a..937588d 100644 --- a/cli/src/org/scalajs/cli/Scalajsld.scala +++ b/cli/src/org/scalajs/cli/Scalajsld.scala @@ -282,24 +282,7 @@ object Scalajsld { } } - val wasEsModule = c.emitWasm match { - case true => - if (c.moduleKind != ModuleKind.ESModule) { - failure("Wasm can only be emitted with module kind EsModule") - } else success - case false => success - } - - val wasmFewestModules = c.emitWasm match { - case true => { - if (c.moduleSplitStyle != ModuleSplitStyle.FewestModules.toString) { - failure("Wasm can only be emitted with module split style FewestModules") - } else success - } - case false => success - } - - val allValidations = Seq(outputCheck, importMapCheck, wasEsModule, wasmFewestModules) + val allValidations = Seq(outputCheck, importMapCheck) allValidations.forall(_.isRight) match { case true => success case false => failure(allValidations.filter(_.isLeft).map(_.left.get).mkString("\n\n"))