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

Better support for linking SN #2567

Merged
merged 2 commits into from
Jan 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import scala.scalanative.util.Scope
import bloop.config.Config.LinkerMode
import bloop.config.Config.NativeConfig
import bloop.config.Config.NativeBuildTarget
import bloop.config.Config.NativeLTO.Full
import bloop.config.Config.NativeLTO
import bloop.config.Config.NativeLTO.Thin
import scala.scalanative.build.BuildTarget
import bloop.io.Paths
import bloop.io.AbsolutePath
import bloop.logging.DebugFilter
import bloop.logging.Logger
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseFast
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseFull
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseSize

class NativeLinkerException(msg: String) extends RuntimeException(msg)

Expand All @@ -35,14 +41,30 @@ object NativeBridge {
val nativeLogger =
build.Logger(logger.trace _, logger.debug _, logger.info _, logger.warn _, logger.error _)
val config = setUpNativeConfig(classpath, config0)

val nativeMode = config.mode match {
case LinkerMode.Debug => build.Mode.debug
case LinkerMode.Release => build.Mode.releaseFast
case LinkerMode.Release =>
config.nativeModeAndLTO.nativeLinkerReleaseMode match {
case None => build.Mode.releaseFast

case Some(mode) =>
mode match {
case ReleaseFast => build.Mode.releaseFast
case ReleaseFull => build.Mode.releaseFull
case ReleaseSize => build.Mode.releaseFast
}
}
}
val nativeLTO = config.mode match {
case LinkerMode.Debug => build.LTO.none
case LinkerMode.Release if bloop.util.CrossPlatform.isMac => build.LTO.full
case LinkerMode.Release => build.LTO.thin

val nativeLTO = config.nativeModeAndLTO.lto match {
case None => build.LTO.none
case Some(lto) =>
lto match {
case Full => build.LTO.full
case NativeLTO.None => build.LTO.none
case Thin => build.LTO.thin
}
}

val buildTarget = config.buildTarget
Expand Down Expand Up @@ -72,6 +94,9 @@ object NativeBridge {
.withCheck(config.check)
.withDump(config.dump)
.withTargetTriple(config.targetTriple)
.withOptimize(config.nativeFlags.optimize)
.withEmbedResources(config.nativeFlags.embedResources)
.withIncrementalCompilation(config.nativeFlags.useIncrementalCompilation)
)

if (buildTarget == BuildTarget.application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import bloop.io.Paths
import bloop.io.AbsolutePath
import bloop.logging.DebugFilter
import bloop.logging.Logger
import bloop.config.Config.NativeLTO.Full
import bloop.config.Config.NativeLTO
import bloop.config.Config.NativeLTO.Thin
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseFast
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseFull
import bloop.config.Config.NativeLinkerReleaseMode.ReleaseSize

class NativeLinkerException(msg: String) extends RuntimeException(msg)

Expand All @@ -30,21 +36,38 @@ object NativeBridge {
logger: Logger,
ec: ExecutionContext
): Future[Path] = {

val absWorkdir = AbsolutePath(workdir)
if (absWorkdir.isDirectory) Paths.delete(absWorkdir)
Files.createDirectories(workdir)

val nativeLogger =
build.Logger(logger.trace _, logger.debug _, logger.info _, logger.warn _, logger.error _)
val config = setUpNativeConfig(classpath, config0)

val nativeMode = config.mode match {
case LinkerMode.Debug => build.Mode.debug
case LinkerMode.Release => build.Mode.releaseFast
case LinkerMode.Release =>
config.nativeModeAndLTO.nativeLinkerReleaseMode match {
case None => build.Mode.releaseFast

case Some(mode) =>
mode match {
case ReleaseFast => build.Mode.releaseFast
case ReleaseFull => build.Mode.releaseFull
case ReleaseSize => build.Mode.releaseFast
}
}
}
val nativeLTO = config.mode match {
case LinkerMode.Debug => build.LTO.none
case LinkerMode.Release if bloop.util.CrossPlatform.isMac => build.LTO.none
case LinkerMode.Release => build.LTO.thin

val nativeLTO = config.nativeModeAndLTO.lto match {
case None => build.LTO.none
case Some(lto) =>
lto match {
case Full => build.LTO.full
case NativeLTO.None => build.LTO.none
case Thin => build.LTO.thin
}
}

val buildTarget = config.buildTarget
Expand Down Expand Up @@ -75,6 +98,10 @@ object NativeBridge {
.withCheck(config.check)
.withDump(config.dump)
.withTargetTriple(config.targetTriple)
.withOptimize(config.nativeFlags.optimize)
.withEmbedResources(config.nativeFlags.embedResources)
.withIncrementalCompilation(config.nativeFlags.useIncrementalCompilation)
.withMultithreading(config.nativeFlags.multithreading)
)

if (buildTarget == BuildTarget.application) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/scala/bloop/bsp/BspLinkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BspLinkSpec(
}
}
}

test("can link scala-native-05 cross project") {
TestUtil.withinWorkspace { workspace =>
val logger = new RecordingLogger(ansiCodesSupported = false)
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Dependencies {
val asmVersion = "9.7.1"
val ztExecVersion = "1.12"
val debugAdapterVersion = "4.2.1"
val bloopConfigVersion = "2.2.0"
val bloopConfigVersion = "2.3.0"
val semanticdbVersion = "4.9.9"
val zinc = "org.scala-sbt" %% "zinc" % zincVersion
val bsp4s = "ch.epfl.scala" %% "bsp4s" % bspVersion
Expand Down
Loading