-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panama-backend - basic integration with jextract #499
base: main
Are you sure you want to change the base?
Changes from 2 commits
e260451
7c5b60d
037aacf
c8282c9
5272832
dc8969f
aa87b13
c3cb18f
e863425
68e6beb
e58ed73
7005062
c02c92f
fdc619b
031272d
a323918
127d6ff
2b10d7a
69cbab6
eb6e890
7cd8e8a
ee58338
d620460
18a5762
770b99b
15b0f7e
b442eea
04fdbba
42898fe
3973f19
2148183
57e67e6
9bebc5b
b9bc603
5666887
e323f50
d56671e
0d9a024
99e0ec2
89f1aab
fba6db2
108417a
fc5a255
85da4d5
6c2f94e
7aabcc2
cae2a94
2252b85
9878fb9
f3eb060
4de1b97
2ec7735
5ab860a
a796ffb
5abfc5d
d6e61f9
d8e7509
41becfa
5b6fbd8
fc37865
35a587c
596b0c2
bc7c3fe
47f7ce9
dfe88e3
42d941b
4aa75d6
d633c3b
7f37a99
bfc71ea
14ae4a5
b00adf6
8675eb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
.idea/encodings.xml | ||
.idea/misc.xml | ||
.idea/vcs.xml | ||
.idea/codeStyles | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
libsomelib.dylib |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>dev.diplomattest.somelib</groupId> | ||
<artifactId>somelib</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>22</maven.compiler.source> | ||
<maven.compiler.target>22</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>RELEASE</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
public class OpaqueBench { | ||
@Benchmark | ||
public static void benchOpaque(Blackhole bh) { | ||
var opaque = new Opaque(); | ||
bh.consume(opaque); | ||
// opaque.delete(); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(OpaqueBench.class.getSimpleName()) | ||
.forks(1) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import java.lang.ref.Cleaner; | ||
|
||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or | ||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. | ||
public class Main { | ||
static final Cleaner cleaner = Cleaner.create(); | ||
public static void main(String[] args) { | ||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text | ||
// to see how IntelliJ IDEA suggests fixing it. | ||
System.out.printf("Hello and welcome!"); | ||
|
||
for (int i = 1; i <= 5; i++) { | ||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint | ||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>. | ||
System.out.println("i = " + i); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import dev.diplomattest.somelib.ntv.somelib_h; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.SegmentAllocator; | ||
|
||
public class MyStruct { | ||
MemorySegment nativeStruct$; | ||
public MyStruct(SegmentAllocator alloc) { | ||
var function = somelib_h.MyStruct_new.makeInvoker(); | ||
this.nativeStruct$ = function.apply(alloc); | ||
} | ||
|
||
MemorySegment getNativeStruct$() { | ||
return nativeStruct$; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.diplomattest.somelib; | ||
|
||
import dev.diplomattest.somelib.ntv.somelib_h; | ||
import dev.diplomattest.somelib.ntv.somelib_h; | ||
|
||
import java.lang.foreign.MemoryLayout; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.ref.Cleaner; | ||
|
||
public class Opaque { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the tool doesn't actually generate code, the class body has now been been copied from an insta snapshot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ no longer valid 😝 |
||
private MemorySegment internal; | ||
private final Cleaner.Cleanable cleanable; | ||
static class OpaqueCleaner implements Runnable { | ||
MemorySegment segment; | ||
OpaqueCleaner(MemorySegment segment) { | ||
this.segment = segment; | ||
} | ||
public void run() { | ||
somelib_h.Opaque_destroy(this.segment); | ||
} | ||
} | ||
public Opaque() { | ||
var invoker = somelib_h.Opaque_new.makeInvoker(); | ||
var segment = invoker.apply(); | ||
this.internal = segment; | ||
var opaqueCleaner = new OpaqueCleaner(segment); | ||
this.cleanable = Main.cleaner.register(this, opaqueCleaner); | ||
} | ||
|
||
public long pointer() { | ||
return internal.address(); | ||
} | ||
|
||
public void delete() { | ||
somelib_h.Opaque_destroy(this.internal); | ||
} | ||
|
||
public void assertStruct(MyStruct struct) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: wait, jextract generated this from the C header files? How did it know that these C header files correspond to a class with methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly no, that would be amazing 😃. That’s just a hand rolled wrapper for a more ergonomic type. I’m using this to build the templating for opaque types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha! Okay, carry on! |
||
somelib_h.Opaque_assert_struct(internal, struct.getNativeStruct$()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a shell command to actually run this yet. I only ran it from IntelliJ, but want to keep it as it'll be nice to have to compare to the kotlin backend once the icu4x example can be made to work