Skip to content

Commit

Permalink
Merge branch 'master' of github.com:libgdx/gdx-jnigen
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Ski committed Feb 23, 2025
2 parents 2f50329 + 7fc4d2f commit 5a4944e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
20 changes: 20 additions & 0 deletions MIGRATION.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## jnigen 2.x to jnigen 3.x
jnigen 3.x is a major rewrite of the jnigen internals.
The internals have been rewritten from ant to a full java code base. Together with this, many other refactors of jnigen occured.

#### Gradle plugin:
- The artifact of the gradle plugin has been changed from `com.badlogicgames.gdx:gdx-jnigen-gradle` to `com.badlogicgames.jnigen:jnigen-gradle`
- All old build tasks have been removed. They have been replaced by tasks names like `jnigenBuildAllWindows` or `jnigenBuildWindows_x86_64`.
- The generalised build task `jnigenBuild` got replaced by the more specialised `jnigenBuildHost`, which only builds the host architecture.
- All packaging tasks have been removed and replaced by `jnigenPackageAll` or `jnigenPackageAllDesktop`. Some specialised variants exist for android too.
- The generic `jnigen#add` methods have been removed and replaced by `addXXX(bitness, architecture, compilerAbi)`, where compilerAbi can be GCC/Clang or MSVC.
- The fields `cFlags`, `cppFlags`, `linkerFlags`, `libraries` are now `String[]`. Migration steps are needed to split args into an array.
- The build directory of the jni files has changed. jnigen will now use `build/jnigen/` as build directory.
- The working directory of jnigen has changed to module directory. Relative path traversal works now.
- jnigen now configures the publishing of the natives under a `jniPlatform` publication automatically, if the `maven-publish` plugin is applied. Your artifacts will be published using `groupid:artifactid-platform:version:classifierXXX` as the coordinates.
- Getting verbose debug logs is now configured through gradle, by passing `--info` flag.

#### SharedLibraryLoader:
- The artifact of the `jnigen-loader` has been changed from `com.badlogicgames.jnigen:gdx-jnigen-loader` to `com.badlogicgames.jnigen:jnigen-loader`
- The package of the `SharedLibraryLoader` has been changed from `com.badlogic.gdx.utils` to `com.badlogic.gdx.jnigen.loader`
- The platform detection logic of `SharedLibraryLoader` has been split of into `com.badlogic.gdx.jnigen.commons.HostDetection`
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ avoids "java.library.path" troubles.

See the libGDX Wiki for usage: https://libgdx.com/wiki/utils/jnigen

> [!CAUTION]
> The jnigen-runtime and jnigen-generator API is considered incubating and may change at any point.
> [!NOTE]
> For migrating from jnigen 2.x see the `MIGRATION.MD`

## gdx-jnigen-gradle quickstart

We recommend you look at some existing projects for examples:
Expand All @@ -21,6 +28,7 @@ We recommend you look at some existing projects for examples:
- [gdx-bullet](https://github.com/libgdx/libgdx/blob/master/extensions/gdx-bullet/build.gradle) (Uses jnigen 2.x)
- [gdx-video-desktop](https://github.com/libgdx/gdx-video/blob/master/gdx-video-desktop/build.gradle) (Uses jnigen 2.x)
- [Jamepad](https://github.com/libgdx/Jamepad/blob/master/build.gradle) (Uses jnigen 2.x)
- [gdx-box2d](https://github.com/libgdx/gdx-box2d/blob/master/build.gradle.kts) (Uses jnigen 3.x and kotlin DSL)


## Configuring
Expand All @@ -47,11 +55,11 @@ jnigen {
// String[] options can be replaced by using `x = ["value"]` or appended to with `x += "extravalue"` or `x += ["extravalue", "extravalue2"]`
all {
// Add extra flags passed to the C compiler
cFlags += " -fvisibility=hidden "
cFlags += ["-fvisibility=hidden"]
// Add extra flags passed to the C++ compiler
cppFlags += " -std=c++11 -fvisibility=hidden "
cppFlags += ["-std=c++11", "-fvisibility=hidden"]
// Add extra flags passed to the linker
linkerFlags += " -fvisibility=hidden "
linkerFlags += ["-fvisibility=hidden"]
}
// Configure robovm.xml for IOS builds, most simple libraries will not need to do this
Expand All @@ -72,14 +80,14 @@ jnigen {
// Add windows 32-bit BuildTarget and customize it
addWindows(x32, x86) {
//cFlags += " -fextraflag=fake "
//cFlags += ["-fextraflag=fake"]
//compilerPrefix = "someprefix-";
//cIncludes += "windowsspecificdir/*.c"
}
//Add windows 64 bit, x86, MSVC toolchain
addWindows(x64, x86, MSVC) {
msvcPreLinkerFlags += "/MD"
msvcPreLinkerFlags += ["/MD"]
}
addWindows(x64, x86)
Expand Down Expand Up @@ -117,20 +125,20 @@ jnigen {
// Customize each BuildTarget that matches the condition
each({ it.os != Android && !it.isARM }) {
//cppFlags += " -march=nocona "
//cppFlags += ["-march=nocona"]
}
// Customize everything again, can be used for conditional changes
each({ true }) {
//if(!it.cppCompiler.contains("clang")) {
// it.cFlags += " -flto "
// it.cppFlags += " -flto "
// it.linkerFlags += " -flto "
// it.cFlags += ["-flto"]
// it.cppFlags += ["-flto"]
// it.linkerFlags += ["-flto"]
//}
//if(it.cppCompiler.contains("clang"))
// it.linkerFlags += " -Wl,-dead_strip -Wl,-s "
// it.linkerFlags += ["-Wl,-dead_strip", "-Wl,-s"]
//else
// it.linkerFlags += " -Wl,--gc-sections "
// it.linkerFlags += ["-Wl,--gc-sections"]
}
}
```
Expand Down

0 comments on commit 5a4944e

Please sign in to comment.