Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / library / ml / build.gradle.kts

build.gradle.kts59 lines · 2.5 KiBRaw
1plugins {
2 id("common-conventions-library")
3}
4
5androidComponents {
6 onVariants { variant ->
7 variant.sources.jniLibs?.addStaticSourceDirectory(
8 layout.buildDirectory.dir("rustJniLibs").get().asFile.absolutePath
9 )
10 }
11}
12
13// The Vulkan compute ML runtime: `library/ml/src/main/rust`, on ash.
14//
15// No `externalNativeBuild` and no `ndkVersion`: there is no C++ or CMake in this repo
16// (CMake was deliberately removed — see maps/build.gradle.kts:29-31), so cargo does the
17// cross-compile and the NDK is only reached for its clang wrappers and glslc.
18//
19// Shaders are GLSL compute compiled to SPIR-V by the `compileShaders` task (build-logic
20// GlslcCompile); `*.glsl` are #include-only and not compiled on their own.
21// `-PemulatorAbi=x86_64` additionally cross-compiles for the emulator's ABI so the gate can be
22// exercised on an x86_64 host. Off unless asked for, so no default or release build is affected.
23rustNativeLib(
24 "modelrunner",
25 "ml",
26 extraAbis = if (providers.gradleProperty("emulatorAbi").orNull == ABI_X86_64) {
27 listOf(ABI_X86_64)
28 } else {
29 emptyList()
30 },
31 shaders = listOf("*.comp"),
32 glslcArgs = listOf("--target-env=vulkan1.1", "-O"),
33)
34
35// Only the classes below actually load a native library: they construct a
36// handle, segmenter or recogniser (WhisperHandle, ClipHandle,
37// Gemma4AudioHandle/Gemma4VisionHandle, TextRecognizer, FaceDetector, the
38// segmenters, SupertonicSynthesizer), whose init reads MlNative.isAvailable
39// — the one System.loadLibrary("modelrunner") attempt — or read that flag
40// directly (HandlesUnavailableTest's `native availability flag` test). The
41// pure Gemma companion tests (render/declare/parse, fitAudio/promptCeiling,
42// markers, n-gram draft, sampling, tool calls) never construct a handle and
43// never touch MlNative, so they stay in the main task. Quarantine the
44// loaders into testDebugUnitTestNative (forkEvery = 1); the remaining
45// classes batch 20-per-JVM in testDebugUnitTest, which depends on the
46// quarantine task so the usual invocation still runs everything. No
47// isolatedClasses: this module has no DataStore/ViewModel or other
48// process-wide singleton for a test to pollute.
49rustNativeTests {
50 nativeClasses.addAll(
51 listOf(
52 "com.vayunmathur.library.ml.DataSemanticsTest",
53 "com.vayunmathur.library.ml.HandlesUnavailableTest",
54 "com.vayunmathur.library.ml.MlDeepTest",
55 "com.vayunmathur.library.ml.SegmentationAndFacesTest",
56 "com.vayunmathur.library.ml.SupertonicTest",
57 )
58 )
59}