Skip to content

Commit d3a4c9e

Browse files
committed
chore: normalize os architecture
1 parent 745548e commit d3a4c9e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

bindings/java/java_code/src/main/java/ethereum/cryptography/LibPeerDASKZG.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,40 @@ public static native boolean verifyCellKZGProof(
2828
private static final String LIBRARY_NAME = "java_peerdas_kzg";
2929
private static final String PLATFORM_NATIVE_LIBRARY_NAME = System.mapLibraryName(LIBRARY_NAME);
3030

31+
private static String getNormalizedArchitecture() {
32+
String osArch = System.getProperty("os.arch").toLowerCase();
33+
if (osArch.equals("x86_64") || osArch.equals("amd64")) {
34+
return "x86_64";
35+
} else if (osArch.equals("aarch64") || osArch.equals("arm64")) {
36+
return "aarch64";
37+
} else {
38+
return osArch;
39+
}
40+
}
41+
3142
/** Loads the appropriate native library based on your platform. */
3243
// Copied from c-kzg
3344
public static void loadNativeLibrary() {
3445

3546
String osName = System.getProperty("os.name").toLowerCase();
36-
String osArch = System.getProperty("os.arch").toLowerCase();
47+
String osArch = getNormalizedArchitecture();
3748
String libraryResourcePath = null;
3849

3950
if (osName.contains("win")) {
40-
if (osArch.contains("amd64") || osArch.contains("x86_64")) {
41-
libraryResourcePath = "/x86_64-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
51+
if (osArch.contains("x86_64")) {
52+
libraryResourcePath = "/x86_64-windows-pc-gnu/" + PLATFORM_NATIVE_LIBRARY_NAME;
4253
} else if (osArch.contains("x86")) {
43-
libraryResourcePath = "/x86-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
44-
} else if (osArch.contains("arm64")) {
45-
libraryResourcePath = "/arm64-windows/" + PLATFORM_NATIVE_LIBRARY_NAME;
54+
// TODO: Remove this and just don't support 32-bit Windows
55+
libraryResourcePath = "/i686-pc-windows-gnu/" + PLATFORM_NATIVE_LIBRARY_NAME;
56+
} else if (osArch.contains("aarch64")) {
57+
// Current version of c-kzg does not support arm windows either
58+
// TODO: Rust has support for msvc with arm64, but it also has:
59+
// aarch64-pc-windows-gnullvm -- we probably want to stick to one
60+
// toolchain for now.
61+
// If we do switch to msvc, nethermind had an issue with windows server 2022
62+
// that we should check works with an msvc build.
63+
// libraryResourcePath = "/aarch64-pc-windows-gnullvm/" + PLATFORM_NATIVE_LIBRARY_NAME;
64+
4665
}
4766
} else if (osName.contains("mac")) {
4867
if (osArch.contains("x86_64")) {

0 commit comments

Comments
 (0)