Skip to content

Commit

Permalink
Docs: Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaracha committed Oct 12, 2024
1 parent e4e65e7 commit fd55b41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
44 changes: 13 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ The plugin generates Java bindings for native libraries using the FFM-related [J
- [x] Preset conventions for Jextract versions 19 up to 22.
- [x] Download locations can be customized for more restrictive environments.
- [x] Alternately, use a local installation of Jextract.
- [x] Generated code is available in main sourceset of Java projects.
- [x] Generated source code is available in a user-selected Java source set (`main` by default).
- [x] Multiple libs can be configured in one project and are built concurrently.
- [x] Whitelisting of included symbols via DSL extension
- [x] Can dump includes and use arg files
- [x] Compatible with [Configuration Cache].
- [x] Tasks are [cacheable][build cache].

## Usage

You might want to apply this plugin after one of the Java plugins.
It tries to get the correct Java version from the toolchain extension or falls back to the JDK Gradle is running on.
On JDk 23, Jextract 22 is used, because FFM has been finalized and a version 23 wouldn't make a difference effectively.
On JDk 23, Jextract 22 is used, because FFM has been finalized, so there are effectively no differences between version 22 and 23.
After running `./gradlew build`, the generated code will be available in the main source set.

### Simple Example
Expand Down Expand Up @@ -62,11 +63,6 @@ Add this copy to the plugin's extension.
Instead of using an arg file, included symbols can also be configured directly in the whitelist extension via respective properties.

```gradle kotlin dsl
plugins {
id("application")
id("de.infolektuell.jextract") version "0.2.1"
}
jextract.libraries {
create("bass") {
header = layout.projectDirectory.file("bass.h")
Expand All @@ -80,8 +76,6 @@ jextract.libraries {
libraries = listOf("bass")
}
}
java.toolchain.languageVersion = JavaLanguageVersion.of(22)
```

See [Filtering] section in the Jextract guide for more information.
Expand All @@ -91,17 +85,10 @@ See [Filtering] section in the Jextract guide for more information.
The extension offers a property to select a version without relying on a Java plugin.

```gradle kotlin dsl
plugins {
id("de.infolektuell.jextract") version "0.2.1"
}
jextract {
generator {
javaLanguageVersion = JavaLanguageVersion.of(21)
}
libraries {
...
}
}
```

Expand All @@ -110,43 +97,37 @@ jextract {
Instead of downloading Jextract, a local installation directory can be configured.

```gradle kotlin dsl
plugins {
id("de.infolektuell.jextract") version "0.2.1"
}
jextract {
generator {
local = layout.projectDirectory.dir("/usr/local/opt/jextract-22/")
}
libraries {
...
}
}
```

### Custom Locations

Jextract is downloaded from the [official page][jextract] by default.
If custom locations are needed, the download task must be configured (url, checksum, and verification algorithm).
The plugin implements its own decision logic to select apropriate values depending on the current build platform and JDK version.
The plugin implements its own decision logic to select appropriate conventions depending on the current build platform and JDK version.

```gradle kotlin dsl
import de.infolektuell.gradle.jextract.tasks.DownloadTask
plugins {
id("de.infolektuell.jextract") version "0.2.1"
}
tasks.withType(DownloadTask::class).configureEach {
resource.url = uri("https://my-company.com/jextract/file.tgz")
resource.checksum = "xyz"
resource.algorithm = "SHA-512" // SHA-256 by default
}
```

### Custom source set

In some situations, the `main` source set is not available or the sources should be added to another one, e.g., `test`.
This must be configured in the extension:

```gradle kotlin dsl
jextract {
libraries {
...
}
sourceSet = sourceSets.named("test")
}
```

Expand All @@ -157,4 +138,5 @@ jextract {
[jextract]: https://jdk.java.net/jextract/
[ffm]: https://openjdk.org/jeps/454
[configuration cache]: https://docs.gradle.org/current/userguide/configuration_cache.html
[build cache]: https://docs.gradle.org/current/userguide/build_cache.html
[filtering]: https://github.com/openjdk/jextract/blob/master/doc/GUIDE.md#filtering
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml

This file was deleted.

0 comments on commit fd55b41

Please sign in to comment.