From 1f01a0ee6f0efb8e615d2fd934dbf01f8bc6dcc3 Mon Sep 17 00:00:00 2001 From: Kristian Nedrevold-Hansen Date: Sat, 11 Jan 2025 00:56:57 +0100 Subject: [PATCH] Better support for linking SN Includes new options for SN linking with new configuration options added to bloop-config --- .../bloop/scalanative/NativeBridge.scala | 35 +++++++++++++++--- .../bloop/scalanative/NativeBridge.scala | 37 ++++++++++++++++--- .../test/scala/bloop/bsp/BspLinkSpec.scala | 1 + project/Dependencies.scala | 2 +- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/bridges/scala-native-0.4/src/main/scala/bloop/scalanative/NativeBridge.scala b/bridges/scala-native-0.4/src/main/scala/bloop/scalanative/NativeBridge.scala index bf5df0f3b..4baf9eeb8 100644 --- a/bridges/scala-native-0.4/src/main/scala/bloop/scalanative/NativeBridge.scala +++ b/bridges/scala-native-0.4/src/main/scala/bloop/scalanative/NativeBridge.scala @@ -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) @@ -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 @@ -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) { diff --git a/bridges/scala-native-0.5/src/main/scala/bloop/scalanative/NativeBridge.scala b/bridges/scala-native-0.5/src/main/scala/bloop/scalanative/NativeBridge.scala index 16199ad91..b883f877e 100644 --- a/bridges/scala-native-0.5/src/main/scala/bloop/scalanative/NativeBridge.scala +++ b/bridges/scala-native-0.5/src/main/scala/bloop/scalanative/NativeBridge.scala @@ -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) @@ -30,6 +36,7 @@ object NativeBridge { logger: Logger, ec: ExecutionContext ): Future[Path] = { + val absWorkdir = AbsolutePath(workdir) if (absWorkdir.isDirectory) Paths.delete(absWorkdir) Files.createDirectories(workdir) @@ -37,14 +44,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.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 @@ -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) { diff --git a/frontend/src/test/scala/bloop/bsp/BspLinkSpec.scala b/frontend/src/test/scala/bloop/bsp/BspLinkSpec.scala index f8a4b541d..0dff665df 100644 --- a/frontend/src/test/scala/bloop/bsp/BspLinkSpec.scala +++ b/frontend/src/test/scala/bloop/bsp/BspLinkSpec.scala @@ -30,6 +30,7 @@ class BspLinkSpec( } } } + test("can link scala-native-05 cross project") { TestUtil.withinWorkspace { workspace => val logger = new RecordingLogger(ansiCodesSupported = false) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index b99112af1..184b33d01 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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