From 9734ce200b6b697bfcea0ba8c613da78d0599bb7 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 12 Sep 2024 12:19:17 +0200 Subject: [PATCH] Allow to publish mdoc-parser for Scala Native --- .github/workflows/ci.yml | 2 +- build.sbt | 19 ++++++++++++++----- .../main/scala/mdoc/parser/MarkdownPart.scala | 0 .../scala/mdoc/parser/ParserSettings.scala | 0 project/plugins.sbt | 4 ++++ 5 files changed, 19 insertions(+), 6 deletions(-) rename parser/{ => shared}/src/main/scala/mdoc/parser/MarkdownPart.scala (100%) rename parser/{ => shared}/src/main/scala/mdoc/parser/ParserSettings.scala (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fda7a060..a70fff1bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: java: [11, 17] command: # Test legacy Scala versions, where reporting API changed - - "'++2.12.12! test'" + - "'++2.12.12! testAllNonNative'" # compiler version too old for Scala Native - "'++2.12.19 test'" - "'++2.13.14 test'" # Minimal supported version diff --git a/build.sbt b/build.sbt index 2f5e4b520..0c2c859b8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,11 @@ import scala.collection.mutable +import sbtcrossproject.CrossPlugin.autoImport.crossProject +import scala.scalanative.build._ + +addCommandAlias( + "testAllNonNative", + "interfaces/test;runtime/test;parser/test;cli/test;mdoc/test;testsInput/test;tests/test;jsdocs/test;worksheets/test;unit/test;unitJS/test;jsApi/test;jsWorker/test;js/test;" +) def scala212 = "2.12.19" def scala213 = "2.13.14" @@ -178,7 +185,8 @@ val excludePprint = ExclusionRule(organization = "com.lihaoyi") val excludeCollection = ExclusionRule(organization = "org.scala-lang.modules", name = "scala-collection-compat_2.13") -lazy val parser = project +lazy val parser = crossProject(JVMPlatform, NativePlatform) + .withoutSuffixFor(JVMPlatform) .settings( sharedSettings, moduleName := "mdoc-parser" @@ -210,7 +218,7 @@ lazy val cli = project ) ) ) - .dependsOn(parser) + .dependsOn(parser.jvm) lazy val mdoc = project .settings( @@ -252,7 +260,7 @@ lazy val mdoc = project "com.lihaoyi" %% "pprint" % V.pprint ) ) - .dependsOn(parser, runtime, cli) + .dependsOn(parser.jvm, runtime, cli) .enablePlugins(BuildInfoPlugin) lazy val testsInput = project @@ -348,7 +356,7 @@ lazy val unit = project "testsInputClassDirectory" -> (testsInput / Compile / classDirectory).value ) ) - .dependsOn(parser, mdoc, testsInput, tests) + .dependsOn(parser.jvm, mdoc, testsInput, tests) .enablePlugins(BuildInfoPlugin, MdocPlugin) lazy val unitJS = project @@ -501,6 +509,7 @@ def localCrossPublish(versions: List[String]): Def.Initialize[Task[Unit]] = def localCrossPublishProjects(scalaV: String): Def.Initialize[Task[Unit]] = { val projects = List(parser, runtime, cli, mdoc, js, jsWorker).reverse projects + .flatMap(_.componentProjects) .map(p => localCrossPublishProject(p, scalaV)) .reduceLeft(_ dependsOn _) } @@ -511,7 +520,7 @@ def localCrossPublishProject(ref: Project, scalaV: String): Def.Initialize[Task[ val projects = List(parser, runtime, cli, mdoc, js, jsWorker) val setttings = (ThisBuild / version := versionValue) :: - projects.map(p => p / scalaVersion := scalaV) + projects.flatMap(_.componentProjects).map(p => p / scalaVersion := scalaV) val newState = Project .extract(state.value) .appendWithSession( diff --git a/parser/src/main/scala/mdoc/parser/MarkdownPart.scala b/parser/shared/src/main/scala/mdoc/parser/MarkdownPart.scala similarity index 100% rename from parser/src/main/scala/mdoc/parser/MarkdownPart.scala rename to parser/shared/src/main/scala/mdoc/parser/MarkdownPart.scala diff --git a/parser/src/main/scala/mdoc/parser/ParserSettings.scala b/parser/shared/src/main/scala/mdoc/parser/ParserSettings.scala similarity index 100% rename from parser/src/main/scala/mdoc/parser/ParserSettings.scala rename to parser/shared/src/main/scala/mdoc/parser/ParserSettings.scala diff --git a/project/plugins.sbt b/project/plugins.sbt index 902e1bf4d..206037a59 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,6 +6,10 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.5") + +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") + libraryDependencies ++= List( "org.jsoup" % "jsoup" % "1.12.1", "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value