From 205b049fcd4ea1fd998c8343e65e794941ff35d8 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Mon, 20 Oct 2025 19:00:00 +0200 Subject: [PATCH] mach: Android: Support custom profiles (#39982) Use Release mode for gradle for production builds and Debug for any other builds. This fixes an exception when building for android with a custom cargo profile. `SERVO_TARGET_DIR` is read in `apk/jni/Android.mk` and specifies the folder libservoshell.so is expected to be in. Testing: Tested manually with `./mach build --android --production` Fixes: #34564 --------- Signed-off-by: Jonathan Schwender Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Co-authored-by: Mukilan Thiyagarajan --- python/servo/command_base.py | 2 +- python/servo/package_commands.py | 8 ++++++-- support/android/apk/buildSrc/src/main/kotlin/Interop.kt | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 74a14d018e3..60a531ce662 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -77,7 +77,7 @@ class BuildType: return self.kind == BuildType.Kind.RELEASE def is_prod(self) -> bool: - return self.kind == BuildType.Kind.CUSTOM and self.profile == "production" + return self.is_custom() and (self.profile in ["production", "production-stripped"]) def is_custom(self) -> bool: return self.kind == BuildType.Kind.CUSTOM diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py index b547199f4d4..5e8d6e3338f 100644 --- a/python/servo/package_commands.py +++ b/python/servo/package_commands.py @@ -136,10 +136,14 @@ class PackageCommands(CommandBase): if build_type.is_dev(): build_type_string = "Debug" - elif build_type.is_release(): + elif build_type.is_release() or build_type.is_prod(): build_type_string = "Release" else: - raise Exception("TODO what should this be?") + print(f"Servo was built with custom cargo profile `{build_type.profile}`.") + print("Using Debug build for gradle.") + build_type_string = "Debug" + # Inform the android build of where `libservoshell.so` is located. + env["SERVO_TARGET_DIR"] = target_dir flavor_name = "Basic" if flavor is not None: diff --git a/support/android/apk/buildSrc/src/main/kotlin/Interop.kt b/support/android/apk/buildSrc/src/main/kotlin/Interop.kt index 79b9694058b..d81b6d53a22 100644 --- a/support/android/apk/buildSrc/src/main/kotlin/Interop.kt +++ b/support/android/apk/buildSrc/src/main/kotlin/Interop.kt @@ -15,7 +15,11 @@ fun Project.getTargetDir(debug: Boolean, arch: String): String { fun Project.getNativeTargetDir(debug: Boolean, arch: String): String { val basePath = project.rootDir.parentFile.parentFile.parentFile.absolutePath - return basePath + "/target/" + getSubTargetDir(debug, arch) + val fallback = basePath + "/target/" + getSubTargetDir(debug, arch) + // Prefer the value provided by `mach`, which supports custom cargo profiles. + // The fallback is for packaging in Android studio, after a mach build (only debug / release). + val target_dir = System.getenv("SERVO_TARGET_DIR") ?: fallback + return target_dir } fun getSubTargetDir(debug: Boolean, arch: String): String {