Another attempt at M1 compilation (#3859)

This commit is contained in:
Marcin Kostrzewa 2022-11-09 16:26:25 +01:00 committed by GitHub
parent e8f3ad3979
commit 23e04f905f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 18 deletions

View File

@ -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")
}

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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")
)