@@ -47,12 +47,17 @@ allprojects {
4747 }
4848}
4949
50+ val cargoBinaryPath = resolveBinary(" cargo" )
51+ val rustcBinaryPath = resolveBinary(" rustc" )
5052val cargoProjectRoot = " ${project.rootDir} /../.."
5153val jniLibsPath = " ${layout.buildDirectory.get()} /jniLibs/"
5254val generatedTestResourcesPath = " ${layout.buildDirectory.get()} /generatedTestResources/"
5355val rustModuleName = " wp_api"
5456val nativeLibraryPath =
5557 " $cargoProjectRoot /target/release/lib${rustModuleName}${getNativeLibraryExtension()} "
58+
59+ rootProject.ext.set(" cargoBinaryPath" , cargoBinaryPath)
60+ rootProject.ext.set(" rustcBinaryPath" , rustcBinaryPath)
5661rootProject.ext.set(" cargoProjectRoot" , cargoProjectRoot)
5762rootProject.ext.set(" jniLibsPath" , jniLibsPath)
5863rootProject.ext.set(" generatedTestResourcesPath" , generatedTestResourcesPath)
@@ -68,7 +73,7 @@ fun setupJniAndBindings() {
6873
6974 val cargoBuildLibraryReleaseTask = tasks.register<Exec >(" cargoBuildLibraryRelease" ) {
7075 workingDir(rootProject.ext.get(" cargoProjectRoot" )!! )
71- commandLine(" cargo " , " build" , " --package" , rustModuleName, " --release" )
76+ commandLine(cargoBinaryPath , " build" , " --package" , rustModuleName, " --release" )
7277 // No inputs.dir added, because we want to always re-run this task and let Cargo handle caching
7378 }
7479
@@ -101,6 +106,16 @@ fun setupJniAndBindings() {
101106 }
102107}
103108
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+
104119fun getNativeLibraryExtension (): String {
105120 val currentOS = org.gradle.internal.os.OperatingSystem .current()
106121 return if (currentOS.isLinux) {
0 commit comments