Skip to content

Commit

Permalink
Add script to generate rustc --remap-path-prefix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kl committed Jan 23, 2025
1 parent dfa2979 commit 1a58706
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
26 changes: 18 additions & 8 deletions android/buildSrc/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
15 changes: 15 additions & 0 deletions building/rustc-remap-path-prefix.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 1a58706

Please sign in to comment.