From c6f00b1ac8efbc313e9d9fd7d4ef0ffcc8414b75 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 28 Feb 2024 01:28:59 +0100 Subject: [PATCH] Sync with main branch --- build.sbt | 7 +- .../scala/scalanative/cli/ScalaNativeLd.scala | 3 + .../cli/options/LinkerOptions.scala | 3 + .../cli/options/NativeConfigOptions.scala | 11 ---- .../cli/options/SemanticsConfigOptions.scala | 45 +++++++++++++ .../SourceLevelDebuggingConfigOptions.scala | 64 +++++++++++++++++++ .../cli/utils/ConfigConverter.scala | 26 +++++++- .../cli/utils/ConfigConverterTest.scala | 6 +- 8 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 cli/src/main/scala/scala/scalanative/cli/options/SemanticsConfigOptions.scala create mode 100644 cli/src/main/scala/scala/scalanative/cli/options/SourceLevelDebuggingConfigOptions.scala diff --git a/build.sbt b/build.sbt index 4999df0..a829f38 100644 --- a/build.sbt +++ b/build.sbt @@ -1,9 +1,10 @@ -val crossScalaVersions212 = (14 to 18).map("2.12." + _) -val crossScalaVersions213 = (8 to 12).map("2.13." + _) +val crossScalaVersions212 = (14 to 19).map("2.12." + _) +val crossScalaVersions213 = (8 to 13).map("2.13." + _) val crossScalaVersions3 = (2 to 3).map("3.1." + _) ++ (0 to 2).map("3.2." + _) ++ - (0 to 1).map("3.3." + _) + (0 to 2).map("3.3." + _) ++ + (0 to 0).map("3.4." + _) val scala2_12 = crossScalaVersions212.last val scala2_13 = crossScalaVersions213.last diff --git a/cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala b/cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala index 358d5f9..df7e17c 100644 --- a/cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala +++ b/cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala @@ -24,6 +24,8 @@ object ScalaNativeLd { ConfigOptions.set(this) NativeConfigOptions.set(this) OptimizerConfigOptions.set(this) + SemanticsConfigOptions.set(this) + SourceLevelDebuggingConfigOptions.set(this) note("Logger options:") opt[Unit]("verbose") @@ -75,6 +77,7 @@ object ScalaNativeLd { case Right(buildOptions) => val outpath = Paths.get(options.config.outpath) val build = Scope { implicit scope => + println(buildOptions.config) Build .build(buildOptions.config) .map( diff --git a/cli/src/main/scala/scala/scalanative/cli/options/LinkerOptions.scala b/cli/src/main/scala/scala/scalanative/cli/options/LinkerOptions.scala index 4b4a854..8ef4e18 100644 --- a/cli/src/main/scala/scala/scalanative/cli/options/LinkerOptions.scala +++ b/cli/src/main/scala/scala/scalanative/cli/options/LinkerOptions.scala @@ -5,5 +5,8 @@ case class LinkerOptions( config: ConfigOptions = ConfigOptions(), nativeConfig: NativeConfigOptions = NativeConfigOptions(), optimizerConifg: OptimizerConfigOptions = OptimizerConfigOptions(), + semanticsConfig: SemanticsConfigOptions = SemanticsConfigOptions(), + sourceLevelDebuggingConfig: SourceLevelDebuggingConfigOptions = + SourceLevelDebuggingConfigOptions(), verbose: Int = 0 ) diff --git a/cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala b/cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala index 90ce772..701aa0c 100644 --- a/cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala +++ b/cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala @@ -17,7 +17,6 @@ case class NativeConfigOptions( noOptimize: Boolean = false, embedResources: Boolean = false, multithreadingSupport: Boolean = true, - debugMetadata: Boolean = false, incrementalCompilation: Boolean = false, baseName: Option[String] = None, ltp: List[String] = List.empty, @@ -122,16 +121,6 @@ object NativeConfigOptions { .text( "Should the target enable multihreading support for builds? [true]" ) - parser - .opt[Boolean]("debug-info") - .abbr("-g") - .optional() - .action((x, c) => - c.copy(nativeConfig = c.nativeConfig.copy(debugMetadata = x)) - ) - .text( - "Should the build include additional debug information? These can be used for better stacktraces or debuging support [false]" - ) parser .opt[String]("base-name") .optional() diff --git a/cli/src/main/scala/scala/scalanative/cli/options/SemanticsConfigOptions.scala b/cli/src/main/scala/scala/scalanative/cli/options/SemanticsConfigOptions.scala new file mode 100644 index 0000000..d8a92f2 --- /dev/null +++ b/cli/src/main/scala/scala/scalanative/cli/options/SemanticsConfigOptions.scala @@ -0,0 +1,45 @@ +package scala.scalanative.cli.options + +import scopt.OptionParser +import scala.scalanative.build + +case class SemanticsConfigOptions( + finalFields: Option[JVMMemoryModelCompliance] = None +) + +sealed abstract class JVMMemoryModelCompliance { + import JVMMemoryModelCompliance._ + def convert: build.JVMMemoryModelCompliance = this match { + case None => build.JVMMemoryModelCompliance.None + case Relaxed => build.JVMMemoryModelCompliance.Relaxed + case Strict => build.JVMMemoryModelCompliance.Strict + } +} +object JVMMemoryModelCompliance { + case object None extends JVMMemoryModelCompliance + case object Relaxed extends JVMMemoryModelCompliance + case object Strict extends JVMMemoryModelCompliance + + implicit val read: scopt.Read[JVMMemoryModelCompliance] = + scopt.Read.reads { + case "none" => JVMMemoryModelCompliance.None + case "relaxed" => JVMMemoryModelCompliance.Relaxed + case "strict" => JVMMemoryModelCompliance.Strict + } +} + +object SemanticsConfigOptions { + def set(parser: OptionParser[LinkerOptions]) = { + def update(c: LinkerOptions)( + fn: SemanticsConfigOptions => SemanticsConfigOptions + ) = + c.copy(semanticsConfig = fn(c.semanticsConfig)) + parser.note("Semantics options:") + parser + .opt[JVMMemoryModelCompliance]("final-fields-semantics") + .valueName(" (none, relaxed, or stricts)") + .optional() + .action((x, c) => update(c)(_.copy(finalFields = Some(x)))) + .text("Maximal number of allowed nested inlines.") + } +} diff --git a/cli/src/main/scala/scala/scalanative/cli/options/SourceLevelDebuggingConfigOptions.scala b/cli/src/main/scala/scala/scalanative/cli/options/SourceLevelDebuggingConfigOptions.scala new file mode 100644 index 0000000..19b93c4 --- /dev/null +++ b/cli/src/main/scala/scala/scalanative/cli/options/SourceLevelDebuggingConfigOptions.scala @@ -0,0 +1,64 @@ +package scala.scalanative.cli.options + +import java.nio.file.{Path, Paths} +import scopt.OptionParser + +case class SourceLevelDebuggingConfigOptions( + enabled: Option[Boolean] = None, + genFunctionSourcePositions: Option[Boolean] = None, + genLocalVariables: Option[Boolean] = None, + customSourceRoots: Seq[Path] = Nil +) + +object SourceLevelDebuggingConfigOptions { + def set(parser: OptionParser[LinkerOptions]) = { + def update(c: LinkerOptions)( + fn: SourceLevelDebuggingConfigOptions => SourceLevelDebuggingConfigOptions + ) = + c.copy(sourceLevelDebuggingConfig = fn(c.sourceLevelDebuggingConfig)) + parser.note("Source Level Debugging options:") + parser + .opt[Boolean]("-debug-info") + .optional() + .action((x, c) => update(c)(_.copy(enabled = Some(x)))) + .text("Should enable generation of source level debug metadata") + parser + .opt[Unit]("debug-all") + .abbr("g") + .optional() + .action((x, c) => + update(c)( + _.copy( + enabled = Some(true), + genFunctionSourcePositions = Some(true), + genLocalVariables = Some(true) + ) + ) + ) + .text( + "Should enable all debug metadata generation" + ) + parser + .opt[Boolean]("debug-function-source-positions") + .optional() + .action((x, c) => update(c)(_.copy(genFunctionSourcePositions = Some(x)))) + .text( + "Should enable generation of function source position for stack traces" + ) + parser + .opt[Boolean]("debug-local-variables") + .optional() + .action((x, c) => update(c)(_.copy(genLocalVariables = Some(x)))) + .text("Should enable generation of localv variables metadata") + parser + .opt[String]("debug-source-root") + .optional() + .unbounded() + .action((x, c) => + update(c)(cc => + cc.copy(customSourceRoots = Paths.get(x) +: cc.customSourceRoots) + ) + ) + .text("Add custom sources root directory") + } +} diff --git a/cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala b/cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala index 20d8fd4..827fbff 100644 --- a/cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala +++ b/cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala @@ -101,8 +101,9 @@ object ConfigConverter { .withOptimizerConfig(generateOptimizerConfig(options.optimizerConifg)) .withBaseName(baseName) .withMultithreadingSupport(options.nativeConfig.multithreadingSupport) + .withSemanticsConfig(generateSemanticsConfig(options.semanticsConfig)) .withSourceLevelDebuggingConfig( - _.enabled(options.nativeConfig.debugMetadata) + generateSourceLevelDebuggingConfig(options.sourceLevelDebuggingConfig) ) } @@ -117,6 +118,29 @@ object ConfigConverter { c4 } + private def generateSemanticsConfig( + options: SemanticsConfigOptions + ): SemanticsConfig = { + val c0 = SemanticsConfig.default + val c1 = + options.finalFields.map(_.convert).foldLeft(c0)(_.withFinalFields(_)) + c1 + } + + private def generateSourceLevelDebuggingConfig( + options: SourceLevelDebuggingConfigOptions + ): SourceLevelDebuggingConfig = { + val c0 = SourceLevelDebuggingConfig.disabled.withCustomSourceRoots( + options.customSourceRoots + ) + val c1 = options.enabled.foldLeft(c0)(_.enabled(_)) + val c2 = options.genFunctionSourcePositions.foldLeft(c1)( + _.generateFunctionSourcePositions(_) + ) + val c3 = options.genLocalVariables.foldLeft(c2)(_.generateLocalVariables(_)) + c3 + } + private def generateConfig( options: LinkerOptions, main: Option[String], diff --git a/cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala b/cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala index 94eb174..b08ba12 100644 --- a/cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala +++ b/cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala @@ -206,7 +206,7 @@ class ConfigConverterTest extends AnyFlatSpec { config = dummyConfigOptions, nativeConfig = NativeConfigOptions( multithreadingSupport = true, - debugMetadata = true + incrementalCompilation = true ) ) val optionsNegative = LinkerOptions( @@ -214,7 +214,7 @@ class ConfigConverterTest extends AnyFlatSpec { config = dummyConfigOptions, nativeConfig = NativeConfigOptions( multithreadingSupport = false, - debugMetadata = false + incrementalCompilation = false ) ) val parsed = for { @@ -231,7 +231,7 @@ class ConfigConverterTest extends AnyFlatSpec { { case (positive, negative) => assert(positive.multithreadingSupport != negative.multithreadingSupport) assert( - positive.sourceLevelDebuggingConfig.enabled != negative.sourceLevelDebuggingConfig.enabled + positive.useIncrementalCompilation != negative.useIncrementalCompilation ) } )