Skip to content

Commit 52b7241

Browse files
feat: add the platform classifier to the native library filename (#194)
* feat: add the platform classifier to the native library filename * Apply suggestions from code review fix: make native platform detection more robust Co-authored-by: Alex Andres <58339654+devopvoid@users.noreply.github.com> --------- Co-authored-by: Alex Andres <58339654+devopvoid@users.noreply.github.com>
1 parent 7c2be3b commit 52b7241

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

webrtc-jni/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
<option>
112112
-DCMAKE_INSTALL_PREFIX=${project.build.directory}/lib
113113
</option>
114+
<option>
115+
-DOUTPUT_NAME_SUFFIX=${platform.classifier}
116+
</option>
114117
</options>
115118
</configuration>
116119
</execution>

webrtc-jni/src/main/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ target_include_directories(${PROJECT_NAME}
8888
)
8989

9090
set_target_properties(${PROJECT_NAME} PROPERTIES
91+
OUTPUT_NAME "${PROJECT_NAME}-${OUTPUT_NAME_SUFFIX}"
9192
CXX_STANDARD 20
9293
CXX_STANDARD_REQUIRED ON
9394
CXX_EXTENSIONS OFF

webrtc/src/main/java/dev/onvoid/webrtc/internal/NativeLoader.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public static void loadLibrary(final String libName) throws Exception {
5151
return;
5252
}
5353

54-
String libFileName = System.mapLibraryName(libName);
54+
String osFamily = getOSFamily();
55+
String osArch = getOSArch();
56+
String libFileName = System.mapLibraryName(libName + "-" + osFamily + "-" + osArch);
5557
String tempName = removeExtension(libFileName);
5658
String ext = getExtension(libFileName);
5759

@@ -119,4 +121,39 @@ private static int getExtensionIndex(String fileName) {
119121
return extSeparator;
120122
}
121123

124+
private static String getOSFamily() {
125+
String osName = System.getProperty("os.name").toLowerCase();
126+
127+
if (osName.startsWith("mac os")) {
128+
return "macos";
129+
}
130+
if (osName.startsWith("linux")) {
131+
return "linux";
132+
}
133+
if (osName.startsWith("windows")) {
134+
return "windows";
135+
}
136+
137+
throw new RuntimeException("Unsupported operating system: " + osName);
138+
}
139+
140+
private static String getOSArch() {
141+
String osArch = System.getProperty("os.arch").toLowerCase();
142+
143+
switch (osArch) {
144+
case "x86_64":
145+
case "x86-64":
146+
case "amd64":
147+
return "x86_64";
148+
case "aarch32":
149+
case "arm":
150+
return "aarch32";
151+
case "aarch64":
152+
case "arm64":
153+
return "aarch64";
154+
}
155+
156+
throw new RuntimeException("Unsupported CPU architecture: " + osArch);
157+
}
158+
122159
}

0 commit comments

Comments
 (0)