Skip to content

Commit 0807e31

Browse files
Initial implementation for Scala Native 0.4.0 and 0.4.1
Initial implementation of CLI including linker capability. After initial release (keeping up with latest stable Scala Native version) we would be only publishing CLI for latest release
2 parents 1b888df + 645cefa commit 0807e31

File tree

32 files changed

+999
-2
lines changed

32 files changed

+999
-2
lines changed

.github/workflows/CI.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test All
2+
on: [pull_request]
3+
jobs:
4+
test-all:
5+
runs-on: ${{matrix.OS}}
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
OS: [ubuntu-18.04, windows-2019]
10+
SN: [0.4.0, 0.4.1, 0.4.2]
11+
exclude:
12+
# does not support windows
13+
- OS: windows-2019
14+
SN: 0.4.0
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: olafurpg/setup-scala@v13
18+
- name: Test
19+
run: >
20+
sbt 'set cli/scalaNativeVersion := "${{matrix.SN}}"'
21+
cli/test
22+
cli/scripted
23+
shell: bash

.github/workflows/check-cla.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copy/pasted from https://github.com/scala-native/scala-native
2+
name: Check CLA
3+
on: [pull_request]
4+
jobs:
5+
check-cla:
6+
runs-on: ubuntu-18.04
7+
steps:
8+
- uses: actions/checkout@v2
9+
- run: ./scripts/check-cla.sh

.github/workflows/check-lint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copy/pasted from https://github.com/scala-native/scala-native
2+
name: Check Lint
3+
on: [pull_request]
4+
jobs:
5+
check-lint:
6+
runs-on: ubuntu-18.04
7+
steps:
8+
- uses: actions/checkout@v2
9+
- run: ./scripts/check-lint.sh

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
**/target/
2+
3+
scripts/.coursier
4+
scripts/.scalafmt*
5+
6+
# IntelliJ
7+
.idea
8+
9+
# Eclipse / Scala IDE
10+
bin/
11+
.project
12+
.classpath
13+
.settings/
14+
.externalToolBuilders/
15+
.cache*
16+
17+
# metals
18+
**/.bloop/
19+
**/.metals/
20+
/project/**/metals.sbt
21+
22+
# Build Server Protocol, used by sbt
23+
/.bsp/
24+
25+
# vscode
26+
/.vscode/
27+
28+
# vim
29+
*.swp

