summaryrefslogtreecommitdiffhomepage
path: root/building/rustc-remap-path-prefix.sh
blob: 0d3d31fce5e4958c23cb9ee61808eb7185d04059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/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

CARGO_HOME_PATH=${CARGO_HOME:-$HOME/.cargo}
RUSTUP_HOME_PATH=${RUSTUP_HOME:-$HOME/.rustup}
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CARGO_TARGET_DIR_PATH=${CARGO_TARGET_DIR:-$SOURCE_DIR/target}

# The order is significant. Iterated over in reverse, so last argument is
# treated as most significant. Since CARGO_TARGET_DIR_PATH might be located
# under $SOURCE_DIR, it's important to keep it last.
# See: https://github.com/rust-lang/rust/blob/55459598c250d985eb5f840306dfb59f267c03b6/compiler/rustc_span/src/source_map.rs#L1125-L1127
echo "\
--remap-path-prefix $CARGO_HOME_PATH=/CARGO_HOME \
--remap-path-prefix $RUSTUP_HOME_PATH=/RUSTUP_HOME \
--remap-path-prefix $SOURCE_DIR=/SOURCE_DIR \
--remap-path-prefix $CARGO_TARGET_DIR_PATH=/CARGO_TARGET_DIR \
" | xargs