Skip to content

Commit

Permalink
Merge branch 'main' into out-folder-content-reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
rahat2134 authored Nov 5, 2024
2 parents 6e391b5 + 9d11962 commit 5caff3e
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 38 deletions.
51 changes: 47 additions & 4 deletions .github/workflows/publish-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,34 @@ concurrency:
cancel-in-progress: true

jobs:
build-artifacts:
# when in master repo, publish all tags and manual runs on main
if: github.repository == 'com-lihaoyi/mill'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}

- uses: coursier/cache-action@v6

- uses: actions/setup-java@v4
with:
java-version: '11'
distribution: temurin

- run: ./mill -i __.publishArtifacts

- uses: actions/upload-artifact@v4.4.3
with:
path: .
include-hidden-files: true
name: publish-artifacts

publish-sonatype:
# when in master repo, publish all tags and manual runs on main
if: github.repository == 'com-lihaoyi/mill'
needs: build-artifacts
runs-on: ubuntu-latest

# only run one publish job for the same sha at the same time
Expand All @@ -40,8 +65,17 @@ jobs:
LC_ALL: "en_US.UTF-8"

steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: actions/download-artifact@v4
with:
path: .
name: publish-artifacts

- run: ls -la .

# Need to fix cached artifact file permissions because github actions screws it up
# https://github.com/actions/upload-artifact/issues/38
# Best is, we restore any file to avoid any changes
- run: git reset --hard

- uses: coursier/cache-action@v6

Expand All @@ -62,8 +96,17 @@ jobs:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}

steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: actions/download-artifact@v4
with:
path: .
name: publish-artifacts

- run: ls -la .

# Need to fix cached artifact file permissions because github actions screws it up
# https://github.com/actions/upload-artifact/issues/38
# Best is, we restore any file to avoid any changes
- run: git reset --hard

- uses: coursier/cache-action@v6

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/run-mill-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
java-version: ${{ inputs.java-version }}
distribution: temurin

- uses: actions/setup-node@v4
with:
node-version: '22'


- name: Prepare git config
run: |
git config --global user.name "Mill GithHub Actions"
Expand All @@ -69,7 +74,7 @@ jobs:

- name: Run Mill '${{ inputs.millargs }}'
# Mill tests are pretty heavy so run them only 3x parallel on 4 core Github Actions runners
run: ./mill -i -j3 -k ${{ inputs.millargs }}
run: ./mill -i -j3 -k ${{ inputs.millargs }}
if: inputs.millargs != '' && !startsWith(inputs.os, 'windows')

- name: Run Mill (on Windows) '${{ inputs.millargs }}'
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/scala-steward.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
schedule:
- cron: '0 0 * * *' # daily
workflow_dispatch:

name: Scala Steward

permissions:
contents: write
pull-requests: write

jobs:
scala-steward:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- uses: scala-steward-org/scala-steward-action@v2.71.0
6 changes: 5 additions & 1 deletion docs/modules/ROOT/pages/scalalib/web-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ include::partial$example/scalalib/web/6-cross-version-platform-publishing.adoc[]

== Publishing Cross-Platform Scala Modules Alternative

include::partial$example/scalalib/web/7-cross-platform-version-publishing.adoc[]
include::partial$example/scalalib/web/7-cross-platform-version-publishing.adoc[]

== Scala.js WebAssembly Example

include::partial$example/scalalib/web/8-wasm.adoc[]
5 changes: 2 additions & 3 deletions example/scalalib/native/1-simple/src/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import mainargs.{main, ParserForMethods}

