summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2025-01-23 17:50:06 +0100
committerKalle Lindström <karl.lindstrom@mullvad.net>2025-01-23 17:50:06 +0100
commit1a58706ffd5cb0702a1ba3281fd648deb9b6501e (patch)
tree48c607aeefc99a1b06a28dd786172eb695197ede
parentdfa29794bdc5e8f6211b3eaf6c5fd15a220265d2 (diff)
downloadmullvadvpn-1a58706ffd5cb0702a1ba3281fd648deb9b6501e.tar.xz
mullvadvpn-1a58706ffd5cb0702a1ba3281fd648deb9b6501e.zip
Add script to generate rustc --remap-path-prefix
This is needed for reproducible builds. The script gets the file paths to the user's Cargo and Rustup home dirs, as well as the path to the Mullvad app source dir. These paths are then remapped to fixed values which is needed to make the build reproducible.
-rw-r--r--android/app/build.gradle.kts5
-rw-r--r--android/buildSrc/src/main/kotlin/Utils.kt26
-rwxr-xr-xbuilding/rustc-remap-path-prefix.sh15
3 files changed, 38 insertions, 8 deletions
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts
index 26db17f1bb..5bd78f7906 100644
--- a/android/app/build.gradle.kts
+++ b/android/app/build.gradle.kts
@@ -291,6 +291,11 @@ cargo {
add("--locked")
}
}
+ exec = { spec, _ ->
+ val remaps = generateRemapArguments()
+ println("rustc path prefix remaps: $remaps")
+ spec.environment("RUSTFLAGS", remaps)
+ }
}
tasks.register<Exec>("generateRelayList") {
diff --git a/android/buildSrc/src/main/kotlin/Utils.kt b/android/buildSrc/src/main/kotlin/Utils.kt
index ffea7ce51f..5c70b6f290 100644
--- a/android/buildSrc/src/main/kotlin/Utils.kt
+++ b/android/buildSrc/src/main/kotlin/Utils.kt
@@ -1,7 +1,5 @@
-import java.io.ByteArrayOutputStream
import java.util.*
import org.gradle.api.Project
-import org.gradle.process.ExecSpec
fun Project.generateVersionCode(localProperties: Properties): Int {
return localProperties.getProperty("OVERRIDE_VERSION_CODE")?.toIntOrNull()
@@ -12,12 +10,24 @@ fun Project.generateVersionName(localProperties: Properties): String {
return localProperties.getProperty("OVERRIDE_VERSION_NAME") ?: execVersionNameCargoCommand()
}
+fun Project.generateRemapArguments(): String {
+ val script = "${projectDir.parent}/../building/rustc-remap-path-prefix.sh"
+ return providers.exec { commandLine(script) }.standardOutput.asText.get().trim()
+}
+
private fun Project.execVersionCodeCargoCommand() =
- providers.exec {
- commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionCode")
- }.standardOutput.asText.get().trim().toInt()
+ providers
+ .exec { commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionCode") }
+ .standardOutput
+ .asText
+ .get()
+ .trim()
+ .toInt()
private fun Project.execVersionNameCargoCommand() =
- providers.exec {
- commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionName")
- }.standardOutput.asText.get().trim()
+ providers
+ .exec { commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionName") }
+ .standardOutput
+ .asText
+ .get()
+ .trim()
diff --git a/building/rustc-remap-path-prefix.sh b/building/rustc-remap-path-prefix.sh
new file mode 100755
index 0000000000..0531d206e7
--- /dev/null
+++ b/building/rustc-remap-path-prefix.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+# Returns the rustc `--remap-path-prefix` flags needed to replace file paths
+# that gets put in the build artifacts with fixed values in order to make
+# the build reproducible across different machines.
+
+set -eu
+
+SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
+CARGO_HOME_PATH=${CARGO_HOME:-$HOME/.cargo}
+RUSTUP_HOME_PATH=${RUSTUP_HOME:-$HOME/.rustup}
+
+echo "--remap-path-prefix $CARGO_HOME_PATH=/CARGO_HOME \
+--remap-path-prefix $RUSTUP_HOME_PATH=/RUSTUP_HOME \
+--remap-path-prefix $SOURCE_DIR=/SOURCE_DIR"