From 0bb9c4ee2b003f5454b53f281aee415bd7358037 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 3 May 2022 03:27:18 +0800 Subject: [PATCH 1/4] Support scala native --- build.sbt | 32 ++++++++++--------- project/Dependencies.scala | 8 ++--- project/plugins.sbt | 8 +++-- .../scala/ai/kien/python/PythonTest.scala | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/build.sbt b/build.sbt index 63eb7a3..ecf55f9 100644 --- a/build.sbt +++ b/build.sbt @@ -23,21 +23,24 @@ lazy val scala3 = "3.0.2" ThisBuild / scalaVersion := scala213 ThisBuild / scalafixDependencies += organizeImports -lazy val root = project +lazy val root = crossProject(JVMPlatform, NativePlatform) + .crossType(CrossType.Pure) .in(file(".")) .settings( - name := "Python Native Libs", - crossScalaVersions := Seq(scala212, scala213, scala3), + name := "Python Native Libs", + sonatypeCredentialHost := "s01.oss.sonatype.org", + sonatypeRepository := "https://s01.oss.sonatype.org/service/local", libraryDependencies ++= Seq( - scalaCollectionCompat, - scalapy % Test, - scalaTest % Test - ), - Test / fork := true + "org.scala-lang.modules" %%% "scala-collection-compat" % scalaCollectionCompatVersion, + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test, + "me.shadaj" %%% "scalapy-core" % scalapyVersion % Test + ) ) - .settings( - semanticdbEnabled := true, - semanticdbVersion := scalafixSemanticdb.revision, + .jvmSettings( + crossScalaVersions := Seq(scala212, scala213, scala3), + Test / fork := true, + semanticdbEnabled := true, + semanticdbVersion := scalafixSemanticdb.revision, scalacOptions += { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 13)) => "-Wunused:imports" @@ -46,9 +49,8 @@ lazy val root = project } } ) - .settings( - sonatypeCredentialHost := "s01.oss.sonatype.org", - sonatypeRepository := "https://s01.oss.sonatype.org/service/local" + .nativeSettings( + crossScalaVersions := Seq(scala212, scala213) ) lazy val docs = project @@ -59,4 +61,4 @@ lazy val docs = project "PYTHON" -> "/usr/bin/python3" ) ) - .dependsOn(root) + .dependsOn(root.jvm) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c1ff9f5..c59bd9d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,9 +1,9 @@ import sbt._ object Dependencies { - lazy val scalaCollectionCompat = - "org.scala-lang.modules" %% "scala-collection-compat" % "2.7.0" - lazy val scalapy = "me.shadaj" %% "scalapy-core" % "0.5.2" - lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.11" + lazy val scalapyVersion = "0.5.2" + lazy val scalaCollectionCompatVersion = "2.7.0" + lazy val scalaTestVersion = "3.2.11" + lazy val organizeImports = "com.github.liancheng" %% "organize-imports" % "0.6.0" } diff --git a/project/plugins.sbt b/project/plugins.sbt index 9412367..7444726 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,5 @@ -addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.2") -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.0") +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.2") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.0") diff --git a/src/test/scala/ai/kien/python/PythonTest.scala b/src/test/scala/ai/kien/python/PythonTest.scala index 4c46181..28d4990 100644 --- a/src/test/scala/ai/kien/python/PythonTest.scala +++ b/src/test/scala/ai/kien/python/PythonTest.scala @@ -7,7 +7,7 @@ import org.scalatest.funsuite.AnyFunSuite class PythonTest extends AnyFunSuite { Python().scalapyProperties.get.foreach { case (k, v) => System.setProperty(k, v) } - test("ScalaPy runs successfully") { + test("ScalaPy actually runs") { py.Dynamic.global.list(Seq(1, 2, 3).toPythonCopy) py"'Hello from ScalaPy!'" } From bee2892d8461e2e8a195436dbf4ab6c0ff093b0c Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 3 May 2022 08:31:00 +0800 Subject: [PATCH 2/4] Downgrade scala-collection-compat for native compatibility --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c59bd9d..dc509f2 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -2,7 +2,7 @@ import sbt._ object Dependencies { lazy val scalapyVersion = "0.5.2" - lazy val scalaCollectionCompatVersion = "2.7.0" + lazy val scalaCollectionCompatVersion = "2.5.0" lazy val scalaTestVersion = "3.2.11" lazy val organizeImports = "com.github.liancheng" %% "organize-imports" % "0.6.0" From cf870f6864b0d25c5fce365848bb16253693f2bd Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 3 May 2022 08:46:44 +0800 Subject: [PATCH 3/4] Downgrade scalatest for native compatibility --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index dc509f2..2403fdc 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -3,7 +3,7 @@ import sbt._ object Dependencies { lazy val scalapyVersion = "0.5.2" lazy val scalaCollectionCompatVersion = "2.5.0" - lazy val scalaTestVersion = "3.2.11" + lazy val scalaTestVersion = "3.2.10" lazy val organizeImports = "com.github.liancheng" %% "organize-imports" % "0.6.0" } From aa343bc2fbe3110de52a303aadeff3c92933b1f0 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 3 May 2022 08:54:48 +0800 Subject: [PATCH 4/4] CI --- .github/workflows/ci.yml | 2 +- build.sbt | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c288a3e..c04995a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: with: python-version: ${{ matrix.python }} - name: Test - run: sbtn +test + run: sbtn +root/test shell: bash publish: runs-on: ubuntu-20.04 diff --git a/build.sbt b/build.sbt index ecf55f9..ab56a7e 100644 --- a/build.sbt +++ b/build.sbt @@ -24,18 +24,21 @@ ThisBuild / scalaVersion := scala213 ThisBuild / scalafixDependencies += organizeImports lazy val root = crossProject(JVMPlatform, NativePlatform) + .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Pure) .in(file(".")) .settings( - name := "Python Native Libs", - sonatypeCredentialHost := "s01.oss.sonatype.org", - sonatypeRepository := "https://s01.oss.sonatype.org/service/local", + name := "Python Native Libs", libraryDependencies ++= Seq( "org.scala-lang.modules" %%% "scala-collection-compat" % scalaCollectionCompatVersion, "org.scalatest" %%% "scalatest" % scalaTestVersion % Test, "me.shadaj" %%% "scalapy-core" % scalapyVersion % Test ) ) + .settings( + sonatypeCredentialHost := "s01.oss.sonatype.org", + sonatypeRepository := "https://s01.oss.sonatype.org/service/local" + ) .jvmSettings( crossScalaVersions := Seq(scala212, scala213, scala3), Test / fork := true,