diff --git a/modules/build/src/test/scala/scala/build/tests/ScalaNativeUsingDirectiveTests.scala b/modules/build/src/test/scala/scala/build/tests/ScalaNativeUsingDirectiveTests.scala index be5c7d76bf..3fab0b285f 100644 --- a/modules/build/src/test/scala/scala/build/tests/ScalaNativeUsingDirectiveTests.scala +++ b/modules/build/src/test/scala/scala/build/tests/ScalaNativeUsingDirectiveTests.scala @@ -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" -> diff --git a/modules/cli/src/main/scala/scala/cli/commands/shared/ScalaNativeOptions.scala b/modules/cli/src/main/scala/scala/cli/commands/shared/ScalaNativeOptions.scala index 79286e3b94..1f8027fe5e 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/shared/ScalaNativeOptions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/shared/ScalaNativeOptions.scala @@ -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") diff --git a/modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala b/modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala index efc9a76d48..773d5931f6 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala @@ -273,6 +273,8 @@ final case class SharedOptions( linkingOptions = nativeLinking, linkingDefaults = nativeLinkingDefaults, compileOptions = nativeCompile, + cCompileOptions = nativeCCompile, + cppCompileOptions = nativeCppCompile, compileDefaults = nativeCompileDefaults, embedResources = embedResources, buildTargetStr = nativeTarget, diff --git a/modules/directives/src/main/scala/scala/build/preprocessing/directives/ScalaNative.scala b/modules/directives/src/main/scala/scala/build/preprocessing/directives/ScalaNative.scala index 2c5902b2ba..3ae63be429 100644 --- a/modules/directives/src/main/scala/scala/build/preprocessing/directives/ScalaNative.scala +++ b/modules/directives/src/main/scala/scala/build/preprocessing/directives/ScalaNative.scala @@ -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++") @@ -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_ @@ -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") @@ -74,6 +82,8 @@ final case class ScalaNative( ltoStr = nativeLto, version = nativeVersion, compileOptions = nativeCompile, + cCompileOptions = nativeCCompile, + cppCompileOptions = nativeCppCompile, linkingOptions = nativeLinking, clang = nativeClang, clangpp = nativeClangPP, diff --git a/modules/options/src/main/scala/scala/build/options/ScalaNativeOptions.scala b/modules/options/src/main/scala/scala/build/options/ScalaNativeOptions.scala index 03834b16c7..909dce678c 100644 --- a/modules/options/src/main/scala/scala/build/options/ScalaNativeOptions.scala +++ b/modules/options/src/main/scala/scala/build/options/ScalaNativeOptions.scala @@ -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, @@ -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)) @@ -176,6 +182,8 @@ final case class ScalaNativeOptions( clangppCliOption() ++ linkingCliOptions() ++ compileCliOptions() ++ + cCompileCliOptions() ++ + cppCompileCliOptions() ++ resourcesCliOptions(resourcesExist) ++ targetCliOption() ++ multithreadingCliOption() diff --git a/project/deps/package.mill.scala b/project/deps/package.mill.scala index 130c38669a..a9d67be825 100644 --- a/project/deps/package.mill.scala +++ b/project/deps/package.mill.scala @@ -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 diff --git a/website/docs/reference/cli-options.md b/website/docs/reference/cli-options.md index ccb9728014..6c8d1aaf42 100644 --- a/website/docs/reference/cli-options.md +++ b/website/docs/reference/cli-options.md @@ -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` @@ -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] diff --git a/website/docs/reference/directives.md b/website/docs/reference/directives.md index a52e7cef31..9f54bf9625 100644 --- a/website/docs/reference/directives.md +++ b/website/docs/reference/directives.md @@ -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_ @@ -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` diff --git a/website/docs/reference/scala-command/cli-options.md b/website/docs/reference/scala-command/cli-options.md index 370ac5980b..44ccb4c197 100644 --- a/website/docs/reference/scala-command/cli-options.md +++ b/website/docs/reference/scala-command/cli-options.md @@ -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` @@ -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 diff --git a/website/docs/reference/scala-command/directives.md b/website/docs/reference/scala-command/directives.md index 601ba675d6..38e36f4aa4 100644 --- a/website/docs/reference/scala-command/directives.md +++ b/website/docs/reference/scala-command/directives.md @@ -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_ @@ -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` diff --git a/website/docs/reference/scala-command/runner-specification.md b/website/docs/reference/scala-command/runner-specification.md index 585a3ee9f4..b09fe63dfb 100644 --- a/website/docs/reference/scala-command/runner-specification.md +++ b/website/docs/reference/scala-command/runner-specification.md @@ -178,7 +178,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** @@ -200,6 +200,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -972,7 +980,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** @@ -994,6 +1002,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -1567,7 +1583,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** @@ -1589,6 +1605,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -2188,7 +2212,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** @@ -2210,6 +2234,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -2828,7 +2860,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** @@ -2850,6 +2882,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -3444,7 +3484,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** @@ -3466,6 +3506,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -4097,7 +4145,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** @@ -4119,6 +4167,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -4810,7 +4866,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** @@ -4832,6 +4888,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type @@ -5779,7 +5843,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** @@ -5801,6 +5865,14 @@ Extra options passed to `clang` verbatim during linking 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-target** Build target type