Skip to content

Commit c60aae8

Browse files
Sync with main branch (#36)
1 parent 654d085 commit c60aae8

File tree

8 files changed

+147
-18
lines changed

8 files changed

+147
-18
lines changed

build.sbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
val crossScalaVersions212 = (14 to 18).map("2.12." + _)
2-
val crossScalaVersions213 = (8 to 12).map("2.13." + _)
1+
val crossScalaVersions212 = (14 to 19).map("2.12." + _)
2+
val crossScalaVersions213 = (8 to 13).map("2.13." + _)
33
val crossScalaVersions3 =
44
(2 to 3).map("3.1." + _) ++
55
(0 to 2).map("3.2." + _) ++
6-
(0 to 1).map("3.3." + _)
6+
(0 to 2).map("3.3." + _) ++
7+
(0 to 0).map("3.4." + _)
78

89
val scala2_12 = crossScalaVersions212.last
910
val scala2_13 = crossScalaVersions213.last

cli/src/main/scala/scala/scalanative/cli/ScalaNativeLd.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ object ScalaNativeLd {
2424
ConfigOptions.set(this)
2525
NativeConfigOptions.set(this)
2626
OptimizerConfigOptions.set(this)
27+
SemanticsConfigOptions.set(this)
28+
SourceLevelDebuggingConfigOptions.set(this)
2729

2830
note("Logger options:")
2931
opt[Unit]("verbose")
@@ -75,6 +77,7 @@ object ScalaNativeLd {
7577
case Right(buildOptions) =>
7678
val outpath = Paths.get(options.config.outpath)
7779
val build = Scope { implicit scope =>
80+
println(buildOptions.config)
7881
Build
7982
.build(buildOptions.config)
8083
.map(

cli/src/main/scala/scala/scalanative/cli/options/LinkerOptions.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ case class LinkerOptions(
55
config: ConfigOptions = ConfigOptions(),
66
nativeConfig: NativeConfigOptions = NativeConfigOptions(),
77
optimizerConifg: OptimizerConfigOptions = OptimizerConfigOptions(),
8+
semanticsConfig: SemanticsConfigOptions = SemanticsConfigOptions(),
9+
sourceLevelDebuggingConfig: SourceLevelDebuggingConfigOptions =
10+
SourceLevelDebuggingConfigOptions(),
811
verbose: Int = 0
912
)

cli/src/main/scala/scala/scalanative/cli/options/NativeConfigOptions.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ case class NativeConfigOptions(
1717
noOptimize: Boolean = false,
1818
embedResources: Boolean = false,
1919
multithreadingSupport: Boolean = true,
20-
debugMetadata: Boolean = false,
2120
incrementalCompilation: Boolean = false,
2221
baseName: Option[String] = None,
2322
ltp: List[String] = List.empty,
@@ -122,16 +121,6 @@ object NativeConfigOptions {
122121
.text(
123122
"Should the target enable multihreading support for builds? [true]"
124123
)
125-
parser
126-
.opt[Boolean]("debug-info")
127-
.abbr("-g")
128-
.optional()
129-
.action((x, c) =>
130-
c.copy(nativeConfig = c.nativeConfig.copy(debugMetadata = x))
131-
)
132-
.text(
133-
"Should the build include additional debug information? These can be used for better stacktraces or debuging support [false]"
134-
)
135124
parser
136125
.opt[String]("base-name")
137126
.optional()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package scala.scalanative.cli.options
2+
3+
import scopt.OptionParser
4+
import scala.scalanative.build
5+
6+
case class SemanticsConfigOptions(
7+
finalFields: Option[JVMMemoryModelCompliance] = None
8+
)
9+
10+
sealed abstract class JVMMemoryModelCompliance {
11+
import JVMMemoryModelCompliance._
12+
def convert: build.JVMMemoryModelCompliance = this match {
13+
case None => build.JVMMemoryModelCompliance.None
14+
case Relaxed => build.JVMMemoryModelCompliance.Relaxed
15+
case Strict => build.JVMMemoryModelCompliance.Strict
16+
}
17+
}
18+
object JVMMemoryModelCompliance {
19+
case object None extends JVMMemoryModelCompliance
20+
case object Relaxed extends JVMMemoryModelCompliance
21+
case object Strict extends JVMMemoryModelCompliance
22+
23+
implicit val read: scopt.Read[JVMMemoryModelCompliance] =
24+
scopt.Read.reads {
25+
case "none" => JVMMemoryModelCompliance.None
26+
case "relaxed" => JVMMemoryModelCompliance.Relaxed
27+
case "strict" => JVMMemoryModelCompliance.Strict
28+
}
29+
}
30+
31+
object SemanticsConfigOptions {
32+
def set(parser: OptionParser[LinkerOptions]) = {
33+
def update(c: LinkerOptions)(
34+
fn: SemanticsConfigOptions => SemanticsConfigOptions
35+
) =
36+
c.copy(semanticsConfig = fn(c.semanticsConfig))
37+
parser.note("Semantics options:")
38+
parser
39+
.opt[JVMMemoryModelCompliance]("final-fields-semantics")
40+
.valueName("<final-fields-semantics> (none, relaxed, or stricts)")
41+
.optional()
42+
.action((x, c) => update(c)(_.copy(finalFields = Some(x))))
43+
.text("Maximal number of allowed nested inlines.")
44+
}
45+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package scala.scalanative.cli.options
2+
3+
import java.nio.file.{Path, Paths}
4+
import scopt.OptionParser
5+
6+
case class SourceLevelDebuggingConfigOptions(
7+
enabled: Option[Boolean] = None,
8+
genFunctionSourcePositions: Option[Boolean] = None,
9+
genLocalVariables: Option[Boolean] = None,
10+
customSourceRoots: Seq[Path] = Nil
11+
)
12+
13+
object SourceLevelDebuggingConfigOptions {
14+
def set(parser: OptionParser[LinkerOptions]) = {
15+
def update(c: LinkerOptions)(
16+
fn: SourceLevelDebuggingConfigOptions => SourceLevelDebuggingConfigOptions
17+
) =
18+
c.copy(sourceLevelDebuggingConfig = fn(c.sourceLevelDebuggingConfig))
19+
parser.note("Source Level Debugging options:")
20+
parser
21+
.opt[Boolean]("-debug-info")
22+
.optional()
23+
.action((x, c) => update(c)(_.copy(enabled = Some(x))))
24+
.text("Should enable generation of source level debug metadata")
25+
parser
26+
.opt[Unit]("debug-all")
27+
.abbr("g")
28+
.optional()
29+
.action((x, c) =>
30+
update(c)(
31+
_.copy(
32+
enabled = Some(true),
33+
genFunctionSourcePositions = Some(true),
34+
genLocalVariables = Some(true)
35+
)
36+
)
37+
)
38+
.text(
39+
"Should enable all debug metadata generation"
40+
)
41+
parser
42+
.opt[Boolean]("debug-function-source-positions")
43+
.optional()
44+
.action((x, c) => update(c)(_.copy(genFunctionSourcePositions = Some(x))))
45+
.text(
46+
"Should enable generation of function source position for stack traces"
47+
)
48+
parser
49+
.opt[Boolean]("debug-local-variables")
50+
.optional()
51+
.action((x, c) => update(c)(_.copy(genLocalVariables = Some(x))))
52+
.text("Should enable generation of localv variables metadata")
53+
parser
54+
.opt[String]("debug-source-root")
55+
.optional()
56+
.unbounded()
57+
.action((x, c) =>
58+
update(c)(cc =>
59+
cc.copy(customSourceRoots = Paths.get(x) +: cc.customSourceRoots)
60+
)
61+
)
62+
.text("Add custom sources root directory")
63+
}
64+
}

cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ object ConfigConverter {
101101
.withOptimizerConfig(generateOptimizerConfig(options.optimizerConifg))
102102
.withBaseName(baseName)
103103
.withMultithreadingSupport(options.nativeConfig.multithreadingSupport)
104+
.withSemanticsConfig(generateSemanticsConfig(options.semanticsConfig))
104105
.withSourceLevelDebuggingConfig(
105-
_.enabled(options.nativeConfig.debugMetadata)
106+
generateSourceLevelDebuggingConfig(options.sourceLevelDebuggingConfig)
106107
)
107108
}
108109

@@ -117,6 +118,29 @@ object ConfigConverter {
117118
c4
118119
}
119120

121+
private def generateSemanticsConfig(
122+
options: SemanticsConfigOptions
123+
): SemanticsConfig = {
124+
val c0 = SemanticsConfig.default
125+
val c1 =
126+
options.finalFields.map(_.convert).foldLeft(c0)(_.withFinalFields(_))
127+
c1
128+
}
129+
130+
private def generateSourceLevelDebuggingConfig(
131+
options: SourceLevelDebuggingConfigOptions
132+
): SourceLevelDebuggingConfig = {
133+
val c0 = SourceLevelDebuggingConfig.disabled.withCustomSourceRoots(
134+
options.customSourceRoots
135+
)
136+
val c1 = options.enabled.foldLeft(c0)(_.enabled(_))
137+
val c2 = options.genFunctionSourcePositions.foldLeft(c1)(
138+
_.generateFunctionSourcePositions(_)
139+
)
140+
val c3 = options.genLocalVariables.foldLeft(c2)(_.generateLocalVariables(_))
141+
c3
142+
}
143+
120144
private def generateConfig(
121145
options: LinkerOptions,
122146
main: Option[String],

cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ class ConfigConverterTest extends AnyFlatSpec {
206206
config = dummyConfigOptions,
207207
nativeConfig = NativeConfigOptions(
208208
multithreadingSupport = true,
209-
debugMetadata = true
209+
incrementalCompilation = true
210210
)
211211
)
212212
val optionsNegative = LinkerOptions(
213213
classpath = dummyArguments.toList,
214214
config = dummyConfigOptions,
215215
nativeConfig = NativeConfigOptions(
216216
multithreadingSupport = false,
217-
debugMetadata = false
217+
incrementalCompilation = false
218218
)
219219
)
220220
val parsed = for {
@@ -231,7 +231,7 @@ class ConfigConverterTest extends AnyFlatSpec {
231231
{ case (positive, negative) =>
232232
assert(positive.multithreadingSupport != negative.multithreadingSupport)
233233
assert(
234-
positive.sourceLevelDebuggingConfig.enabled != negative.sourceLevelDebuggingConfig.enabled
234+
positive.useIncrementalCompilation != negative.useIncrementalCompilation
235235
)
236236
}
237237
)

0 commit comments

Comments
 (0)