Skip to content

Commit 9574e20

Browse files
committed
Example project for native image
1 parent 1339041 commit 9574e20

File tree

5 files changed

+469
-0
lines changed

5 files changed

+469
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Device Enumeration (Native)
2+
3+
This example project demonstrates how th build a native application that
4+
enumerates connected devices using [GraalVM](https://www.graalvm.org/) and
5+
this _Java Does USB_ library.
6+
7+
## Build and Run
8+
9+
### Prerequisites
10+
11+
- [GraalVM](https://www.graalvm.org/) 25 or higher
12+
- [Maven](https://maven.apache.org/) 3.9 or higher
13+
14+
15+
### Preparation
16+
17+
GraalVM needs help to learn about the Java FFM downcall and upcall descriptors,
18+
and it needs some help to include all required methods. The relevant items
19+
differ from operating system to operating system. When building the native image,
20+
the operating system must be selected by changing the path in the file
21+
`native-image.properties` in the directory
22+
`src/main/resources/META-INF/native-image/net.codecrete.usb.examples/enumerate_native`.
23+
24+
```properties
25+
Args = --enable-native-access=ALL-UNNAMED -H:ConfigurationFileDirectories=config/macos
26+
```
27+
28+
Note the last word of the line. In this case, it is `macos`. Change this to
29+
`linux` or `windows` if needed. (Windows and Linux are yet to come.)
30+
31+
In your own Maven project, you might also need to move the file or rather rename
32+
directory. It must be named according to the pattern
33+
`src/main/resources/META-INF/native-image/<groupId>/<artifactId>`.
34+
35+
36+
### Building
37+
38+
```shell
39+
mvn -Dnative package
40+
```
41+
42+
43+
### Running
44+
45+
```shell
46+
./target/enumerate-native
47+
```
Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
{
2+
"foreign": {
3+
"upcalls": [
4+
{
5+
"returnType": "void",
6+
"parameterTypes": [
7+
"void*",
8+
"jint",
9+
"void*"
10+
]
11+
},
12+
{
13+
"returnType": "void*",
14+
"parameterTypes": [
15+
"void*",
16+
"jint",
17+
"void*",
18+
"void*"
19+
]
20+
},
21+
{
22+
"returnType": "void",
23+
"parameterTypes": [
24+
"void*",
25+
"jint"
26+
]
27+
}
28+
],
29+
"downcalls": [
30+
{
31+
"returnType": "void",
32+
"parameterTypes": [
33+
"void*",
34+
"void*",
35+
"void*"
36+
]
37+
},
38+
{
39+
"returnType": "void",
40+
"parameterTypes": [
41+
"void*",
42+
"struct(jlong,jlong)",
43+
"void*"
44+
]
45+
},
46+
{
47+
"returnType": "void*",
48+
"parameterTypes": [
49+
"void*",
50+
"void*",
51+
"jlong"
52+
]
53+
},
54+
{
55+
"returnType": "jint",
56+
"parameterTypes": [
57+
"void*",
58+
"void*",
59+
"void*"
60+
]
61+
},
62+
{
63+
"returnType": "jint",
64+
"parameterTypes": [
65+
"void*",
66+
"jint",
67+
"void*",
68+
"jdouble",
69+
"jdouble",
70+
"void*",
71+
"void*"
72+
]
73+
},
74+
{
75+
"returnType": "jint",
76+
"parameterTypes": [
77+
"void*",
78+
"void*",
79+
"void*",
80+
"void*",
81+
"void*",
82+
"void*"
83+
]
84+
},
85+
{
86+
"returnType": "jint",
87+
"parameterTypes": [
88+
"jint"
89+
]
90+
},
91+
{
92+
"returnType": "jlong",
93+
"parameterTypes": [
94+
"void*"
95+
]
96+
},
97+
{
98+
"returnType": "void*",
99+
"parameterTypes": []
100+
},
101+
{
102+
"returnType": "jint",
103+
"parameterTypes": [
104+
"void*",
105+
"void*",
106+
"void*",
107+
"void*"
108+
]
109+
},
110+
{
111+
"returnType": "jint",
112+
"parameterTypes": [
113+
"jint",
114+
"void*",
115+
"void*",
116+
"void*",
117+
"void*"
118+
]
119+
},
120+
{
121+
"returnType": "void*",
122+
"parameterTypes": [
123+
"jint",
124+
"void*",
125+
"void*",
126+
"jint"
127+
]
128+
},
129+
{
130+
"returnType": "void*",
131+
"parameterTypes": [
132+
"void*",
133+
"void*"
134+
]
135+
},
136+
{
137+
"returnType": "jint",
138+
"parameterTypes": [
139+
"void*",
140+
"jbyte"
141+
]
142+
},
143+
{
144+
"returnType": "void*",
145+
"parameterTypes": [
146+
"void*",
147+
"jint",
148+
"void*",
149+
"void*"
150+
]
151+
},
152+
{
153+
"returnType": "jbyte",
154+
"parameterTypes": [
155+
"void*",
156+
"jlong",
157+
"void*"
158+
]
159+
},
160+
{
161+
"returnType": "void*",
162+
"parameterTypes": [
163+
"void*",
164+
"struct(jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte)"
165+
]
166+
},
167+
{
168+
"returnType": "void",
169+
"parameterTypes": []
170+
},
171+
{
172+
"returnType": "jint",
173+
"parameterTypes": [
174+
"void*",
175+
"jbyte",
176+
"void*",
177+
"jint",
178+
"jint",
179+
"jint",
180+
"void*",
181+
"void*"
182+
]
183+
},
184+
{
185+
"returnType": "jint",
186+
"parameterTypes": [
187+
"void*",
188+
"jbyte",
189+
"void*",
190+
"void*",
191+
"void*",
192+
"void*",
193+
"void*"
194+
]
195+
},
196+
{
197+
"returnType": "jint",
198+
"parameterTypes": [
199+
"void*",
200+
"void*"
201+
]
202+
},
203+
{
204+
"returnType": "void*",
205+
"parameterTypes": [
206+
"void*"
207+
]
208+
},
209+
{
210+
"returnType": "jlong",
211+
"parameterTypes": []
212+
},
213+
{
214+
"returnType": "void",
215+
"parameterTypes": [
216+
"void*"
217+
]
218+
},
219+
{
220+
"returnType": "jint",
221+
"parameterTypes": [
222+
"void*",
223+
"jbyte",
224+
"void*"
225+
]
226+
},
227+
{
228+
"returnType": "jint",
229+
"parameterTypes": [
230+
"jint",
231+
"void*"
232+
]
233+
},
234+
{
235+
"returnType": "void*",
236+
"parameterTypes": [
237+
"jint"
238+
]
239+
},
240+
{
241+
"returnType": "jint",
242+
"parameterTypes": [
243+
"void*"
244+
]
245+
},
246+
{
247+
"returnType": "void*",
248+
"parameterTypes": [
249+
"void*",
250+
"void*",
251+
"void*",
252+
"void*",
253+
"void*"
254+
]
255+
},
256+
{
257+
"returnType": "jint",
258+
"parameterTypes": [
259+
"void*",
260+
"jbyte",
261+
"void*",
262+
"jint",
263+
"void*",
264+
"void*"
265+
]
266+
},
267+
{
268+
"returnType": "jint",
269+
"parameterTypes": [
270+
"void*",
271+
"struct(jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte)",
272+
"void*"
273+
]
274+
},
275+
{
276+
"returnType": "struct(jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte,jbyte)",
277+
"parameterTypes": [
278+
"void*"
279+
]
280+
},
281+
{
282+
"returnType": "void",
283+
"parameterTypes": [
284+
"void*",
285+
"jint"
286+
]
287+
}
288+
]
289+
},
290+
"reflection": [
291+
{
292+
"type": "net.codecrete.usb.macos.gen.corefoundation.CFMessagePortCreateLocal$callout$Function",
293+
"methods": [
294+
{
295+
"name": "apply",
296+
"parameterTypes": [
297+
"java.lang.foreign.MemorySegment",
298+
"int",
299+
"java.lang.foreign.MemorySegment",
300+
"java.lang.foreign.MemorySegment"
301+
]
302+
}
303+
]
304+
},
305+
{
306+
"type": "net.codecrete.usb.macos.gen.iokit.IOServiceAddMatchingNotification$callback$Function",
307+
"methods": [
308+
{
309+
"name": "apply",
310+
"parameterTypes": [
311+
"java.lang.foreign.MemorySegment",
312+
"int"
313+
]
314+
}
315+
]
316+
}
317+
]
318+
}

0 commit comments

Comments
 (0)