.scalafmt.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "3.2.1"
2+
runner.dialect = scala212
3+
project.git = true

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright (c) 2013-2018 EPFL
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# scala-native-cli
2-
Command Line Interface for Scala Native
2+
3+
Command Line Interface for the tools component of Scala Native. Tools handle the linking, optimisation and code generation phases.
4+
This means that the initial .scala files cannot be compiled with it - for that look to the nscplugin component.
5+
6+
Please note that this api is meant for Scala Native power users. For a more friendly Scala Native building experience please use
7+
the dedicated [sbt plugin](https://scala-native.readthedocs.io/en/stable/user/sbt.html#minimal-sbt-project) or [scala-cli](https://scala-cli.virtuslab.org).
8+
9+
## Usage
10+
11+
scala-native-cli --help will bring up possible options and syntax.
12+
Since options are dependent on the used version of scala-native-cli, please use it for further instructions.
13+
14+
## Logging
15+
16+
For logging purposes, a default Scala Native logger is used. By default it will only show `Error` messages, but its verbosity can be increased with a -v flag.

build.sbt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
val scalaNativeVersion =
2+
settingKey[String]("Version of Scala Native for which to build to CLI")
3+
4+
val cliAssemblyJarName = settingKey[String]("Name of created assembly jar")
5+
6+
inThisBuild(
7+
Def.settings(
8+
organization := "org.scala-native",
9+
scalaVersion := "2.12.15",
10+
scalaNativeVersion := "0.4.0",
11+
version := scalaNativeVersion.value
12+
)
13+
)
14+
15+
lazy val cli = project
16+
.in(file("cli"))
17+
.enablePlugins(BuildInfoPlugin, ScriptedPlugin)
18+
.settings(
19+
name := "scala-native-cli",
20+
scalacOptions += "-Ywarn-unused:imports",
21+
libraryDependencies ++= Seq(
22+
"org.scala-native" %% "tools" % scalaNativeVersion.value,
23+
"com.github.alexarchambault" %% "case-app" % "2.1.0-M10",
24+
"org.scalatest" %% "scalatest" % "3.1.1" % Test
25+
),
26+
patchSourcesSettings,
27+
buildInfoKeys := Seq[BuildInfoKey](
28+
"nativeVersion" -> scalaNativeVersion.value
29+
),
30+
buildInfoPackage := "scala.scalanative.cli.options",
31+
cliAssemblyJarName := s"${normalizedName.value}-assembly_${scalaBinaryVersion.value}-${scalaNativeVersion.value}.jar",
32+
assembly / assemblyJarName := cliAssemblyJarName.value,
33+
scriptedLaunchOpts ++= {
34+
val jarName = cliAssemblyJarName.value
35+
val cliPath = (Compile / crossTarget).value / jarName
36+
Seq(
37+
"-Xmx1024M",
38+
"-Dplugin.version=" + scalaNativeVersion.value,
39+
"-Dscala-native-cli=" + cliPath
40+
)
41+
},
42+
scriptedBufferLog := false,
43+
scriptedDependencies := {
44+
scriptedDependencies
45+
.dependsOn(assembly)
46+
.value
47+
}
48+
)
49+
50+
// To be removed since 0.4.2
51+
lazy val patchSourcesSettings = {
52+
def patchSources(base: File, version: String, subdir: String) = {
53+
val directory = version match {
54+
case v @ "0.4.0" => v
55+
case _ => "current"
56+
}
57+
base / "patches" / directory / "src" / subdir / "scala"
58+
}
59+
60+
Def.settings(
61+
Compile / unmanagedSourceDirectories += patchSources(
62+
sourceDirectory.value,
63+
scalaNativeVersion.value,
64+
"main"
65+
),
66+
Test / unmanagedSourceDirectories += patchSources(
67+
sourceDirectory.value,
68+
scalaNativeVersion.value,
69+
"test"
70+
)
71+
)
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package scala.scalanative.cli
2+
3+
import scala.scalanative.build.Build
4+
import scala.scalanative.util.Scope
5+
import scala.scalanative.cli.utils.ConfigConverter
6+
import scala.scalanative.cli.utils.NativeConfigParserImplicits._
7+
import scala.scalanative.cli.options.CliOptions
8+
import caseapp.core.app.CaseApp
9+
import caseapp.core.RemainingArgs
10+
import scala.scalanative.cli.options.BuildInfo
11+
12+
object ScalaNativeCli extends CaseApp[CliOptions] {
13+
14+
override def ignoreUnrecognized: Boolean = true
15+
16+
def run(options: CliOptions, args: RemainingArgs) = {
17+
if (options.misc.version) {
18+
println(BuildInfo.nativeVersion)
19+
} else if (options.config.main.isEmpty) {
20+
println("Required option not specified: --main")
21+
exit(1)
22+
} else {
23+
val (ignoredArgs, classpath) = args.all.partition(_.startsWith("-"))
24+
ignoredArgs.foreach { arg =>
25+
println(s"Unrecognised argument: ${arg}")
26+
}
27+
val main = options.config.main.get
28+
val buildOptionsMaybe = ConfigConverter.convert(options, main, classpath)
29+
30+
buildOptionsMaybe match {
31+
case Left(thrown) =>
32+
System.err.println(thrown.getMessage())
33+
exit(1)
34+
case Right(buildOptions) =>
35+
Scope { implicit scope =>
36+
Build.build(buildOptions.config, buildOptions.outpath)
37+
}
38+
}
39+
}
40+
}
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala.scalanative.cli.options
2+
3+
import caseapp._
4+
5+
@AppName("ScalaNativeCli")
6+
@ProgName("scala-native-cli")
7+
@ArgsName("classpath")
8+
case class CliOptions(
9+
@Recurse
10+
config: ConfigOptions,
11+
@Recurse
12+
nativeConfig: NativeConfigOptions,
13+
@Recurse
14+
logger: LoggerOptions,
15+
@Recurse
16+
misc: MiscOptions
17+
)

0 commit comments

Comments
 (0)