Skip to content

Commit

Permalink
Fix broken platform detection
Browse files Browse the repository at this point in the history
- this also changes the platform suffix for windows from `x86_64-msys_nt-10.0-20348` to `x86_64-windows`

Fixes #31
  • Loading branch information
oyvindberg committed Jan 31, 2023
1 parent c95a9d7 commit 2353274
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions crossterm/src/java/tui/crossterm/NativeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ static void loadPackaged(String nativeLibrary) throws Exception {
System.load(extractedPath.toAbsolutePath().toString());
}

private static String getPlatform() throws IOException, InterruptedException {
var process = new ProcessBuilder(asList("uname", "-sm")).start();
var ret = process.waitFor();
if (ret != 0) {
throw new RuntimeException("Error running `uname` command: " + ret);
private static String getPlatform() {
if (System.getenv().containsKey("TUI_SCALA_PLATFORM")) {
return System.getenv().get("TUI_SCALA_PLATFORM");
}
String uname = new String(process.getInputStream().readAllBytes());
String line = uname.split("\n")[0];
String[] parts = line.split(" ");
if (parts.length != 2) {
throw new RuntimeException("Could not determine platform: 'uname -sm' returned unexpected string: " + line);
}
String arch = parts[1].toLowerCase().replaceAll("\\s", "");
String kernel = parts[0].toLowerCase().replaceAll("\\s", "");
return arch + "-" + kernel;
String arch = System.getProperty("os.arch");
String name = System.getProperty("os.name");
String nameLower = name.toLowerCase();

if (arch.equals("x86_64") && nameLower.contains("win")) return "x86_64-windows";
if (arch.equals("x86_64") && nameLower.contains("lin")) return "x86_64-linux";
if (arch.equals("x86_64") && nameLower.contains("mac")) return "x86_64-darwin";
if (arch.equals("aarch64") && nameLower.contains("mac")) return "arm64-darwin";
throw new RuntimeException(
"Platform detection does not understand os.name = " + name + " and os.arch = " + arch + ". " +
"You can set environment variable TUI_SCALA_PLATFORM to x86_64-windows, x86_64-linux, x86_64-darwin, arm64-darwin to override. " +
"Open an issue at https://github.com/oyvindberg/tui-scala/issues ."
);
}
}
2 changes: 1 addition & 1 deletion scripts/src/scala/tui/scripts/GenJniLibrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object GenJniLibrary extends BleepScript("GenJniLibrary") {
override lazy val nativePlatform: String =
OsArch.current match {
case OsArch.LinuxAmd64 => "x86_64-linux"
case OsArch.WindowsAmd64 => "x86_64-msys_nt-10.0-20348"
case OsArch.WindowsAmd64 => "x86_64-windows"
case OsArch.MacosAmd64 => "x86_64-darwin"
case OsArch.MacosArm64(_) => "arm64-darwin"
case other: OsArch.Other => sys.error(s"not implemented: $other")
Expand Down

0 comments on commit 2353274

Please sign in to comment.