Skip to content

Commit

Permalink
Merge pull request #102 from KristianAN/main
Browse files Browse the repository at this point in the history
Add support for defining the application/library type of scala-native project
  • Loading branch information
tgodzik authored Dec 18, 2024
2 parents eeb76eb + f32e806 commit 828b786
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
13 changes: 12 additions & 1 deletion config/src/bloop/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ object Config {
linkStubs: Boolean,
check: Boolean,
dump: Boolean,
output: Option[Path]
output: Option[Path],
@unroll buildTarget: Option[NativeBuildTarget] = None
) extends PlatformConfig

object NativeConfig {
Expand All @@ -236,6 +237,16 @@ object Config {
// FORMAT: ON
}

sealed abstract class NativeBuildTarget(val id: String)
object NativeBuildTarget {
case object Application extends NativeBuildTarget("application")
case object LibraryDynamic extends NativeBuildTarget("dynamic")
case object LibraryStatic extends NativeBuildTarget("static")

val All: List[String] =
List(Application.id, LibraryDynamic.id, LibraryStatic.id)
}

case class NativeOptions(linker: List[String], compiler: List[String])
object NativeOptions {
val empty: NativeOptions = NativeOptions(Nil, Nil)
Expand Down
40 changes: 40 additions & 0 deletions config/src/bloop/config/ConfigCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,46 @@ object ConfigCodecs {
}
}

implicit val codecNativBuildTarget
: JsonValueCodec[Config.NativeBuildTarget] = {
new JsonValueCodec[Config.NativeBuildTarget] {
val nullValue: Config.NativeBuildTarget =
null.asInstanceOf[Config.NativeBuildTarget]
def encodeValue(x: Config.NativeBuildTarget, out: JsonWriter): Unit = {
val str = x match {
case Config.NativeBuildTarget.Application =>
Config.NativeBuildTarget.Application.id
case Config.NativeBuildTarget.LibraryDynamic =>
Config.NativeBuildTarget.LibraryDynamic.id
case Config.NativeBuildTarget.LibraryStatic =>
Config.NativeBuildTarget.LibraryStatic.id
}
out.writeVal(str)
}
def decodeValue(
in: JsonReader,
default: Config.NativeBuildTarget
): Config.NativeBuildTarget =
if (in.isNextToken('"')) {
in.rollbackToken()
in.readString(null) match {
case Config.NativeBuildTarget.Application.id =>
Config.NativeBuildTarget.Application
case Config.NativeBuildTarget.LibraryDynamic.id =>
Config.NativeBuildTarget.LibraryDynamic
case Config.NativeBuildTarget.LibraryStatic.id =>
Config.NativeBuildTarget.LibraryStatic
case _ =>
in.decodeError(
s"Expected build target ${Config.NativeBuildTarget.All.mkString("'", "', '", "'")}"
)
}
} else {
in.rollbackToken()
nullValue
}
}
}
implicit val codecJvmConfig: JsonValueCodec[Config.JvmConfig] =
JsonCodecMaker.makeWithRequiredCollectionFields[Config.JvmConfig]

Expand Down

0 comments on commit 828b786

Please sign in to comment.