Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,48 @@ class ScalaNativeUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
}

for { directiveKey <- Seq("nativeCCompile", "native-c-compile") }
test(s"ScalaNativeOptions for $directiveKey") {
val expectedOption1 = "compileOption1"
val expectedOption2 = "compileOption2"
val inputs = TestInputs(
os.rel / "p.sc" ->
s"""//> using $directiveKey $expectedOption1 $expectedOption2
|def foo() = println("hello foo")
|""".stripMargin
)

inputs.withLoadedBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
assert(
maybeBuild.options.scalaNativeOptions.cCompileOptions.head == expectedOption1
)
assert(
maybeBuild.options.scalaNativeOptions.cCompileOptions.drop(1).head == expectedOption2
)
}
}

for { directiveKey <- Seq("nativeCppCompile", "native-cpp-compile") }
test(s"ScalaNativeOptions for $directiveKey") {
val expectedOption1 = "compileOption1"
val expectedOption2 = "compileOption2"
val inputs = TestInputs(
os.rel / "p.sc" ->
s"""//> using $directiveKey $expectedOption1 $expectedOption2
|def foo() = println("hello foo")
|""".stripMargin
)

inputs.withLoadedBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
assert(
maybeBuild.options.scalaNativeOptions.cppCompileOptions.head == expectedOption1
)
assert(
maybeBuild.options.scalaNativeOptions.cppCompileOptions.drop(1).head == expectedOption2
)
}
}

