@@ -47,12 +47,17 @@ allprojects {
47
47
}
48
48
}
49
49
50
+ val cargoBinaryPath = resolveBinary(" cargo" )
51
+ val rustcBinaryPath = resolveBinary(" rustc" )
50
52
val cargoProjectRoot = " ${project.rootDir} /../.."
51
53
val jniLibsPath = " ${layout.buildDirectory.get()} /jniLibs/"
52
54
val generatedTestResourcesPath = " ${layout.buildDirectory.get()} /generatedTestResources/"
53
55
val rustModuleName = " wp_api"
54
56
val nativeLibraryPath =
55
57
" $cargoProjectRoot /target/release/lib${rustModuleName}${getNativeLibraryExtension()} "
58
+
59
+ rootProject.ext.set(" cargoBinaryPath" , cargoBinaryPath)
60
+ rootProject.ext.set(" rustcBinaryPath" , rustcBinaryPath)
56
61
rootProject.ext.set(" cargoProjectRoot" , cargoProjectRoot)
57
62
rootProject.ext.set(" jniLibsPath" , jniLibsPath)
58
63
rootProject.ext.set(" generatedTestResourcesPath" , generatedTestResourcesPath)
@@ -68,7 +73,7 @@ fun setupJniAndBindings() {
68
73
69
74
val cargoBuildLibraryReleaseTask = tasks.register<Exec >(" cargoBuildLibraryRelease" ) {
70
75
workingDir(rootProject.ext.get(" cargoProjectRoot" )!! )
71
- commandLine(" cargo " , " build" , " --package" , rustModuleName, " --release" )
76
+ commandLine(cargoBinaryPath , " build" , " --package" , rustModuleName, " --release" )
72
77
// No inputs.dir added, because we want to always re-run this task and let Cargo handle caching
73
78
}
74
79
@@ -101,6 +106,16 @@ fun setupJniAndBindings() {
101
106
}
102
107
}
103
108
109
+ fun resolveBinary (name : String ): String {
110
+ val process = ProcessBuilder ().apply {
111
+ command(listOf (" which" , name))
112
+ }.start()
113
+
114
+ process.waitFor()
115
+
116
+ return process.inputReader().readText().trim()
117
+ }
118
+
104
119
fun getNativeLibraryExtension (): String {
105
120
val currentOS = org.gradle.internal.os.OperatingSystem .current()
106
121
return if (currentOS.isLinux) {
0 commit comments