Skip to content

Commit

Permalink
README.md: added a guide for the most straightforward implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pavly-gerges authored Jul 27, 2024
1 parent 6d96b6a commit 9a0d779
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,57 @@ BUILD SUCCESSFUL in 1s
```

## Plug-and-play usage:
### Project build files:
[build.gradle]
```groovy
dependencies {
implementation "io.github.software-hardware-codesign:snaploader:1.0.0-delta"
}
```
[settings.gradle]
```groovy
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
...
// project Gradle modules includes
```
### Library Implementation:
1) The most straightforward way:
```java
final LibraryInfo info = new LibraryInfo(null, "lib/independent", "basename", null);
final NativeBinaryLoader loader = new NativeBinaryLoader(info);
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
new NativeDynamicLibrary("lib/linux/x86-64", PlatformPredicate.LINUX_X86_64),
new NativeDynamicLibrary("lib/macos/arm-64", PlatformPredicate.MACOS_ARM_64),
new NativeDynamicLibrary("lib/macos/x86-64", PlatformPredicate.MACOS_X86_64),
new NativeDynamicLibrary("lib/win/x86-64", PlatformPredicate.WIN_X86_64)
...
};
loader.registerNativeLibraries(libraries).initPlatformLibrary();
loader.setLoggingEnabled(true);
loader.setRetryWithCleanExtraction(true);
try {
loader.loadLibrary(LoadingCriterion.INCREMENTAL_LOADING);
} catch (IOException e) {
Logger.getLogger(NativeBinaryLoader.class.getName()
.log(Level.SEVERE, "Native loader has failed!", e);
}
```
- This way utilizes the classpath on the stock Jar archive to locate, extract and load the native binaries.
- It first defines a library info object with a pointer to the classpath (first null argument), and a default path that will be
used in case the platform path for the selected platform predicate is invalid, then a `basename` for the library to be operated, and finally the current working directory as an extraction path (third null argument).


## Appendix:
Expand Down

0 comments on commit 9a0d779

Please sign in to comment.