GithubHelp home page GithubHelp logo

krakowski / gradle-jextract Goto Github PK

View Code? Open in Web Editor NEW
40.0 40.0 9.0 192 KB

Gradle plugin for integrating Project Panama's jextract tool

Home Page: https://plugins.gradle.org/plugin/io.github.krakowski.jextract

License: GNU General Public License v3.0

Kotlin 100.00%
ffi gradle gradle-plugin java jextract native panama

gradle-jextract's People

Contributors

aecsocket avatar arc-blroth avatar bartvhelvert avatar brownshome avatar elect86 avatar krakowski avatar rnett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gradle-jextract's Issues

Command string not printed on failed build

Environment

  • JDK version: 20
  • Gradle version: 8.0
  • gradle-jextract version: 0.4.0
  • Operating system: Win 11

How does this bug occur?

When a jextract build fails

What happens when the bug occurs?

The command string is not printed.

Invoking jextract failed.
  
   command: [Ljava.lang.String;@6d00ed1b
   stdout: 
   stderr: WARNING: A restricted method in java.lang.foreign.ValueLayout$OfAddress has been called
  WARNING: java.lang.foreign.ValueLayout$OfAddress::asUnbounded has been called by module org.openjdk.jextract
  WARNING: Use --enable-native-access=org.openjdk.jextract to avoid a warning for this module

Would you like to submit a PR fixing this bug?

[ ] YES
[x] NO

The file paths aren't enclosed in quotes ""

Environment

  • JDK version: 19
  • Gradle version: 7.6
  • gradle-jextract version: 0.3.0
  • Operating system: Windows 10

How does this bug occur?

Configure the build.gradle according the README.md
and run the build.

What happens when the bug occurs?

Build fails with the error saying that it got 5 headers instead of 1.

In short my folder names contains spaces so when you put such
paths onto the command line it will obviously not work since the
spaces are used as an argument separator. Adding quotes fixes the issue.
The quotes should be there by default to support all different
file paths including ones that have spaces in it.

Would you like to submit a PR fixing this bug?

[X] YES
[ ] NO

Can't find jextract.exe on Windows even though it is in PATH

Environment

  • Operating system: Windows

How does this bug occur?

  1. Clone https://github.com/krakowski/jextract-demo
  2. Put jextract in PATH
  3. ./gradlew run

What happens when the bug occurs?

Throws exception and fails build:

Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 23: $PATH$\jextract.exe
	at io.github.krakowski.jextract.JextractTask$findExecutable$pathExecutable$1.apply(JextractTask.kt:54)
	at io.github.krakowski.jextract.JextractTask$findExecutable$pathExecutable$1.apply(JextractTask.kt:19)
	at io.github.krakowski.jextract.JextractTask.findExecutable(JextractTask.kt:56)
	at io.github.krakowski.jextract.JextractTask.action(JextractTask.kt:74)

Would you like to submit a PR fixing this bug?

[x] YES
[ ] NO

IntelliJ Project Import Issue

Environment

  • JDK version: 20
  • Gradle version: 8.2.1
  • gradle-jextract version: 0.4.1
  • Operating system: Windows 11
  • IDE: IntelliJ IDEA 2023.2

How does this bug occur?

When using jextract in source-mode in a Java module project that is openned as an IntelliJ project.

What happens when the bug occurs?

A dependency is added on the output directory, which contains the sources. This causes issues in IDEA IntelliJ as it sees these files as in the unnamed module, causing import and module access issues.

Would you like to submit a PR fixing this bug?

[x] YES
[ ] NO

How to use "outputDir" option.

Environment

  • JDK version: JDK19
  • Gradle version: 7.6
  • gradle-jextract version: 0.3.1
  • Operating system: Windows

What would you like to ask?

The field is declared as "final" and there doesn't seems to be a method to change the value of the property you can only create new property using provided methods in the documentation:
https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html

I am not super versed in Gradle or Groovy so maybe I am only missing something basic, but so far I couldn't figure out how to set the output directory for the Jextract.

Update the plugin to support latest `jextract`

Thanks for developing this plugin. As of OpenJDK 20 jextract, macro option is removed and throws the following error

> Invoking jextract failed.

   command: [Ljava.lang.String;@9b0b0e2
   stdout:
   stderr: OPTION ERROR: invalid option: --include-macro
  Usage: jextract <options> <header file>
  Use --help for a list of possible options

Also missing the constants option in plugin.

--include-constant <name>          name of macro or enum constant to include

Libraries should be optional

What should this feature provide?

The libraries configuration should be optional.

Why is this feature needed?

jextract now supports not specifying libraries, leaving loading them up to the user. The plugin does not support this yet, but should.

How can this feature be implemented?

Make LibraryDefinition.libraries optional, default to empty, don't throw if it is empty. I will submit a PR.

jextract binary could not be found in PATH (exe vs bat)

Environment

  • JDK version: 19 (2022-09-20)
  • Gradle version: 7.6-20220924231105+0000
  • gradle-jextract version: 0.3.0
  • Operating system: Windows

How does this bug occur?

When running the gradle build task
"./gradlew build" while using the gradle-jextract plugin

What happens when the bug occurs?

Basically it seems that the plugin is looking for '.exe' file,
but the jextract project from https://github.com/openjdk/jextract
actually generates ".bat" there is not '.exe' file.
The file is on the PATH and can be invoked directly from the
command prompt without specifying the location.

Would you like to submit a PR fixing this bug?

[X] YES
[ ] NO

jextract no longer supports "--source"

https://cr.openjdk.org/~mcimadamore/panama/jextract_changes.html

See

val sourceMode: Property<Boolean> = project.objects.property<Boolean>()

Environment

  • JDK version: 22.0.0.0
  • Gradle version: 8.7
  • gradle-jextract version: 0.4.2
  • Operating system: Linux x64
  • jextract: 22-jextract+3-13 (2024/2/21)

How does this bug occur?

Using the jextract plugin with default settings (source = true)

What happens when the bug occurs?

.../jextract-bin/jextract-22/bin/java -m org.openjdk.jextract/org.openjdk.jextract.JextractTool --source -l lib --target-package com.lib --header-class-name Lib --output .../build/generated/sources/jextract/main/java .../lib.h
  ERROR: invalid option: --source
  Usage: jextract <options> <header file>
  Use --help for a list of possible options

Would you like to submit a PR fixing this bug?

[ ] YES
[X] NO

Adapt Gradle's toolchain mechanism for selecting JDKs

What should this feature provide?

A way to specify the toolchain to be used for compiling and executing using Gradle's standard mechanisms.

Why is this feature needed?

The current way of specifying the toolchain through a custom Gradle property (javaHome) is not an elegant solution and may break in future Gradle versions. This will also reduce the cost of maintenance.

How can this feature be implemented?

As explained in Toolchains for plugin authors, the custom task should expose a toolchain property, letting the user configure which toolchain to use.

How to use it

Hi,

cool project!

However whenever I try sync'ing I'm getting the following:

Execution failed for task ':jextract'.
jextract binary could not be found (JVM_HOME=/home/elect/.jdks/openjdk-15.0.2)

Although I do have

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

Unfortunately Gradle 7.0.2 seems to be compatible up to jdk16.. how do you get the whole thing working?

Also, what about a kotlin conversion? Because I'd like to add some other options/features

Why check PATH before checking bundled jextract

I think it makes more sense for it to be the other way around. I would expect it to use the jextract that is in my current toolchain instead of the one in my PATH. Should the search order be switched?

Delete stale code when output changes

Environment

  • JDK version: 19
  • Gradle version: 7.4.1
  • gradle-jextract version: 0.2.4
  • Operating system: MacOs

How does this bug occur?

When the output destination changes, such as when a new className or targetPackage is given, the previously-generated code remains until clean is run.

What happens when the bug occurs?

Compilation proceeds with both the new and the old code.

Would you like to submit a PR fixing this bug?

[ ] YES
[x] NO

Filtering symbols with argfile

What should this feature provide?

Allow the use of @includes.txt to filter the symbols

https://github.com/openjdk/jextract#filtering-symbols

Why is this feature needed?

The alternative is to put that file's content into the gradle script.

How can this feature be implemented?

Something like:

+// Set argfile
+definition.argfile.orNull?.let {
+    arguments += "@$it"
+}

// Set header file
arguments += definition.header.get()

// Execute command
execute(arguments.toTypedArray())

Cannot be used with gradle kotlin DSL

Environment

  • JDK version: 21.0.2
  • Gradle version: 8,4
  • gradle-jextract version: ___
  • Operating system: Linux

How does this bug occur?

Trying to make a new project with gradle kotlin DSL:

import io.github.krakowski.jextract.JextractPlugin
import io.github.krakowski.jextract.JextractTask
import io.github.krakowski.jextract.LibraryDefinition

plugins {
    kotlin("jvm") version "1.9.22"
    id("application")
    id("c")
    id("io.github.krakowski.jextract") version "0.4.1"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test")
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(21)
}

configure<JextractTask> {
    // The header file from which we want to generate the bindings
    header("${project.projectDir}/src/main/c/native.h") {
        // The library name (don't worry about this for now)
        libraries = arrayOf("nativeLib")
        // The package under which all source files will be generated
        targetPackage = "org.nativelib"
        // The generated class name
        className = "NativeLib"
    }
}

What happens when the bug occurs?

When trying to configure jextract class, Val cannot be reassigned occurs.

Would you like to submit a PR fixing this bug?

[ ] YES
[x] NO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.