Skip to content

Commit 62c2f8d

Browse files
committed
Make the build work on Apple M1 chips
Previously, the build failed to load on M1 computers because Coursier failed to fetch Java home for JVM version 8. Now, we force Coursier to use amd64 instead of aarch64. This may result in slightly slower builds, but it's a big improvement by the fact that the build loads and works correctly now.
1 parent 9a98c50 commit 62c2f8d

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

bin/coursier

83.5 KB
Binary file not shown.

build.sbt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.util.control.NoStackTrace
88

99
lazy val V =
1010
new {
11-
val protobuf = "3.15.6"
11+
val protobuf = "3.21.4"
1212
val coursier = "2.0.8"
1313
val bloop = "1.4.7"
1414
val bsp = "2.0.0-M13"
@@ -37,6 +37,7 @@ inThisBuild(
3737
organization := "com.sourcegraph",
3838
homepage := Some(url("https://github.com/sourcegraph/scip-java")),
3939
dynverSeparator := "-",
40+
PB.protocVersion := V.protobuf,
4041
licenses :=
4142
List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
4243
developers :=
@@ -243,9 +244,7 @@ lazy val cli = project
243244
"coursier",
244245
"java-home",
245246
"--jvm",
246-
"temurin:17",
247-
"--jvm-index",
248-
"https://github.com/coursier/jvm-index/blob/master/index.json"
247+
"17"
249248
)
250249

251250
// Install `scip-java` binary.
@@ -332,9 +331,7 @@ lazy val minimized17 = project
332331
.in(file("tests/minimized/.j17"))
333332
.settings(
334333
minimizedSettings,
335-
javaToolchainJvmIndex :=
336-
Some("https://github.com/coursier/jvm-index/blob/master/index.json"),
337-
javaToolchainVersion := "temurin:17",
334+
javaToolchainVersion := "17",
338335
javacOptions ++= javacModuleOptions
339336
)
340337
.dependsOn(agent, plugin)

project/JavaToolchainPlugin.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object JavaToolchainPlugin extends AutoPlugin {
6767
// The tools.jar file includes the bytecode for the Java compiler in the com.sun.source package.
6868
// The Java compiler is available by default in Java 9+, so we only need to add tools.jar to the
6969
// bootclasspath for Java 8.
70-
if (home.toString.contains("1.8") && toolsJar.isFile) {
70+
if (version == "8" && toolsJar.isFile) {
7171
List(s"-Xbootclasspath/p:$toolsJar")
7272
} else {
7373
List()
@@ -78,6 +78,7 @@ object JavaToolchainPlugin extends AutoPlugin {
7878
(getJavaHome("8") / "jre" / "lib" / "rt.jar").toString
7979
}
8080

81+
8182
private val javaHomeCache: util.Map[String, File] = Collections
8283
.synchronizedMap(new util.HashMap[String, File]())
8384
private def getJavaHome(
@@ -92,10 +93,19 @@ object JavaToolchainPlugin extends AutoPlugin {
9293
.toList
9394
.flatMap(index => "--jvm-index" :: index :: Nil)
9495
val arguments =
95-
List("java", "-jar", coursier.toString, "java-home", "--jvm", v) ++
96+
List("java", "-jar", coursier.toString, "java-home", "--jvm", v, "--architecture", jvmArchitecture(v)) ++
9697
index
9798
new File(Process(arguments).!!.trim)
9899
}
99100
)
100101
}
102+
103+
private def jvmArchitecture(jvmVersion: String): String =
104+
if (scala.util.Properties.isMac && sys.props("os.arch") == "aarch64") "amd64"
105+
else defaultCoursierJVMArchitecture
106+
def defaultCoursierJVMArchitecture: String =
107+
sys.props("os.arch") match{
108+
case "x86_64" => "amd64"
109+
case x => x
110+
}
101111
}

scip-java/src/main/resources/scip-java/coursier

100644100755
83.5 KB
Binary file not shown.

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/ScipBuildTool.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ class ScipBuildTool(index: IndexCommand) extends BuildTool("SCIP", index) {
503503
"java-home",
504504
"--jvm",
505505
config.jvm,
506-
"--jvm-index",
507-
"https://github.com/coursier/jvm-index/blob/master/index.json"
506+
"--architecture",
507+
jvmArchitecture
508508
)
509509
.call()
510510
.out
@@ -532,6 +532,15 @@ class ScipBuildTool(index: IndexCommand) extends BuildTool("SCIP", index) {
532532
Failure(SubprocessException(result))
533533
}
534534

535+
private def jvmArchitecture: String =
536+
if (scala.util.Properties.isMac && sys.props("os.arch") == "aarch64") "amd64"
537+
else defaultCoursierJVMArchitecture
538+
def defaultCoursierJVMArchitecture: String =
539+
sys.props("os.arch") match{
540+
case "x86_64" => "amd64"
541+
case x => x
542+
}
543+
535544
private def clean(): Unit = {
536545
Files.walkFileTree(targetroot, new DeleteVisitor)
537546
}

0 commit comments

Comments
 (0)