@@ -96,7 +96,12 @@ val gnuSelfContained: File? = File(System.getProperty("user.home"), ".rustup/too
9696val msysBinutils = File (" C:\\ msys64\\ mingw64\\ bin" )
9797
9898fun cargoEnvironment (ndkDir : File ): Map <String , String > = buildMap {
99+ // One NDK, everywhere: AGP's ndkVersion, CI's sdkmanager install and
100+ // cargo-ndk's env all agree on ndkVersionPin. Set BOTH legacy names so a
101+ // stray inherited ANDROID_NDK_ROOT pointing at another NDK cannot split
102+ // the toolchain (observed: 27.3 vs 30.0 warning mid-build).
99103 put(" ANDROID_NDK_HOME" , ndkDir.absolutePath)
104+ put(" ANDROID_NDK_ROOT" , ndkDir.absolutePath)
100105 // Reproducibility: assert()/__FILE__ in vendored C (tree-sitter grammars)
101106 // would bake absolute build paths into the .so; NDEBUG compiles asserts
102107 // out, the prefix-map normalizes anything left. cc-rs splits the env var
@@ -207,6 +212,33 @@ val execProbeTasks = abiTriples.map { (abi, triple) ->
207212 }
208213}
209214
215+ // ---------------------------------------------------------------------------
216+ // Userland (busybox/rg/git) from checksum-verified source — userland/build.sh.
217+ // Lands in build/userland/jniLibs/<abi>/lib{name}.so next to libexecprobe.so.
218+ // ---------------------------------------------------------------------------
219+
220+ val userlandBuild = tasks.register<Exec >(" userlandBuild" ) {
221+ group = " build"
222+ description = " Cross-build busybox/ripgrep/git from source (needs bash+make; MSYS2 on Windows, system tools on Linux CI)"
223+ val outDir = layout.buildDirectory.dir(" userland" )
224+ inputs.files(rootProject.file(" userland/build.sh" ), rootProject.file(" userland/versions.env" ))
225+ outputs.dir(outDir)
226+ outputs.cacheIf { true }
227+ environment(" NDK_HOME" , ndkDir.absolutePath)
228+ environment(" OUT_DIR" , outDir.get().asFile.absolutePath)
229+ // MSYS2 bash on Windows (proven path for the kbuild/autoconf host steps);
230+ // MUST be a login shell: non-login MSYS2 lacks /tmp, /usr/bin on PATH and
231+ // working `ln -s` (all three observed failing under direct gradle spawn).
232+ executable = if (isWindows) " C:\\ msys64\\ usr\\ bin\\ bash.exe" else " bash"
233+ if (isWindows) {
234+ val scriptPosix = rootProject.file(" userland/build.sh" ).absolutePath
235+ .replace(' \\ ' , ' /' ).replace(Regex (" ^([A-Za-z]):" ), " /$1" ).lowercase()
236+ args(" -lc" , " \" $scriptPosix \" " )
237+ } else {
238+ args(rootProject.file(" userland/build.sh" ).absolutePath)
239+ }
240+ }
241+
210242// License texts (Apache-2.0 obligation stack, GPL source offer) ship as
211243// assets; the app shows them from the home screen.
212244val copyLicenseAssets = tasks.register<Copy >(" copyLicenseAssets" ) {
@@ -219,6 +251,7 @@ tasks.named("preBuild") {
219251 dependsOn(cargoNdkRelease)
220252 dependsOn(uniffiBindgen)
221253 dependsOn(execProbeTasks)
254+ dependsOn(userlandBuild)
222255 dependsOn(copyLicenseAssets)
223256}
224257
0 commit comments