Skip to content

Commit

Permalink
Switch to use os.arch to detect native arch
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed Nov 23, 2020
1 parent f02d290 commit 577f538
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inThisBuild(
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
nativeArch := "x86_64",
nativeArch := System.getProperty("os.arch"),
nativeCompiler := "gcc",
nativeCompileOptions := "-shared" :: "-O2" :: "-Wall" :: "-Wextra" :: Nil,
nativePlatform := (System.getProperty("os.name").head.toLower match {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/scalasbt/ipcsocket/NativeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class NativeLoader {
private static final boolean isMac;
private static final boolean isLinux;
private static final boolean isWindows;
private static final String arch;

static {
final String os = System.getProperty("os.name", "").toLowerCase();
isMac = os.startsWith("mac");
isLinux = os.startsWith("linux");
isWindows = os.startsWith("windows");
String maybeArch = System.getProperty("os.arch", "");
if ("amd64".equals(maybeArch)) {
maybeArch = "x86_64";
}
arch = maybeArch;
}

private static final String pid =
Expand All @@ -40,18 +46,15 @@ private static String tmpDirLocation() {

static void load() throws UnsatisfiedLinkError {
if (!loaded.get()) {
final String os = System.getProperty("os.name", "").toLowerCase();
final boolean isMac = os.startsWith("mac");
final boolean isLinux = os.startsWith("linux");
final boolean isWindows = os.startsWith("windows");
final String arch = System.getProperty("os.arch", "x86_64").toLowerCase();
final boolean is64bit = System.getProperty("sun.arch.data.model", "64").equals("64");
String tmpDir = tmpDirLocation();
if (is64bit && (isMac || isLinux || isWindows)) {
final String extension = "." + (isMac ? "dylib" : isWindows ? "dll" : "so");
final String libName = (isWindows ? "" : "lib") + "sbtipcsocket" + extension;
final String prefix = isMac ? "darwin" : isLinux ? "linux" : "win32";

final String resource = prefix + "/x86_64/" + libName;
final String resource = prefix + "/" + arch + "/" + libName;
final URL url = NativeLoader.class.getClassLoader().getResource(resource);
if (url == null) throw new UnsatisfiedLinkError(resource + " not found on classpath");
try {
Expand Down

0 comments on commit 577f538

Please sign in to comment.