@@ -7,6 +7,7 @@ ext.moduleName = 'org.bitcoinj.secp.examples'
7
7
8
8
dependencies {
9
9
implementation project(' :secp-api' )
10
+ implementation project(' :secp-graalvm' )
10
11
runtimeOnly project(' :secp-bouncy' )
11
12
runtimeOnly project(' :secp-ffm' )
12
13
}
20
21
inputs. property(" moduleName" , moduleName)
21
22
manifest {
22
23
attributes ' Implementation-Title' : ' Example secp256k1-jdk Apps' ,
24
+ ' Main-Class' : application. mainClass,
23
25
' Implementation-Version' : archiveVersion. get()
24
26
}
25
27
}
33
35
jvmArgs + = ' --enable-native-access=org.bitcoinj.secp.ffm'
34
36
}
35
37
38
+ configurations {
39
+ nativeToolImplementation. extendsFrom implementation
40
+ nativeToolRuntimeOnly. extendsFrom runtimeOnly
41
+ }
42
+
36
43
tasks. register(' runEcdsa' , JavaExec ) {
37
44
javaLauncher = javaToolchains. launcherFor {
38
45
languageVersion = JavaLanguageVersion . of(javaToolchainVersion)
@@ -42,3 +49,61 @@ tasks.register('runEcdsa', JavaExec) {
42
49
mainClass = ' org.bitcoinj.secp.examples.Ecdsa'
43
50
jvmArgs + = ' --enable-native-access=org.bitcoinj.secp.ffm'
44
51
}
52
+
53
+ tasks. register(' nativeCompile' ) {
54
+ dependsOn ' nativeCompileSchnorr' , ' nativeCompileEcdsa'
55
+ }
56
+
57
+ // Compile a native image using GraalVM's native-image tool
58
+ // Graal must be installed at $GRAALVM_HOME
59
+ tasks. register(' nativeCompileSchnorr' , Exec ) {
60
+ dependsOn jar
61
+ workingDir = projectDir
62
+ executable = " ${ System.env.GRAALVM_HOME} /bin/native-image"
63
+ args = [' --verbose' ,
64
+ ' --no-fallback' ,
65
+ ' --module' , ' org.bitcoinj.secp.examples/org.bitcoinj.secp.examples.Schnorr' ,
66
+ ' --module-path' , jar. archiveFile. get(),
67
+ ' --module-path' , " ${ -> configurations.nativeToolImplementation.asPath} " , // Lazy configuration resolution
68
+ ' --module-path' , " ${ -> configurations.nativeToolRuntimeOnly.asPath} " , // Lazy configuration resolution
69
+ ' --add-modules' , ' org.bitcoinj.secp.ffm' ,
70
+ ' --enable-native-access=org.bitcoinj.secp.ffm' ,
71
+ ' -H:Path=build' ,
72
+ ' -H:Name=schnorr-example' ,
73
+ ' -H:+ForeignAPISupport' ,
74
+ ' -H:+SharedArenaSupport' ,
75
+ ' -H:-CheckToolchain' ,
76
+ ' --features=org.bitcoinj.secp.graalvmffm.ForeignRegistrationFeature' ,
77
+ ' --enable-native-access=ALL-UNNAMED' ,
78
+ ' -H:+ReportUnsupportedElementsAtRuntime' ,
79
+ ' -H:+ReportExceptionStackTraces'
80
+ ]
81
+ }
82
+
83
+ // Compile a native image using GraalVM's native-image tool
84
+ // Graal must be installed at $GRAALVM_HOME
85
+ // THIS IS NOT WORKING YET, THERE'S A PROBLEM AT RUNTIME:
86
+ // "Cannot perform downcall with leaf type (long,long,long,long,long)int as it was not registered at compilation time"
87
+ tasks. register(' nativeCompileEcdsa' , Exec ) {
88
+ dependsOn jar
89
+ workingDir = projectDir
90
+ executable = " ${ System.env.GRAALVM_HOME} /bin/native-image"
91
+ args = [' --verbose' ,
92
+ ' --no-fallback' ,
93
+ ' --module' , ' org.bitcoinj.secp.examples/org.bitcoinj.secp.examples.Ecdsa' ,
94
+ ' --module-path' , jar. archiveFile. get(),
95
+ ' --module-path' , " ${ -> configurations.nativeToolImplementation.asPath} " , // Lazy configuration resolution
96
+ ' --module-path' , " ${ -> configurations.nativeToolRuntimeOnly.asPath} " , // Lazy configuration resolution
97
+ ' --add-modules' , ' org.bitcoinj.secp.ffm' ,
98
+ ' --enable-native-access=org.bitcoinj.secp.ffm' ,
99
+ ' -H:Path=build' ,
100
+ ' -H:Name=ecdsa-example' ,
101
+ ' -H:+ForeignAPISupport' ,
102
+ ' -H:+SharedArenaSupport' ,
103
+ ' -H:-CheckToolchain' ,
104
+ ' --features=org.bitcoinj.secp.graalvmffm.ForeignRegistrationFeature' ,
105
+ ' --enable-native-access=ALL-UNNAMED' ,
106
+ ' -H:+ReportUnsupportedElementsAtRuntime' ,
107
+ ' -H:+ReportExceptionStackTraces'
108
+ ]
109
+ }
0 commit comments