Skip to content

Commit

Permalink
Merge pull request #11 from catap/macos-arm64
Browse files Browse the repository at this point in the history
Support of macOS arm64
  • Loading branch information
eed3si9n authored Nov 23, 2020
2 parents f02d290 + 8c63fec commit e92bc13
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ 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") match {
case "amd64" =>
"x86_64"
case arch =>
arch
}
},
nativeCompiler := "gcc",
nativeCompileOptions := "-shared" :: "-O2" :: "-Wall" :: "-Wextra" :: Nil,
nativePlatform := (System.getProperty("os.name").head.toLower match {
Expand Down
12 changes: 7 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,14 @@ 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 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
Binary file not shown.

0 comments on commit e92bc13

Please sign in to comment.