Skip to content

Commit

Permalink
WIP: Graal native-image build of Java Schnorr Example
Browse files Browse the repository at this point in the history
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
  • Loading branch information
msgilligan committed Mar 20, 2024
1 parent 1fc7e40 commit c0bc17a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions secp256k1-examples-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,36 @@ run {
def userHome = System.getProperty("user.home")
systemProperty "java.library.path", findProperty("javaPath") ?: "${userHome}/.nix-profile/lib"
}

configurations {
nativeToolImplementation.extendsFrom implementation
}

def mainClassName = "org.bitcoinj.secp256k1.examples.Schnorr"

jar {
manifest {
attributes 'Implementation-Title': 'Schnorr Signature Example',
'Main-Class': mainClassName,
'Implementation-Version': archiveVersion.get()
}
}

// Compile a native image using GraalVM's native-image tool
// Graal must be installed at $GRAALVM_HOME
tasks.register('nativeCompile', Exec) {
dependsOn jar
workingDir = projectDir
executable = "${System.env.GRAALVM_HOME}/bin/native-image"
args = ['--verbose',
'--no-fallback',
'-cp', "${-> configurations.nativeToolImplementation.asPath}", // Lazy configuration resolution
'-jar', jar.archiveFile.get(),
'-H:Path=build',
'-H:Name=schnorr',
'-H:+ForeignAPISupport',
'-H:+ReportUnsupportedElementsAtRuntime',
'-H:+ReportExceptionStackTraces'
]
}

0 comments on commit c0bc17a

Please sign in to comment.