Skip to content

Commit 105a7e0

Browse files
committed
Add support for SN 0.4.1 and 0.4.2
Add support for 0.4.0 and 0.4.1 by build.sbt defined values with defined values, the idea being that after release 0.4.0 specific code will be removed and shared and 0.4.1 merged. Cli arguments are parsed via case-app and additional NativeConfig generation phase is introduced. Includes initial project definition and testing infrastructure. Testing is comprised of scalatest unit tests and sbt-provided scripted tests acting as integration tests.
1 parent 1b888df commit 105a7e0

File tree

34 files changed

+1194
-1
lines changed

34 files changed

+1194
-1
lines changed

.github/workflows/CI.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
test-all:
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: olafurpg/setup-scala@v13
13+
- name: Unit tests
14+
run: sbt cli/test
15+
- name: Intergration tests
16+
run: sbt cliIntegration/scripted

.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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copy/pasted from https://github.com/scala-native/scala-native
2+
name: Check Lint
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
jobs:
9+
check-lint:
10+
runs-on: ubuntu-18.04
11+
steps:
12+
- name: Install clang-format
13+
run: |
14+
sudo apt update
15+
sudo apt install clang-format-6.0
16+
- uses: actions/checkout@v2
17+
- run: ./scripts/check-lint.sh
18+
env:
19+
CLANG_FORMAT_PATH: "/usr/bin/clang-format-6.0"

.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

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
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+
### Passing link-time resolved properties
15+
16+
Scala Native allows use of link-time properties - values that are used to resolve `if` code blocks on link-time.
17+
Their non-standard format requires special care.
18+
19+
In scala-native-cli their value is defined as follows:
20+
21+
```keystring=[Type]value```
22+
23+
`keystring` is always a string, however value has to have a type specified in the square brackets. It can be one of the following:
24+
25+
* `Short`
26+
* `Int`
27+
* `Long`
28+
* `Float`
29+
* `Double`
30+
* `Char`
31+
* `Boolean`
32+
* `String`
33+
34+
## Logging
35+
36+
For logging purposes, a default Scala Native logger is used. It is possible to specify which messages to log by filtering out the unnecessary ones with the following options:
37+
38+
* `--disable-debug`
39+
* `--disable-info`
40+
* `--disable-warn`
41+
* `--disable-error`

build.sbt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
scalaVersion := "2.12.15"
2+
val nativeVersion = "0.4.1"
3+
val cliVersion = nativeVersion
4+
5+
inThisBuild(
6+
Def.settings(
7+
organization := "org.scala-native",
8+
version := cliVersion
9+
)
10+
)
11+
12+
lazy val cli = project
13+
.in(file(s"cli/version_${nativeVersion}"))
14+
.settings(
15+
moduleName := "scala-native-cli",
16+
scalacOptions += "-Ywarn-unused:imports",
17+
libraryDependencies += "org.scala-native" %% "tools" % nativeVersion,
18+
libraryDependencies += "com.github.alexarchambault" %% "case-app" % "2.1.0-M9",
19+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.1" % Test,
20+
assembly / assemblyJarName := "scala-native-cli.jar", // Used for integration tests.
21+
Compile / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "shared/src/main/scala",
22+
Test / unmanagedSourceDirectories += baseDirectory.value.getParentFile / "shared/src/test/scala"
23+
)
24+
25+
// Meant to resolve classpath dependencies, provide compiled nir
26+
// and a seperate environment for integration tests
27+
lazy val cliIntegration = project
28+
.in(file("scala-native-cli-integration-test-runner"))
29+
.enablePlugins(SbtPlugin)
30+
.settings(
31+
name := "scala-native-cli-integration-test-runner",
32+
scriptedLaunchOpts := {
33+
val cliPath =
34+
(cli / Compile / packageBin / artifactPath).value.toPath.getParent.toString + "/scala-native-cli.jar"
35+
scriptedLaunchOpts.value ++
36+
Seq(
37+
"-Xmx1024M",
38+
"-Dplugin.version=" + version.value,
39+
"-Dscala-native-cli=" + cliPath,
40+
"-Dscala-native-cli-native-version=" + nativeVersion
41+
)
42+
},
43+
addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.0"),
44+
sbtTestDirectory := (ThisProject / baseDirectory).value / "src/test",
45+
// publish the other projects before running scripted tests.
46+
scriptedDependencies := {
47+
scriptedDependencies
48+
.dependsOn(
49+
cli / assembly
50+
)
51+
.value
52+
},
53+
scriptedBufferLog := false
54+
)
55+
.dependsOn(cli)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package scala.scalanative.cli
2+
3+
import scala.scalanative.build.Build
4+
import scala.scalanative.util.Scope
5+
import System._
6+
import scala.scalanative.cli.utils.{BuildOptionsParser, BuildOptions}
7+
8+
object ScalaNativeCli {
9+
def main(options: Array[String]): Unit = {
10+
val configOption = BuildOptionsParser(options)
11+
12+
configOption match {
13+
case Right(Some(BuildOptions(config, outpath))) =>
14+
Scope { implicit scope =>
15+
Build.build(config, outpath)
16+
}
17+
case Left(exception) =>
18+
err.println(exception.getMessage())
19+
sys.exit(1)
20+
case Right(None) => // when --help or --version
21+
}
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package scala.scalanative.cli.options
2+
3+
import caseapp._
4+
5+
@AppName("Scala Native Cli")
6+
@ProgName("scala-native-cli")
7+
case class CliOptions(
8+
@Recurse
9+
config: ConfigOptions,
10+
@Recurse
11+
nativeConfig: NativeConfigOptions,
12+
@Recurse
13+
logger: LoggerOptions
14+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package scala.scalanative.cli.options
2+
3+
import caseapp._
4+
5+
case class ConfigOptions(
6+
@Group("Config")
7+
@HelpMessage(
8+
"Required path of the resulting output binary. [./scala-native-out]"
9+
)
10+
@ValueDescription("<output-path>")
11+
outpath: String = "scala-native-out",
12+
@Group("Config")
13+
@HelpMessage(
14+
"Required sequence of all linked NIR files. Should include the standard Scala Native libraries."
15+
)
16+
@ValueDescription("<colon-separated-file-paths>")
17+
classPath: String,
18+
@Group("Config")
19+
@HelpMessage("Required entry point for linking.")
20+
@ValueDescription("<main-class>")
21+
main: String,
22+
@Group("Config")
23+
@HelpMessage("Scala Native working directory. [.]")
24+
@ValueDescription("<path-to-directory>")
25+
workdir: String = "."
26+
)

0 commit comments

Comments
 (0)