object Foo {

def generateHtml(text: String): CString = {
def generateHtml(text: String) (using Zone) = {
val html = "<h1>" + text + "</h1>\n"

implicit val z: Zone = Zone.open()
val cResult = toCString(html)
cResult

}

@main
def main(text: String) = {
def main(text: String) = Zone {
stdio.printf(generateHtml(text))
}

Expand Down
3 changes: 1 addition & 2 deletions example/scalalib/native/3-multi-module/bar/src/Bar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import scala.scalanative.libc._
import scala.scalanative.unsafe._

object Bar {
def main(args: Array[String]): Unit = {
def main(args: Array[String]): Unit = Zone {
println("Running HelloWorld function")
implicit val z: Zone = Zone.open()
val result = toCString(args(0))
val barValue = HelloWorldBar.stringLength(result)
stdio.printf(c"Bar value: Argument length is %i\n", barValue)
Expand Down
3 changes: 1 addition & 2 deletions example/scalalib/native/3-multi-module/foo/src/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import mainargs.{main, ParserForMethods, arg}
object Foo {
@main
def main(@arg(name = "foo-text") fooText: String,
@arg(name = "bar-text") barText: String): Unit = {
@arg(name = "bar-text") barText: String): Unit = Zone {

implicit val z: Zone = Zone.open()
val cFooText = toCString(fooText)
val cBarText = toCString(barText)

Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/native/4-common-config/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object `package` extends RootModule with ScalaNativeModule {

> ./mill run
...
Foo.value: <h1>hello</h1>
Value: <h1>hello</h1>

> ./mill show releaseMode
"mill.scalanativelib.api.ReleaseMode.ReleaseFast"
Expand Down
10 changes: 4 additions & 6 deletions example/scalalib/native/4-common-config/src/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import fansi._

object Foo {

def generateHtml(text: String): CString = {
def generateHtml(text: String) (using Zone) = {
val colored = Console.RED + "<h1>" + text + "</h1>" + Console.RESET

implicit val z: Zone = Zone.open()
val cResult = toCString(colored)
cResult
}

val value = generateHtml("hello")

def main(args: Array[String]): Unit = {
stdio.printf(c"Foo.value: %s\n", Foo.value)
def main(args: Array[String]): Unit = Zone {
val value = generateHtml("hello")
stdio.printf(c"Value: %s\n", value)
}
}

42 changes: 42 additions & 0 deletions example/scalalib/web/8-wasm/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package build
import mill._, scalalib._, scalajslib._
import mill.scalajslib.api._


object wasm extends ScalaJSModule {
override def scalaVersion = "2.13.14"

override def scalaJSVersion = "1.17.0"

override def moduleKind = ModuleKind.ESModule

override def moduleSplitStyle = ModuleSplitStyle.FewestModules

override def scalaJSExperimentalUseWebAssembly = true
}

// This build defines a single `ScalaJSModule` that uses the `WASM` backend of the scala JS linker.
// The release notes that introduced scalaJS wasm are here;
// https://www.scala-js.org/news/2024/09/28/announcing-scalajs-1.17.0/
// and are worth reading. They include information such as the scala JS requirements to successfully emit wasm,
// the flags needed to run in browser and the minimum node version (22) required to actually run the wasm output.

/** Usage

> ./mill show wasm.fastLinkJS # mac/linux
{
...
..."jsFileName": "main.js",
...
"dest": ".../out/wasm/fastLinkJS.dest"
}

> node --experimental-wasm-exnref out/wasm/fastLinkJS.dest/main.js # mac/linux
hello wasm!

*/

// Here we see that scala JS emits a single WASM module, as well as a loader and main.js file.
// `main.js` is the entry point of the program, and calls into the wasm module.


7 changes: 7 additions & 0 deletions example/scalalib/web/8-wasm/wasm/src/hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wasm

object wasm {
def main(args: Array[String]): Unit = {
println("hello wasm!")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hello.tests

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import hello.getHelloString

class FooTest : FunSpec({
test("testFailure") {
getHelloString() shouldBe "Hello, world!"
}

test("testSuccess") {
getHelloString() shouldBe "WRONG!"
}
})
22 changes: 22 additions & 0 deletions kotlinlib/test/src/mill/kotlinlib/HelloWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ object HelloWorldTests extends TestSuite {
ivy"org.jetbrains.kotlin:kotlin-test-junit:${this.kotlinVersion()}"
)
}
object kotest extends KotlinTests with TestModule.Junit5 {
override def ivyDeps = super.ivyDeps() ++ Agg(
ivy"io.kotest:kotest-runner-junit5-jvm:5.9.1"
)
}
}
object main extends Cross[MainCross](kotlinVersions)
}
Expand Down Expand Up @@ -68,6 +73,23 @@ object HelloWorldTests extends TestSuite {
)
})
}
test("kotest") {
val eval = testEval()

HelloWorldKotlin.main.crossModules.foreach(m => {
val Right(discovered) = eval.apply(m.kotest.discoveredTestClasses)
assert(discovered.value == Seq("hello.tests.FooTest"))

val Left(Result.Failure(_, Some(v1))) = eval.apply(m.kotest.test())

assert(
v1._2(0).fullyQualifiedName == "hello.tests.FooTest",
v1._2(0).status == "Success",
v1._2(1).fullyQualifiedName == "hello.tests.FooTest",
v1._2(1).status == "Failure"
)
})
}
test("failures") {
val eval = testEval()

Expand Down
2 changes: 1 addition & 1 deletion readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ You can reproduce any of the tests manually using `dist.run`, e.g.

[source,bash]
----
./mill "example.basic[1-simple].local"
./mill "example.javalib.basic[1-simple].local"
----

**Manual Test**
Expand Down
27 changes: 23 additions & 4 deletions scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
moduleSplitStyle = moduleSplitStyle(),
outputPatterns = scalaJSOutputPatterns(),
minify = scalaJSMinify(),
importMap = scalaJSImportMap()
importMap = scalaJSImportMap(),
experimentalUseWebAssembly = scalaJSExperimentalUseWebAssembly()
)
}

Expand Down Expand Up @@ -191,7 +192,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
moduleSplitStyle: ModuleSplitStyle,
outputPatterns: OutputPatterns,
minify: Boolean,
importMap: Seq[ESModuleImportMapping]
importMap: Seq[ESModuleImportMapping],
experimentalUseWebAssembly: Boolean
)(implicit ctx: mill.api.Ctx): Result[Report] = {
val outputPath = ctx.dest

Expand All @@ -212,7 +214,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
moduleSplitStyle = moduleSplitStyle,
outputPatterns = outputPatterns,
minify = minify,
importMap = importMap
importMap = importMap,
experimentalUseWebAssembly = experimentalUseWebAssembly
)
}

Expand Down Expand Up @@ -293,6 +296,21 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
/** Whether to emit a source map. */
def scalaJSSourceMap: T[Boolean] = Task { true }

/**
* Specifies whether to use the experimental WebAssembly backend.. Requires scalaJS > 1.17.0
* When using this setting, the following properties must also hold:
*
* - `moduleKind = ModuleKind.ESModule`
* - `moduleSplitStyle = ModuleSplitStyle.FewestModules`
*
* @note
* Currently, the WebAssembly backend silently ignores `@JSExport` and
* `@JSExportAll` annotations. This behavior may change in the future,
* either by making them warnings or errors, or by adding support for them.
* All other language features are supported.
*/
def scalaJSExperimentalUseWebAssembly: T[Boolean] = Task { false }

/** Name patterns for output. */
def scalaJSOutputPatterns: T[OutputPatterns] = Task { OutputPatterns.Defaults }

Expand Down Expand Up @@ -370,7 +388,8 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule {
moduleSplitStyle = moduleSplitStyle(),
outputPatterns = scalaJSOutputPatterns(),
minify = scalaJSMinify(),
importMap = scalaJSImportMap()
importMap = scalaJSImportMap(),
experimentalUseWebAssembly = scalaJSExperimentalUseWebAssembly()
)
}

Expand Down
6 changes: 4 additions & 2 deletions scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable {
moduleSplitStyle: api.ModuleSplitStyle,
outputPatterns: api.OutputPatterns,
minify: Boolean,
importMap: Seq[api.ESModuleImportMapping]
importMap: Seq[api.ESModuleImportMapping],
experimentalUseWebAssembly: Boolean
)(implicit ctx: Ctx.Home): Result[api.Report] = {
bridge(toolsClasspath).link(
runClasspath = runClasspath.iterator.map(_.path.toNIO).toSeq,
Expand All @@ -185,7 +186,8 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable {
moduleSplitStyle = toWorkerApi(moduleSplitStyle),
outputPatterns = toWorkerApi(outputPatterns),
minify = minify,
importMap = importMap.map(toWorkerApi)
importMap = importMap.map(toWorkerApi),
experimentalUseWebAssembly = experimentalUseWebAssembly
) match {
case Right(report) => Result.Success(fromWorkerApi(report))
case Left(message) => Result.Failure(message)
Expand Down
Loading

0 comments on commit 5caff3e

Please sign in to comment.