Skip to content

Commit

Permalink
Use sbt-native-packager instead of sbt-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Jun 11, 2024
1 parent e2dfea3 commit ae7a49c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
54 changes: 35 additions & 19 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import Process._
import Modes._
import ScaladocGeneration._
import com.jsuereth.sbtpgp.PgpKeys
import sbt.Keys._
import sbt._
import complete.DefaultParsers._
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.MappingsHelper.directory
import com.typesafe.sbt.packager.universal.UniversalPlugin
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universal
import com.typesafe.sbt.packager.windows.WindowsPlugin
import com.typesafe.sbt.packager.windows.WindowsPlugin.autoImport.Windows
import sbt.Keys.*
import sbt.*
import complete.DefaultParsers.*
import pl.project13.scala.sbt.JmhPlugin
import pl.project13.scala.sbt.JmhPlugin.JmhKeys.Jmh
import sbt.Package.ManifestAttributes
Expand All @@ -16,8 +22,6 @@ import dotty.tools.sbtplugin.RepublishPlugin
import dotty.tools.sbtplugin.RepublishPlugin.autoImport._
import sbt.plugins.SbtPlugin
import sbt.ScriptedPlugin.autoImport._
import xerial.sbt.pack.PackPlugin
import xerial.sbt.pack.PackPlugin.autoImport._
import xerial.sbt.Sonatype.autoImport._
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
import org.scalajs.sbtplugin.ScalaJSPlugin
Expand Down Expand Up @@ -2121,18 +2125,20 @@ object Build {
)

lazy val commonDistSettings = Seq(
packMain := Map(),
publishArtifact := false,
packGenerateMakefile := false,
republishRepo := target.value / "republish",
packResourceDir += (republishRepo.value / "bin" -> "bin"),
packResourceDir += (republishRepo.value / "maven2" -> "maven2"),
Compile / pack := (Compile / pack).dependsOn(republish).value,
Universal / packageName := packageName.value,
Universal / stage := (Universal / stage).dependsOn(republish).value,
Universal / packageBin := (Universal / packageBin).dependsOn(republish).value,
// ========
Universal / mappings ++= directory(republishRepo.value / "bin"),
Universal / mappings ++= (Compile / dependencyClasspathAsJars).value.map(jar => jar.data -> s"lib/${jar.data.getName}"),
Universal / mappings ++= directory(republishRepo.value / "maven2"),
)

lazy val dist = project.asDist(Bootstrapped)
.settings(packageName := "scala3-" + dottyVersion)
.settings(
packArchiveName := "scala3-" + dottyVersion,
republishBinDir := baseDirectory.value / "bin",
republishCoursier +=
("coursier.jar" -> s"https://github.com/coursier/coursier/releases/download/v$coursierJarVersion/coursier.jar"),
Expand All @@ -2141,51 +2147,62 @@ object Build {
)

lazy val `dist-mac-x86_64` = project.in(file("dist/mac-x86_64")).asDist(Bootstrapped)
.settings(packageName := (dist / packageName).value + "-x86_64-apple-darwin")
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-apple-darwin",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishFetchCoursier := (dist / republishFetchCoursier).value,
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-x86_64-apple-darwin.gz")
)

lazy val `dist-mac-aarch64` = project.in(file("dist/mac-aarch64")).asDist(Bootstrapped)
.settings(packageName := (dist / packageName).value + "-aarch64-apple-darwin")
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-aarch64-apple-darwin",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishFetchCoursier := (dist / republishFetchCoursier).value,
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-aarch64-apple-darwin.gz")
)

