Skip to content

Commit 7633b55

Browse files
Prepare for release 0.5.0 (#31)
* Initial 0.5.0-SNAPSHOT support * Streamline publishing process * Properly handle new options * Adapt to new scalalib publishing model + add new javalibintf module * Accept repository dispatch events instead of building on schedule * Fix scripts and warnings in build.sbt
1 parent 859e059 commit 7633b55

File tree

21 files changed

+367
-83
lines changed

21 files changed

+367
-83
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ jobs:
77
fail-fast: false
88
matrix:
99
OS: [ubuntu-22.04, windows-2022]
10-
scala: [2.12.17, 2.13.10, 3.2.1]
10+
scala: [2.12.18, 2.13.12, 3.3.1]
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: olafurpg/setup-scala@v13
12+
- uses: actions/checkout@v3
13+
- uses: coursier/cache-action@v6
14+
- uses: coursier/setup-action@v1
15+
with:
16+
jvm: adopt:8
1417
- name: Set env Linux
1518
if: ${{ startsWith(matrix.OS, 'ubuntu') }}
1619
run: |

.github/workflows/check-cla.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ jobs:
55
check-cla:
66
runs-on: ubuntu-22.04
77
steps:
8-
- uses: actions/checkout@v2
8+
- uses: actions/checkout@v3
99
- run: ./scripts/check-cla.sh

.github/workflows/check-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ jobs:
55
check-lint:
66
runs-on: ubuntu-22.04
77
steps:
8-
- uses: actions/checkout@v2
8+
- uses: actions/checkout@v3
99
- run: ./scripts/check-lint.sh

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- 'v0.5.*'
6+
workflow_dispatch:
7+
repository_dispatch:
8+
types: [nightly-published]
9+
10+
jobs:
11+
publish:
12+
name: Publish
13+
runs-on: ubuntu-22.04
14+
if: github.repository == 'scala-native/scala-native-cli'
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: coursier/cache-action@v6
18+
- uses: coursier/setup-action@v1
19+
with:
20+
jvm: adopt:8
21+
22+
- name: Setup PGP Key
23+
run: |
24+
echo -n "$PGP_SECRET" | base64 --decode | gpg --batch --import
25+
env:
26+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
27+
28+
- name: Compile everything
29+
run: sbt "+Test/compile"
30+
31+
- name: Publish release
32+
env:
33+
MAVEN_USER: "${{ secrets.SONATYPE_USER }}"
34+
MAVEN_PASSWORD: "${{ secrets.SONATYPE_PASSWORD }}"
35+
PGP_PASSPHRASE: "${{ secrets.PGP_PASSWORD }}"
36+
run: sbt "clean;+cli/cliPack; +cli/publishSigned"
37+
38+
- name: Create release artifacts
39+
run: |
40+
version=$(sbt "print cli/version" | tail -n1)
41+
echo "This build version: $version"
42+
./scritps/dist.sh $version
43+
44+
- name: Archive CLI artifacts
45+
uses: actions/upload-artifact@v3
46+
with:
47+
name: scala-native-cli
48+
path: release/

build.sbt

Lines changed: 81 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
val crossScalaVersions212 = (13 to 18).map("2.12." + _)
2-
val crossScalaVersions213 = (4 to 11).map("2.13." + _)
1+
val crossScalaVersions212 = (14 to 18).map("2.12." + _)
2+
val crossScalaVersions213 = (8 to 12).map("2.13." + _)
33
val crossScalaVersions3 =
4-
(0 to 3).map("3.1." + _) ++
4+
(2 to 3).map("3.1." + _) ++
55
(0 to 2).map("3.2." + _) ++
6-
(0 to 0).map("3.3." + _)
6+
(0 to 1).map("3.3." + _)
77

8-
val publishScalaVersions =
9-
Seq(crossScalaVersions212, crossScalaVersions213).map(_.last) ++ Seq("3.1.3")
8+
val scala2_12 = crossScalaVersions212.last
9+
val scala2_13 = crossScalaVersions213.last
10+
val scala3 = crossScalaVersions3.last
11+
val scala3PublishVersion = "3.1.3"
12+
13+
val publishScalaVersions = Seq(scala2_12, scala2_13, scala3PublishVersion)
1014

1115
def scalaReleasesForBinaryVersion(v: String): Seq[String] = v match {
1216
case "2.12" => crossScalaVersions212
@@ -19,27 +23,37 @@ def scalaReleasesForBinaryVersion(v: String): Seq[String] = v match {
1923
}
2024

2125
def scalaStdlibForBinaryVersion(
22-
nativeBinVer: String,
23-
scalaBinVer: String
24-
): Seq[String] = {
25-
def depPattern(lib: String, v: String) =
26-
s"${lib}_native${nativeBinVer}_${v}"
27-
val scalalib = "scalalib"
28-
val scala3lib = "scala3lib"
29-
val commonLibs = Seq(
26+
organization: String,
27+
nativeVersion: String,
28+
nativeBinaryVersion: String,
29+
scalaBinaryVersion: String
30+
): Seq[ModuleID] = {
31+
def artifact(module: String, binV: String, version: String = nativeVersion) =
32+
organization % s"${module}_native${nativeBinaryVersion}_$binV" % version
33+
34+
def scalalibVersion(scalaBinVersion: String): String = {
35+
val scalaVersion = scalaReleasesForBinaryVersion(scalaBinaryVersion).last
36+
s"$scalaVersion+$nativeVersion"
37+
}
38+
def scalalib(binV: String) = artifact("scalalib", binV, scalalibVersion(binV))
39+
val scala3lib = artifact("scalalib", "3", scalalibVersion("3"))
40+
val crossRuntimeLibraries = List(
3041
"nativelib",
3142
"clib",
3243
"posixlib",
3344
"windowslib",
3445
"javalib",
3546
"auxlib"
36-
)
37-
scalaBinVer match {
38-
case "2.12" | "2.13" =>
39-
(commonLibs :+ scalalib).map(depPattern(_, scalaBinVer))
40-
case "3" =>
41-
(commonLibs :+ scala3lib).map(depPattern(_, scalaBinVer)) :+
42-
depPattern(scalalib, "2.13")
47+
).map(artifact(_, scalaBinaryVersion))
48+
49+
val nonCrossRuntimeLibraries = List("javalib-intf")
50+
.map(organization % _ % nativeVersion)
51+
52+
val runtimeLibraries = crossRuntimeLibraries ++ nonCrossRuntimeLibraries
53+
54+
scalaBinaryVersion match {
55+
case "2.12" | "2.13" => scalalib(scalaBinaryVersion) :: runtimeLibraries
56+
case "3" => scala3lib :: scalalib("2.13") :: runtimeLibraries
4357
case ver =>
4458
throw new IllegalArgumentException(
4559
s"Unsupported binary scala version `${ver}`"
@@ -55,9 +69,9 @@ val cliAssemblyJarName = settingKey[String]("Name of created assembly jar")
5569
inThisBuild(
5670
Def.settings(
5771
organization := "org.scala-native",
58-
scalaNativeVersion := "0.4.15",
72+
scalaNativeVersion := "0.5.0-SNAPSHOT",
5973
version := scalaNativeVersion.value,
60-
scalaVersion := crossScalaVersions212.last,
74+
scalaVersion := scala3PublishVersion,
6175
crossScalaVersions := publishScalaVersions,
6276
homepage := Some(url("http://www.scala-native.org")),
6377
startYear := Some(2021),
@@ -74,7 +88,7 @@ inThisBuild(
7488
Some("scm:git:[email protected]:scala-native/scala-native-cli.git")
7589
)
7690
),
77-
resolvers += Resolver.sonatypeRepo("snapshots"),
91+
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
7892
resolvers += Resolver.mavenCentral,
7993
resolvers += Resolver.defaultLocal
8094
)
@@ -143,10 +157,33 @@ lazy val cliScriptedTests = project
143157

144158
def nativeBinaryVersion(version: String): String = {
145159
val VersionPattern = raw"(\d+)\.(\d+)\.(\d+)(\-.*)?".r
146-
val VersionPattern(major, minor, _, _) = version
147-
s"$major.$minor"
160+
val VersionPattern(major, minor, patch, milestone) = version
161+
if (patch != null && milestone != null) version
162+
else s"$major.$minor"
163+
}
164+
165+
val nativeSourceExtensions = Set(".c", ".cpp", ".cxx", ".h", ".hpp", ".S")
166+
val DeduplicateOrRename = new sbtassembly.MergeStrategy {
167+
def name: String = "deduplicate-or-rename"
168+
def apply(
169+
tempDir: java.io.File,
170+
path: String,
171+
files: Seq[java.io.File]
172+
): Either[String, Seq[(java.io.File, String)]] =
173+
MergeStrategy.deduplicate(tempDir, path, files) match {
174+
case v @ Right(_) => v
175+
case _ => MergeStrategy.rename(tempDir, path, files)
176+
}
148177
}
178+
149179
lazy val cliPackSettings = Def.settings(
180+
assemblyMergeStrategy := {
181+
val default = assemblyMergeStrategy.value
182+
file =>
183+
if (nativeSourceExtensions.exists(file.endsWith)) DeduplicateOrRename
184+
else if (file.endsWith("scala-native.properties")) MergeStrategy.concat
185+
else default(file)
186+
},
150187
cliPackLibJars := {
151188
val s = streams.value
152189
val log = s.log
@@ -159,13 +196,15 @@ lazy val cliPackSettings = Def.settings(
159196
val scalaFullVers = scalaReleasesForBinaryVersion(scalaBinVer)
160197
val cliAssemblyJar = assembly.value
161198

162-
val scalaStdLibraryModuleIDs =
163-
scalaStdlibForBinaryVersion(nativeBinVer, scalaBinVer)
164-
165199
// Standard modules needed for linking of Scala Native
166-
val stdLibModuleIDs = scalaStdLibraryModuleIDs.map(
167-
scalaNativeOrg % _ % snVer
168-
)
200+
val stdLibModuleIDs =
201+
scalaStdlibForBinaryVersion(
202+
organization = scalaNativeOrg,
203+
nativeVersion = snVer,
204+
nativeBinaryVersion = nativeBinVer,
205+
scalaBinaryVersion = scalaBinVer
206+
)
207+
169208
val compilerPluginModuleIDs =
170209
scalaFullVers.map(v => scalaNativeOrg % s"nscplugin_$v" % snVer)
171210
val allModuleIDs = (stdLibModuleIDs ++ compilerPluginModuleIDs).toVector
@@ -235,6 +274,10 @@ lazy val cliPackSettings = Def.settings(
235274
"@SCALANATIVE_BIN_VER@",
236275
nativeBinaryVersion(snVer)
237276
)
277+
.replaceAllLiterally(
278+
"@SCALALIB_2_13_FOR_3_VER@",
279+
crossScalaVersions213.last
280+
)
238281
val dest = trgBin / scriptFile.getName
239282
IO.write(dest, processedContent)
240283
if (scriptFile.canExecute)
@@ -259,11 +302,14 @@ lazy val publishSettings = Def.settings(
259302
},
260303
credentials ++= {
261304
for {
262-
realm <- sys.env.get("MAVEN_REALM")
263-
domain <- sys.env.get("MAVEN_DOMAIN")
264305
user <- sys.env.get("MAVEN_USER")
265306
password <- sys.env.get("MAVEN_PASSWORD")
266-
} yield Credentials(realm, domain, user, password)
307+
} yield Credentials(
308+
realm = "Sonatype Nexus Repository Manager",
309+
host = "oss.sonatype.org",
310+
userName = user,
311+
passwd = password
312+
)
267313
}.toSeq,
268314
developers ++= List(
269315
Developer(

cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package scala.scalanative.cli
22

3+
import java.nio.file._
34
import scala.scalanative.build._
45
import scala.scalanative.util.Scope
56
import scala.scalanative.cli.utils.ConfigConverter
67
import scala.scalanative.cli.options._
8+
import scala.concurrent._
9+
import scala.concurrent.duration.Duration
10+
import scala.concurrent.ExecutionContext.Implicits.global
711

812
object ScalaNativeLd {
913

@@ -69,9 +73,21 @@ object ScalaNativeLd {
6973
System.err.println(thrown.getMessage())
7074
sys.exit(1)
7175
case Right(buildOptions) =>
72-
Scope { implicit scope =>
73-
Build.build(buildOptions.config, buildOptions.outpath)
76+
val outpath = Paths.get(options.config.outpath)
77+
val build = Scope { implicit scope =>
78+
Build
79+
.build(buildOptions.config)
80+
.map(
81+
Files.copy(
82+
_,
83+
outpath,
84+
StandardCopyOption.REPLACE_EXISTING,
85+
StandardCopyOption.COPY_ATTRIBUTES
86+
)
87+
)
7488
}
89+
Await.result(build, Duration.Inf)
90+
7591
}
7692
}
7793
}

cli/src/main/scala/scala/scalanative/cli/ScalaNativeP.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ object ScalaNativeP {
151151
private def printNIR(defns: Seq[Defn], verbose: Boolean) =
152152
defns
153153
.map {
154-
case defn @ Defn.Define(attrs, name, ty, _) if !verbose =>
154+
case defn @ Defn.Define(attrs, name, ty, _, _) if !verbose =>
155155
Defn.Declare(attrs, name, ty)(defn.pos)
156156
case defn => defn
157157
}

cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ case class NativeConfigOptions(
1616
dump: Boolean = false,
1717
noOptimize: Boolean = false,
1818
embedResources: Boolean = false,
19+
multithreadingSupport: Boolean = true,
20+
debugMetadata: Boolean = false,
1921
incrementalCompilation: Boolean = false,
22+
baseName: Option[String] = None,
2023
ltp: List[String] = List.empty,
2124
linkingOption: List[String] = List.empty,
2225
compileOption: List[String] = List.empty,
@@ -109,6 +112,38 @@ object NativeConfigOptions {
109112
.text(
110113
"Shall use incremental compilation mode for builds? (experimental) [false]"
111114
)
115+
parser
116+
.opt[Boolean]("multithreading")
117+
.abbr("-mt")
118+
.optional()
119+
.action((x, c) =>
120+
c.copy(nativeConfig = c.nativeConfig.copy(multithreadingSupport = x))
121+
)
122+
.text(
123+
"Should the target enable multihreading support for builds? [true]"
124+
)
125+
parser
126+
.opt[Boolean]("debug-info")
127+
.abbr("-g")
128+
.optional()
129+
.action((x, c) =>
130+
c.copy(nativeConfig = c.nativeConfig.copy(debugMetadata = x))
131+
)
132+
.text(
133+
"Should the build include additional debug information? These can be used for better stacktraces or debuging support [false]"
134+
)
135+
parser
136+
.opt[String]("base-name")
137+
.optional()
138+
.action((x, c) =>
139+
c.copy(nativeConfig =
140+
c.nativeConfig
141+
.copy(baseName = Some(x).map(_.trim()).filter(_.nonEmpty))
142+
)
143+
)
144+
.text(
145+
"Base name (without extension) used to generate names for build outputs. If empty `--base-name` would be resolved from `--outpath`"
146+
)
112147
parser
113148
.opt[String]("ltp")
114149
.valueName("<keystring=value>")

0 commit comments

Comments
 (0)