Skip to content

Commit

Permalink
Change native libraries structure
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed May 18, 2024
1 parent 7c03902 commit 13386b9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 76 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
allprojects {
tasks.withType<Javadoc> {
options {
verbose()
if (this is CoreJavadocOptions) {
if (jdkEnablePreview.toBoolean()) {
addBooleanOption("-enable-preview", true)
Expand Down
18 changes: 8 additions & 10 deletions buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ enum class NativePlatform(
val nativeLibSuffix: String,
val taskSuffix: String
) {
WIN_64("windows", "x64", "windows", "", ".dll", "Win64"),
WIN_ARM64("windows", "arm64", "windows-arm64", "", ".dll", "WinArm64"),
FREEBSD_X64("freebsd", "x64", "freebsd", "lib", ".so", "FreeBSD64"),
LINUX_64("linux", "x64", "linux", "lib", ".so", "Linux64"),
LINUX_ARM32("linux", "arm32", "linux-arm32", "lib", ".so", "LinuxArm32"),
LINUX_ARM64("linux", "arm64", "linux-arm64", "lib", ".so", "LinuxArm64"),
LINUX_PPC64LE("linux", "ppc64le", "linux-ppc64le", "lib", ".so", "LinuxPpc64le"),
LINUX_RISCV64("linux", "riscv64", "linux-riscv64", "lib", ".so", "LinuxRiscv64"),
MACOS("macos", "x64", "macos", "lib", ".dylib", "Macos"),
MACOS_ARM64("macos", "arm64", "macos-arm64", "lib", ".dylib", "MacosArm64");
MACOS_ARM64("macos", "arm64", "macos-arm64", "lib", ".dylib", "MacosArm64"),
WIN_64("windows", "x64", "windows", "", ".dll", "Win64"),
WIN_ARM64("windows", "arm64", "windows-arm64", "", ".dll", "WinArm64");

companion object {
val ALL = values()
Expand All @@ -42,12 +45,7 @@ enum class NativeBinding(
val basename: String,
vararg val platforms: NativePlatform
) {
GLFW(
"glfw", "glfw3",
NativePlatform.WIN_64,
NativePlatform.LINUX_64, NativePlatform.LINUX_ARM64,
NativePlatform.MACOS, NativePlatform.MACOS_ARM64
),
GLFW("glfw", "glfw", *NativePlatform.ALL),
NFD("nfd", "nfd", *NativePlatform.ALL),
STB("stb", "stb", *NativePlatform.ALL)
}
Expand Down Expand Up @@ -97,6 +95,6 @@ enum class Artifact(

fun nativeFileName(platform: NativePlatform): String? {
return if (nativeBinding == null) null
else "${nativeBinding.bindingName}/${platform.osFamilyName}/${platform.osArch}/${platform.nativeLibPrefix}${nativeBinding.basename}${platform.nativeLibSuffix}"
else "${nativeBinding.bindingName}/${platform.osFamilyName}-${platform.osArch}/${platform.nativeLibPrefix}${nativeBinding.basename}${platform.nativeLibSuffix}"
}
}
79 changes: 28 additions & 51 deletions doc/internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

To publish this library, you need a GPG key and the write permission of Maven Central.

### CI

- [glfw](https://github.com/Over-Run/glfw-ci)
- [nfd](https://github.com/Over-Run/nfd-ci)
- [stb](https://github.com/Over-Run/stb-ci)

### Packing Natives

The build script packs the native libraries into jars.
Expand All @@ -12,56 +18,27 @@ The tree structure of the native libraries is:

```text
natives
├─ glfw
│ ├─ linux
│ │ ├─ arm64
│ │ │ └─ libglfw3.so
│ │ └─ x64
│ │ └─ libglfw3.so
│ ├─ macos
│ │ ├─ arm64
│ │ │ └─ libglfw3.dylib
│ │ └─ x64
│ │ └─ libglfw3.dylib
│ └─ windows
│ └─ x64
│ └─ glfw3.dll
├─ nfd https://github.com/Over-Run/nfd-ci
│ ├─ linux
│ │ ├─ arm32
│ │ │ └─ libnfd.so
│ │ ├─ arm64
│ │ │ └─ libnfd.so
│ │ └─ x64
│ │ └─ libnfd.so
│ ├─ macos
│ │ ├─ arm64
│ │ │ └─ libnfd.dylib
│ │ └─ x64
│ │ └─ libnfd.dylib
│ └─ windows
│ ├─ arm64
│ │ └─ nfd.dll
│ └─ x64
│ └─ nfd.dll
└─ stb https://github.com/Over-Run/stb-ci
├─ linux
│ ├─ arm32
│ │ └─ libstb.so
│ ├─ arm64
│ │ └─ libstb.so
│ └─ x64
│ └─ libstb.so
├─ macos
│ ├─ arm64
│ │ └─ libstb.dylib
│ └─ x64
│ └─ libstb.dylib
└─ windows
├─ arm64
│ └─ stb.dll
└─ x64
└─ stb.dll
└─ <module-name>
├─ freebsd-x64
│ └─ lib<basename>.so
├─ linux-arm32
│ └─ lib<basename>.so
├─ linux-arm64
│ └─ lib<basename>.so
├─ linux-ppc64le
│ └─ lib<basename>.so
├─ linux-riscv64
│ └─ lib<basename>.so
├─ linux-x64
│ └─ lib<basename>.so
├─ macos-arm64
│ └─ lib<basename>.dylib
├─ macos-x64
│ └─ lib<basename>.dylib
├─ windows-arm64
│ └─ <basename>.dll
└─ windows-x64
└─ <basename>.dll
```

The `natives` directory is in the project directory.
The `natives` directory is in the root project directory.
6 changes: 3 additions & 3 deletions modules/overrungl.core/src/main/java/overrungl/OverrunGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public final class OverrunGL {
/**
* The version of GLFW native libraries.
*/
public static final String GLFW_VERSION = "3.4.0.0";
public static final String GLFW_VERSION = "3.5.0.0";
/**
* The version of NFD native libraries.
*/
public static final String NFD_VERSION = "0.1.0.0";
public static final String NFD_VERSION = "1.1.1.0";
/**
* The version of STB native libraries.
*/
public static final String STB_VERSION = "0.1.0.3";
public static final String STB_VERSION = "0.1.0.4";
private static final Consumer<String> DEFAULT_LOGGER = System.err::println;
private static Consumer<String> apiLogger = DEFAULT_LOGGER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public final class RuntimeHelper {
* The native linker.
*/
private static final Linker LINKER = Linker.nativeLinker();
private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir"));
private static final Path tmpdir = Path.of(System.getProperty("java.io.tmpdir"))
.resolve(STR."overrungl\{System.getProperty("user.name")}");
private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
private static final Map<String, MemoryLayout> CANONICAL_LAYOUTS = LINKER.canonicalLayouts();
/**
Expand Down Expand Up @@ -102,24 +103,23 @@ public static SymbolLookup load(String module, String basename, String version)
uri = localFile;
} else {
// 2. Load from classpath
var file = tmpdir.resolve(STR."overrungl\{System.getProperty("user.name")}");
try {
if (!Files.exists(file)) {
if (!Files.exists(tmpdir)) {
// Create directory
Files.createDirectories(file);
} else if (!Files.isDirectory(file)) {
Files.createDirectories(tmpdir);
} else if (!Files.isDirectory(tmpdir)) {
// Remove
Files.delete(file);
Files.delete(tmpdir);
// Create directory
Files.createDirectories(file);
Files.createDirectories(tmpdir);
}
} catch (IOException e) {
throw new IllegalStateException(STR."Couldn't create directory: \{file}; try setting -Doverrungl.natives to a valid path", e);
throw new IllegalStateException(STR."Couldn't create directory: \{tmpdir}; try setting -Doverrungl.natives to a valid path", e);
}
var libFile = file.resolve(STR."\{basename}-\{version}\{suffix}");
var libFile = tmpdir.resolve(STR."\{basename}-\{version}\{suffix}");
if (!Files.exists(libFile)) {
// Extract
final String fromPath = STR."\{module}/\{os.familyName()}/\{Architecture.current()}/\{path}";
final String fromPath = STR."\{module}/\{os.familyName()}-\{Architecture.current()}/\{path}";
try (var is = STACK_WALKER.getCallerClass().getClassLoader().getResourceAsStream(fromPath)) {
Files.copy(Objects.requireNonNull(is, STR."File not found in classpath: \{fromPath}"), libFile);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Handles {
static final SymbolLookup lookup;

static {
final Supplier<SymbolLookup> lib = () -> RuntimeHelper.load("glfw", "glfw3", OverrunGL.GLFW_VERSION);
final Supplier<SymbolLookup> lib = () -> RuntimeHelper.load("glfw", "glfw", OverrunGL.GLFW_VERSION);
final var function = Configurations.GLFW_SYMBOL_LOOKUP.get();
lookup = function != null ? function.apply(lib) : lib.get();
}
Expand Down

0 comments on commit 13386b9

Please sign in to comment.