lazy val `dist-win-x86_64` = project.in(file("dist/win-x86_64")).asDist(Bootstrapped)
.enablePlugins(WindowsPlugin) // TO GENERATE THE `.msi` installer
.settings(packageName := (dist / packageName).value + "-x86_64-pc-win32")
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-pc-win32",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishFetchCoursier := (dist / republishFetchCoursier).value,
republishExtraProps += ("cli_version" -> scalaCliLauncherVersion),
mappings += (republishRepo.value / "etc" / "EXTRA_PROPERTIES" -> "EXTRA_PROPERTIES"),
republishLaunchers +=
("scala-cli.exe" -> s"zip+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersionWindows/scala-cli-x86_64-pc-win32.zip!/scala-cli.exe")
)
.settings(
Universal / mappings += (republishRepo.value / "etc" / "EXTRA_PROPERTIES" -> "EXTRA_PROPERTIES"),
)
.settings(
Windows / mappings := (Universal / mappings).value,
maintainer := "Josh Suereth <[email protected]>",
packageSummary := "test-windows",
packageDescription := """Test Windows MSI.""",
wixProductId := "ce07be71-510d-414a-92d4-dff47631848a",
wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424"
)

lazy val `dist-linux-x86_64` = project.in(file("dist/linux-x86_64")).asDist(Bootstrapped)
.settings(packageName := (dist / packageName).value + "-x86_64-pc-linux")
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-x86_64-pc-linux",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishFetchCoursier := (dist / republishFetchCoursier).value,
republishLaunchers +=
("scala-cli" -> s"gz+https://github.com/VirtusLab/scala-cli/releases/download/v$scalaCliLauncherVersion/scala-cli-x86_64-pc-linux.gz")
)

lazy val `dist-linux-aarch64` = project.in(file("dist/linux-aarch64")).asDist(Bootstrapped)
.settings(packageName := (dist / packageName).value + "-aarch64-pc-linux")
.settings(
republishBinDir := (dist / republishBinDir).value,
packArchiveName := (dist / packArchiveName).value + "-aarch64-pc-linux",
republishBinOverrides += (dist / baseDirectory).value / "bin-native-overrides",
republishFetchCoursier := (dist / republishFetchCoursier).value,
republishLaunchers +=
Expand Down Expand Up @@ -2323,7 +2340,7 @@ object Build {
settings(scala3PresentationCompilerBuildInfo)

def asDist(implicit mode: Mode): Project = project.
enablePlugins(PackPlugin, RepublishPlugin).
enablePlugins(UniversalPlugin, RepublishPlugin).
withCommonSettings.
settings(commonDistSettings).
dependsOn(
Expand Down Expand Up @@ -2419,7 +2436,6 @@ object ScaladocConfigs {
}

lazy val DefaultGenerationConfig = Def.task {
def distLocation = (dist / Compile / pack).value
DefaultGenerationSettings.value
}

Expand Down
19 changes: 8 additions & 11 deletions project/RepublishPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package dotty.tools.sbtplugin

import sbt._
import xerial.sbt.pack.PackPlugin
import sbt.Keys._
import com.typesafe.sbt.packager.universal.UniversalPlugin
import sbt.*
import sbt.Keys.*
import sbt.AutoPlugin
import sbt.PublishBinPlugin
import sbt.PublishBinPlugin.autoImport._
import sbt.PublishBinPlugin.autoImport.*
import sbt.io.Using
import sbt.util.CacheImplicits._
import sbt.util.CacheImplicits.*

import scala.collection.mutable
import java.nio.file.Files

import java.nio.file.attribute.PosixFilePermission
import java.nio.file.{Files, Path}

import scala.jdk.CollectionConverters._
import java.nio.file.Path
import scala.jdk.CollectionConverters.*

/** This local plugin provides ways of publishing a project classpath and library dependencies to
* .a local repository */
Expand Down Expand Up @@ -52,7 +49,7 @@ object RepublishPlugin extends AutoPlugin {
}

override def trigger = allRequirements
override def requires = super.requires && PublishBinPlugin && PackPlugin
override def requires = super.requires && PublishBinPlugin && UniversalPlugin

object autoImport {
val republishProjectRefs = taskKey[Seq[ProjectRef]]("fetch the classpath deps from the project.")
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")

addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.17")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.5")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.2")

addSbtPlugin("ch.epfl.scala" % "sbt-tasty-mima" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.6")

0 comments on commit ae7a49c

Please sign in to comment.