mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 11:52:59 +03:00
Including enso_parser library in the engine distribution (#3842)
Make sure `libenso_parser.so`, `.dll` or `.dylib` are packaged and included when `sbt buildEngineDistribution`. # Important Notes There was [a discussion](https://discord.com/channels/401396655599124480/1036562819644141598) about proper location of the library. It was concluded that _"there's no functional difference between a dylib and a jar."_ and as such the library is placed in `component` folder. Currently the old parser is still used for parsing. This PR just integrates the build system changes and makes us ready for smooth flipping of the parser in the future as part of #3611.
This commit is contained in:
parent
418120f16c
commit
85f71cbfc8
@ -678,7 +678,12 @@ val generateRustParserLib =
|
||||
allLibs.isEmpty ||
|
||||
(`syntax-rust-definition` / generateRustParserLib).inputFileChanges.hasChanges
|
||||
) {
|
||||
Seq("cargo", "build", "-p", "enso-parser-jni") !
|
||||
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") !
|
||||
}
|
||||
}
|
||||
FileTreeView.default.list(Seq(libGlob)).map(_._1.toFile)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.syntax2;
|
||||
|
||||
import org.enso.syntax2.Message;
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -9,26 +9,50 @@ import java.nio.charset.StandardCharsets;
|
||||
public final class Parser implements AutoCloseable {
|
||||
static {
|
||||
String os = System.getProperty("os.name");
|
||||
File dir = new File(".").getAbsoluteFile();
|
||||
for (; ; ) {
|
||||
File parser;
|
||||
if (os.startsWith("Mac")) {
|
||||
parser = new File(dir, "target/rust/debug/libenso_parser.dylib");
|
||||
} else if (os.startsWith("Windows")) {
|
||||
parser = new File(dir, "target/rust/debug/enso_parser.dll");
|
||||
} else {
|
||||
parser = new File(dir, "target/rust/debug/libenso_parser.so");
|
||||
String name;
|
||||
if (os.startsWith("Mac")) {
|
||||
name = "libenso_parser.dylib";
|
||||
} else if (os.startsWith("Windows")) {
|
||||
name = "enso_parser.dll";
|
||||
} else {
|
||||
name = "libenso_parser.so";
|
||||
}
|
||||
|
||||
File parser = null;
|
||||
try {
|
||||
var whereAmI = Parser.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
File dir = new File(whereAmI.toURI()).getParentFile();
|
||||
parser = new File(dir, name);
|
||||
System.load(parser.getAbsolutePath());
|
||||
} 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)) {
|
||||
throw new IllegalStateException("Cannot load parser from " + parser, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean searchFromDirToTop(Throwable chain, File root, String... names) {
|
||||
while (root != null) {
|
||||
var parser = root;
|
||||
for (var e : names) {
|
||||
parser = new File(parser, e);
|
||||
}
|
||||
try {
|
||||
System.load(parser.getAbsolutePath());
|
||||
break;
|
||||
} catch (LinkageError e) {
|
||||
dir = dir.getParentFile();
|
||||
if (dir == null) {
|
||||
throw e;
|
||||
System.err.println("Succeeded loading " + parser.getAbsolutePath());
|
||||
return true;
|
||||
} catch (LinkageError err) {
|
||||
while (chain.getCause() != null) {
|
||||
chain = chain.getCause();
|
||||
}
|
||||
chain.initCause(err);
|
||||
root = root.getParentFile();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private long state;
|
||||
|
@ -134,6 +134,19 @@ object DistributionPackage {
|
||||
distributionRoot / "component",
|
||||
cacheFactory.make("engine-jars")
|
||||
)
|
||||
val os = System.getProperty("os.name")
|
||||
val parser = "target/rust/debug/" + (if (os.startsWith("Mac")) {
|
||||
"x86_64-apple-darwin/libenso_parser.dylib"
|
||||
} else if (os.startsWith("Windows")) {
|
||||
"enso_parser.dll"
|
||||
} else {
|
||||
"libenso_parser.so"
|
||||
})
|
||||
copyFilesIncremental(
|
||||
Seq(file(parser)),
|
||||
distributionRoot / "component",
|
||||
cacheFactory.make("engine-parser-library")
|
||||
)
|
||||
|
||||
(distributionRoot / "editions").mkdirs()
|
||||
Editions.writeEditionConfig(
|
||||
|
Loading…
Reference in New Issue
Block a user