Skip to content

Commit e33c9c7

Browse files
committedMar 20, 2024
WIP: Graal native-image build of Java Schnorr Example
To build native image use: ./gradlew secp256k1-examples-java:nativeCompile Build currently fails on macOS with: Error: Support for the Foreign Function and Memory API is currently available only on the AMD64 architecture
1 parent d80b889 commit e33c9c7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

‎secp256k1-examples-java/build.gradle

+33
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,36 @@ run {
3333
def userHome = System.getProperty("user.home")
3434
systemProperty "java.library.path", findProperty("javaPath") ?: "${userHome}/.nix-profile/lib"
3535
}
36+
37+
configurations {
38+
nativeToolImplementation.extendsFrom implementation
39+
}
40+
41+
def mainClassName = "org.bitcoinj.secp256k1.examples.Schnorr"
42+
43+
jar {
44+
manifest {
45+
attributes 'Implementation-Title': 'Schnorr Signature Example',
46+
'Main-Class': mainClassName,
47+
'Implementation-Version': archiveVersion.get()
48+
}
49+
}
50+
51+
// Compile a native image using GraalVM's native-image tool
52+
// Graal must be installed at $GRAALVM_HOME
53+
tasks.register('nativeCompile', Exec) {
54+
dependsOn jar
55+
workingDir = projectDir
56+
executable = "${System.env.GRAALVM_HOME}/bin/native-image"
57+
args = ['--verbose',
58+
'--no-fallback',
59+
'-cp', "${-> configurations.nativeToolImplementation.asPath}", // Lazy configuration resolution
60+
'-jar', jar.archiveFile.get(),
61+
'-H:Path=build',
62+
'-H:Name=schnorr',
63+
'-H:+ForeignAPISupport',
64+
'-H:+ReportUnsupportedElementsAtRuntime',
65+
'-H:+ReportExceptionStackTraces'
66+
]
67+
}
68+

0 commit comments

Comments
 (0)