test("ScalaNativeOptions for native-linking and no value") {
val inputs = TestInputs(
os.rel / "p.sc" ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ final case class ScalaNativeOptions(
@Tag(tags.should)
nativeCompile: List[String] = Nil,

@Group(HelpGroup.ScalaNative.toString)
@HelpMessage("List of compile options (C files only)")
@Tag(tags.should)
nativeCCompile: List[String] = Nil,

@Group(HelpGroup.ScalaNative.toString)
@HelpMessage("List of compile options (C++ files only)")
@Tag(tags.should)
nativeCppCompile: List[String] = Nil,

@Group(HelpGroup.ScalaNative.toString)
@Hidden
@HelpMessage("Use default compile options")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ final case class SharedOptions(
linkingOptions = nativeLinking,
linkingDefaults = nativeLinkingDefaults,
compileOptions = nativeCompile,
cCompileOptions = nativeCCompile,
cppCompileOptions = nativeCppCompile,
compileDefaults = nativeCompileDefaults,
embedResources = embedResources,
buildTargetStr = nativeTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import scala.cli.commands.SpecificationLevel
@DirectiveExamples(s"//> using nativeLto full")
@DirectiveExamples(s"//> using nativeVersion ${Constants.scalaNativeVersion}")
@DirectiveExamples(s"//> using nativeCompile -flto=thin")
@DirectiveExamples(s"//> using nativeCCompile -std=c17")
@DirectiveExamples(s"//> using nativeCppCompile -std=c++17 -fcxx-exceptions")
@DirectiveExamples(s"//> using nativeLinking -flto=thin")
@DirectiveExamples(s"//> using nativeClang ./clang")
@DirectiveExamples(s"//> using nativeClangPP ./clang++")
Expand All @@ -32,6 +34,10 @@ import scala.cli.commands.SpecificationLevel
|
|`//> using nativeCompile` _value1_ _value2_ …
|
|`//> using nativeCCompile` _value1_ _value2_ …
|
|`//> using nativeCppCompile` _value1_ _value2_ …
|
|`//> using nativeLinking` _value1_ _value2_ …
|
|`//> using nativeClang` _value_
Expand Down Expand Up @@ -59,6 +65,8 @@ final case class ScalaNative(
nativeLto: Option[String] = None,
nativeVersion: Option[String] = None,
nativeCompile: List[String] = Nil,
nativeCCompile: List[String] = Nil,
nativeCppCompile: List[String] = Nil,
nativeLinking: List[String] = Nil,
nativeClang: Option[String] = None,
@DirectiveName("nativeClangPp")
Expand All @@ -74,6 +82,8 @@ final case class ScalaNative(
ltoStr = nativeLto,
version = nativeVersion,
compileOptions = nativeCompile,
cCompileOptions = nativeCCompile,
cppCompileOptions = nativeCppCompile,
linkingOptions = nativeLinking,
clang = nativeClang,
clangpp = nativeClangPP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ final case class ScalaNativeOptions(
linkingOptions: List[String] = Nil,
linkingDefaults: Option[Boolean] = None,
compileOptions: List[String] = Nil,
cCompileOptions: List[String] = Nil,
cppCompileOptions: List[String] = Nil,
compileDefaults: Option[Boolean] = None,
embedResources: Option[Boolean] = None,
buildTargetStr: Option[String] = None,
Expand Down Expand Up @@ -109,6 +111,10 @@ final case class ScalaNativeOptions(

private def compileCliOptions(): List[String] =
finalCompileOptions().flatMap(option => List("--compile-option", option))
private def cCompileCliOptions(): List[String] =
cCompileOptions.flatMap(option => List("--c-compile-option", option))
private def cppCompileCliOptions(): List[String] =
cppCompileOptions.flatMap(option => List("--cpp-compile-option", option))
private def ltoOptions(): List[String] =
ltoStr.map(_.trim).filter(_.nonEmpty)
.map(lto => LTO.apply(lto))
Expand Down Expand Up @@ -176,6 +182,8 @@ final case class ScalaNativeOptions(
clangppCliOption() ++
linkingCliOptions() ++
compileCliOptions() ++
cCompileCliOptions() ++
cppCompileCliOptions() ++
resourcesCliOptions(resourcesExist) ++
targetCliOption() ++
multithreadingCliOption()
Expand Down
2 changes: 1 addition & 1 deletion project/deps/package.mill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ object Deps {
def scalaMeta = "4.13.9"
def scalafmt = "3.9.10"
def scalaNative04 = "0.4.17"
def scalaNative05 = "0.5.8"
def scalaNative05 = "0.5.9"
def scalaNative = scalaNative05
def maxScalaNativeForToolkit = scalaNative05
def maxScalaNativeForTypelevelToolkit = scalaNative04
Expand Down
10 changes: 9 additions & 1 deletion website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ Enable Scala Native. To show more options for Scala Native pass `--help-native`

### `--native-version`

Set the Scala Native version (0.5.8 by default).
Set the Scala Native version (0.5.9 by default).

### `--native-mode`

Expand Down Expand Up @@ -1455,6 +1455,14 @@ Use default linking settings

List of compile options

### `--native-c-compile`

List of compile options (C files only)

### `--native-cpp-compile`

List of compile options (C++ files only)

### `--native-compile-defaults`

[Internal]
Expand Down
10 changes: 9 additions & 1 deletion website/docs/reference/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ Add Scala Native options

`//> using nativeCompile` _value1_ _value2_ …

`//> using nativeCCompile` _value1_ _value2_ …

`//> using nativeCppCompile` _value1_ _value2_ …

`//> using nativeLinking` _value1_ _value2_ …

`//> using nativeClang` _value_
Expand All @@ -530,10 +534,14 @@ Add Scala Native options

`//> using nativeLto full`

`//> using nativeVersion 0.5.8`
`//> using nativeVersion 0.5.9`

`//> using nativeCompile -flto=thin`

`//> using nativeCCompile -std=c17`

`//> using nativeCppCompile -std=c++17 -fcxx-exceptions`

`//> using nativeLinking -flto=thin`

`//> using nativeClang ./clang`
Expand Down
14 changes: 13 additions & 1 deletion website/docs/reference/scala-command/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ Enable Scala Native. To show more options for Scala Native pass `--help-native`

`SHOULD have` per Scala Runner specification

Set the Scala Native version (0.5.8 by default).
Set the Scala Native version (0.5.9 by default).

### `--native-mode`

Expand Down Expand Up @@ -904,6 +904,18 @@ Use default linking settings

List of compile options

### `--native-c-compile`

`SHOULD have` per Scala Runner specification

List of compile options (C files only)

### `--native-cpp-compile`

`SHOULD have` per Scala Runner specification

List of compile options (C++ files only)

### `--native-compile-defaults`

`IMPLEMENTATION specific` per Scala Runner specification
Expand Down
10 changes: 9 additions & 1 deletion website/docs/reference/scala-command/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ Add Scala Native options

`//> using nativeCompile` _value1_ _value2_ …

`//> using nativeCCompile` _value1_ _value2_ …

`//> using nativeCppCompile` _value1_ _value2_ …

`//> using nativeLinking` _value1_ _value2_ …

`//> using nativeClang` _value_
Expand All @@ -346,10 +350,14 @@ Add Scala Native options

`//> using nativeLto full`

`//> using nativeVersion 0.5.8`
`//> using nativeVersion 0.5.9`

`//> using nativeCompile -flto=thin`

`//> using nativeCCompile -std=c17`

`//> using nativeCppCompile -std=c++17 -fcxx-exceptions`

`//> using nativeLinking -flto=thin`

`//> using nativeClang ./clang`
Expand Down
Loading