Skip to content

Commit

Permalink
Update how LD_LIBRARY_PATH is set for rustfmt binaries in diff check
Browse files Browse the repository at this point in the history
rustfmt currently has a runtime dependency on the sysroot. So when we
build a standalone rustfmt binary we need to set `LD_LIBRARY_PATH` so
each rustfmt binary knows where to find it's dependencies.

When running our Diff-Check job to test PRs for breaking changes it's
often the case that both the master rustfmt binary and the feature
branch binary have the same runtime dependencies so we only need to
set `LD_LIBRARY_PATH` once.

However, when running the diff-check job against a subtree sync PR that
assumption doesn't hold. The subtree sync PR bumps the required
toolchain used to build rustfmt and therefore the binary that gets built
for the subtree sync PR has a different runtime dependency than the
master rustfmt binary.
  • Loading branch information
ytmimi committed Oct 28, 2023
1 parent f05e7af commit 1271c79
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ci/check_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

set -e

# https://github.com/rust-lang/rustfmt/issues/5675
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH

function print_usage() {
echo "usage check_diff REMOTE_REPO FEATURE_BRANCH [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]"
}
Expand Down Expand Up @@ -117,6 +114,11 @@ function compile_rustfmt() {
CARGO_VERSON=$(cargo --version)
echo -e "\ncompiling with $CARGO_VERSON\n"

# Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each
# binary can find it's runtime dependencies. See https://github.com/rust-lang/rustfmt/issues/5675
# This will prepend the `LD_LIBRARY_PATH` for the master rustfmt binary
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH

echo "Building rustfmt from src"
cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/rustfmt

Expand All @@ -126,9 +128,18 @@ function compile_rustfmt() {
git switch $OPTIONAL_COMMIT_HASH --detach
fi

# This will prepend the `LD_LIBRARY_PATH` for the feature branch rustfmt binary.
# In most cases the `LD_LIBRARY_PATH` should be the same for both rustfmt binaries that we build
# in `compile_rustfmt`, however, there are scenarios where each binary has different runtime
# dependencies. For example, during subtree syncs we bump the nightly toolchain required to build
# rustfmt, and therefore the feature branch relies on a newer set of runtime dependencies.
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH

echo "Building feature rustfmt from src"
cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/feature_rustfmt

echo -e "\nRuntime dependencies for rustfmt -- LD_LIBRARY_PATH: $LD_LIBRARY_PATH"

RUSFMT_BIN=$1/rustfmt
RUSTFMT_VERSION=$($RUSFMT_BIN --version)
echo -e "\nRUSFMT_BIN $RUSTFMT_VERSION\n"
Expand Down

0 comments on commit 1271c79

Please sign in to comment.