Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix nix shell detection + keep the non-nix build behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kczulko committed Mar 15, 2024
1 parent 8738585 commit 648e60e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ task compileRust {
project.logger.info("#####################" + System.getProperty("os.name").toLowerCase())
doLast {
// nix build detection
if (!System.getenv('NIX_CC').empty) {
if (System.getenv('NIX_CC') != null) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=aarch64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
Expand All @@ -29,11 +29,25 @@ task compileRust {
environment RUSTFLAGS: "-L ${System.getenv('PTHREAD_LOCATION')}"
}
} else {
// keep the old build behavior while not running in nix shell
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-unknown-linux-gnu', '--target-dir=../../build/jni-crypto'
}
} else if (System.getProperty("os.name").toLowerCase().contains("windows")) {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target=x86_64-pc-windows-gnu', '--target-dir=../../build/jni-crypto'
}
}
// Does not cover solaris, just MacOS. See potential return types here:
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target-dir=../../build/jni-crypto'
// https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html
else {
exec {
workingDir 'src/jni-crypto'
commandLine 'cargo', 'build', '--release', '--target-dir=../../build/jni-crypto'
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static String copyLibraryFromResourcesToTempDir() throws IOException {
osDir = "x86_64-linux";
} else if (IS_LINUX && IS_AARCH64) {
osDir = "aarch64-linux";
} else if (IS_MAC) { // TODO 'MasOS support problem'
} else if (IS_MAC) { // TODO 'MacOS support problem'
osDir = "macos";
} else {
throw new RuntimeException("JNI library can't be loaded because OS wasn't detected as supported.");
Expand Down

0 comments on commit 648e60e

Please sign in to comment.