From 23e04f905f89b857ecd58a733f1aad4a63338513 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewa Date: Wed, 9 Nov 2022 16:26:25 +0100 Subject: [PATCH] Another attempt at M1 compilation (#3859) --- build.sbt | 41 +++++++++++++++---- .../java/org/enso/syntax2/Parser.java | 3 +- project/BuildInfo.scala | 2 +- project/DistributionPackage.scala | 12 ++---- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/build.sbt b/build.sbt index 30225f2a4ca..c71ac5a387a 100644 --- a/build.sbt +++ b/build.sbt @@ -667,11 +667,23 @@ lazy val `text-buffer` = project ) ) +lazy val rustParserTargetDirectory = + SettingKey[File]("target directory for the Rust parser") + +(`syntax-rust-definition` / rustParserTargetDirectory) := { + // setting "debug" for release, because it isn't yet safely integrated into + // the parser definition + val versionName = if (BuildInfo.isReleaseMode) "debug" else "debug" + target.value / "rust" / versionName +} + val generateRustParserLib = TaskKey[Seq[File]]("generateRustParserLib", "Generates parser native library") `syntax-rust-definition` / generateRustParserLib := { import sys.process._ - val libGlob = target.value.toGlob / "rust" / * / "libenso_parser.so" + val libGlob = + (`syntax-rust-definition` / rustParserTargetDirectory).value.toGlob / "libenso_parser.so" + val allLibs = FileTreeView.default.list(Seq(libGlob)).map(_._1) if ( sys.env.get("CI").isDefined || @@ -679,11 +691,25 @@ val generateRustParserLib = (`syntax-rust-definition` / generateRustParserLib).inputFileChanges.hasChanges ) { val os = System.getProperty("os.name") - if (os.startsWith("Mac")) { - Seq("cargo", "build", "-p", "enso-parser-jni", "--target", "x86_64-apple-darwin") ! - } else { - Seq("cargo", "build", "-p", "enso-parser-jni") ! - } + val baseCommand = Seq( + "cargo", + "build", + "-p", + "enso-parser-jni", + "-Z", + "unstable-options", + "--out-dir", + (`syntax-rust-definition` / rustParserTargetDirectory).value.toString + ) + val releaseMode = baseCommand ++ + (if (BuildInfo.isReleaseMode) + Seq("--release") + else Seq()) + val macBuild = releaseMode ++ + (if (os.contains("Mac")) + Seq("--target", "x86_64-apple-darwin") + else Seq()) + macBuild ! } FileTreeView.default.list(Seq(libGlob)).map(_._1.toFile) } @@ -2041,7 +2067,8 @@ buildEngineDistribution := { ensoVersion = ensoVersion, editionName = currentEdition, sourceStdlibVersion = stdLibVersion, - targetStdlibVersion = targetStdlibVersion + targetStdlibVersion = targetStdlibVersion, + targetDir = (`syntax-rust-definition` / rustParserTargetDirectory).value ) log.info(s"Engine package created at $root") } diff --git a/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java b/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java index 93b6a7db34a..8b528a84cac 100644 --- a/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java +++ b/lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java @@ -27,8 +27,7 @@ public final class Parser implements AutoCloseable { } catch (URISyntaxException | LinkageError e) { System.err.println("Cannot load " + parser); File root = new File(".").getAbsoluteFile(); - if (!searchFromDirToTop(e, root, "target", "rust", "x86_64-apple-darwin", "debug", name) - && !searchFromDirToTop(e, root, "target", "rust", "debug", name)) { + if (!searchFromDirToTop(e, root, "target", "rust", "debug", name)) { throw new IllegalStateException("Cannot load parser from " + parser, e); } } diff --git a/project/BuildInfo.scala b/project/BuildInfo.scala index 92cda64ae55..a33fea224de 100644 --- a/project/BuildInfo.scala +++ b/project/BuildInfo.scala @@ -63,7 +63,7 @@ object BuildInfo { Seq(file) } - private def isReleaseMode: Boolean = + def isReleaseMode: Boolean = sys.env.get("ENSO_RELEASE_MODE").contains("true") /** Information regarding the Git repository that was used in the build. diff --git a/project/DistributionPackage.scala b/project/DistributionPackage.scala index 57d5dcbcbfe..88fffdd7abf 100644 --- a/project/DistributionPackage.scala +++ b/project/DistributionPackage.scala @@ -120,7 +120,8 @@ object DistributionPackage { ensoVersion: String, editionName: String, sourceStdlibVersion: String, - targetStdlibVersion: String + targetStdlibVersion: String, + targetDir: File ): Unit = { copyDirectoryIncremental( @@ -136,12 +137,7 @@ object DistributionPackage { ) val os = System.getProperty("os.name") val isMac = os.startsWith("Mac") - val dir = if (isMac) { - "target/rust/x86_64-apple-darwin/debug/" - } else { - "target/rust/debug/" - } - val parser = dir + (if (isMac) { + val parser = targetDir / (if (isMac) { "libenso_parser.dylib" } else if (os.startsWith("Windows")) { "enso_parser.dll" @@ -149,7 +145,7 @@ object DistributionPackage { "libenso_parser.so" }) copyFilesIncremental( - Seq(file(parser)), + Seq(parser), distributionRoot / "component", cacheFactory.make("engine-parser-library") )