Skip to content

Commit

Permalink
chore: normalize os architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed May 30, 2024
1 parent 745548e commit d3a4c9e
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,40 @@ public static native boolean verifyCellKZGProof(
private static final String LIBRARY_NAME = "java_peerdas_kzg";
private static final String PLATFORM_NATIVE_LIBRARY_NAME = System.mapLibraryName(LIBRARY_NAME);

private static String getNormalizedArchitecture() {
String osArch = System.getProperty("os.arch").toLowerCase();
if (osArch.equals("x86_64") || osArch.equals("amd64")) {
return "x86_64";
} else if (osArch.equals("aarch64") || osArch.equals("arm64")) {
return "aarch64";
} else {
return osArch;
}
}

/** Loads the appropriate native library based on your platform. */
// Copied from c-kzg
public static void loadNativeLibrary() {

String osName = System.getProperty("os.name").toLowerCase();
String osArch = System.getProperty("os.arch").toLowerCase();
String osArch = getNormalizedArchitecture();
String libraryResourcePath = null;

if (osName.contains("win")) {
if (osArch.contains("amd64") || osArch.contains("x86_64")) {
libraryResourcePath = "/x86_64-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
if (osArch.contains("x86_64")) {
libraryResourcePath = "/x86_64-windows-pc-gnu/" + PLATFORM_NATIVE_LIBRARY_NAME;
} else if (osArch.contains("x86")) {
libraryResourcePath = "/x86-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
} else if (osArch.contains("arm64")) {
libraryResourcePath = "/arm64-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
// TODO: Remove this and just don't support 32-bit Windows
libraryResourcePath = "/i686-pc-windows-gnu/" + PLATFORM_NATIVE_LIBRARY_NAME;
} else if (osArch.contains("aarch64")) {
// Current version of c-kzg does not support arm windows either
// TODO: Rust has support for msvc with arm64, but it also has:
// aarch64-pc-windows-gnullvm -- we probably want to stick to one
// toolchain for now.
// If we do switch to msvc, nethermind had an issue with windows server 2022
// that we should check works with an msvc build.
// libraryResourcePath = "/aarch64-pc-windows-gnullvm/" + PLATFORM_NATIVE_LIBRARY_NAME;

}
} else if (osName.contains("mac")) {
if (osArch.contains("x86_64")) {
Expand Down

0 comments on commit d3a4c9e

Please sign in to comment.