Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with main branch #36

Merged
merged 1 commit into from
Feb 28, 2024
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
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<final-fields-semantics> (none, relaxed, or stricts)")
.optional()
.action((x, c) => update(c)(_.copy(finalFields = Some(x))))
.text("Maximal number of allowed nested inlines.")
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ class ConfigConverterTest extends AnyFlatSpec {
config = dummyConfigOptions,
nativeConfig = NativeConfigOptions(
multithreadingSupport = true,
debugMetadata = true
incrementalCompilation = true
)
)
val optionsNegative = LinkerOptions(
classpath = dummyArguments.toList,
config = dummyConfigOptions,
nativeConfig = NativeConfigOptions(
multithreadingSupport = false,
debugMetadata = false
incrementalCompilation = false
)
)
val parsed = for {
Expand All @@ -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
)
}
)
Expand Down
Loading