Skip to content

Commit

Permalink
Ensure to build release binaries without dcou (#2867)
Browse files Browse the repository at this point in the history
* Ensure to build release binaries without dcou

* Comment about use of RUSTC_BOOTSTRAP

* Mention about lack of use of cargo tree
  • Loading branch information
ryoqun authored Sep 9, 2024
1 parent e351b4f commit b1de2e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
57 changes: 51 additions & 6 deletions scripts/cargo-install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,36 +96,41 @@ if [[ $CI_OS_NAME = windows ]]; then
solana-test-validator
solana-tokens
)
DCOU_BINS=()
else
./fetch-perf-libs.sh

BINS=(
solana
solana-bench-tps
solana-faucet
solana-genesis
solana-gossip
agave-install
solana-keygen
agave-ledger-tool
solana-log-analyzer
solana-net-shaper
agave-validator
rbpf-cli
)
DCOU_BINS=(
agave-ledger-tool
solana-bench-tps
)

# Speed up net.sh deploys by excluding unused binaries
if [[ -z "$validatorOnly" ]]; then
BINS+=(
cargo-build-sbf
cargo-test-sbf
solana-dos
agave-install-init
solana-stake-accounts
solana-test-validator
solana-tokens
agave-watchtower
)
DCOU_BINS+=(
solana-dos
)
fi
fi

Expand All @@ -134,12 +139,52 @@ for bin in "${BINS[@]}"; do
binArgs+=(--bin "$bin")
done

dcouBinArgs=()
for bin in "${DCOU_BINS[@]}"; do
dcouBinArgs+=(--bin "$bin")
done

source "$SOLANA_ROOT"/scripts/dcou-tainted-packages.sh

excludeArgs=()
for package in "${dcou_tainted_packages[@]}"; do
excludeArgs+=(--exclude "$package")
done

mkdir -p "$installDir/bin"

# Some binaries (like the notable agave-ledger-tool) need to acitivate
# the dev-context-only-utils feature flag to build.
# Build those binaries separately to avoid the unwanted feature unification.
# Note that `--workspace --exclude <dcou tainted packages>` is needed to really
# inhibit the feature unification due to a cargo bug. Otherwise, feature
# unification happens even if cargo build is run only with `--bin` targets
# which don't depend on dcou as part of dependencies at all.
(
set -x
# shellcheck disable=SC2086 # Don't want to double quote $rust_version
"$cargo" $maybeRustVersion build $buildProfileArg "${binArgs[@]}"
# Make sure dcou is really disabled by peeking the (unstable) build plan
# output after turning rustc into the nightly mode with RUSTC_BOOTSTRAP=1.
# In this way, additional requirement of nightly rustc toolchian is avoided.
# Note that `cargo tree` can't be used, because it doesn't support `--bin`.
# shellcheck disable=SC2086 # Don't want to double quote $maybeRustVersion
if (RUSTC_BOOTSTRAP=1 \
"$cargo" $maybeRustVersion build \
-Z unstable-options --build-plan \
$buildProfileArg "${binArgs[@]}" --workspace "${excludeArgs[@]}" | \
grep -q -F '"feature=\"dev-context-only-utils\""'); then
echo 'dcou feature activation is incorrctly activated!' && \
exit 1
fi

# Build our production binaries without dcou.
# shellcheck disable=SC2086 # Don't want to double quote $maybeRustVersion
"$cargo" $maybeRustVersion build \
$buildProfileArg "${binArgs[@]}" --workspace "${excludeArgs[@]}"

# Finally, build the remaining dev tools with dcou.
# shellcheck disable=SC2086 # Don't want to double quote $maybeRustVersion
"$cargo" $maybeRustVersion build \
$buildProfileArg "${dcouBinArgs[@]}"

# Exclude `spl-token` binary for net.sh builds
if [[ -z "$validatorOnly" ]]; then
Expand All @@ -155,7 +200,7 @@ mkdir -p "$installDir/bin"
fi
)

for bin in "${BINS[@]}"; do
for bin in "${BINS[@]}" "${DCOU_BINS[@]}"; do
cp -fv "target/$buildProfile/$bin" "$installDir"/bin
done

Expand Down
12 changes: 2 additions & 10 deletions scripts/check-dev-context-only-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@ source ci/rust-version.sh nightly
# as normal (not dev) dependencies, only if you're sure that there's good
# reason to bend dev-context-only-utils's original intention and that listed
# package isn't part of released binaries.
declare tainted_packages=(
solana-accounts-bench
solana-banking-bench
agave-ledger-tool
solana-bench-tps
agave-store-tool
agave-store-histogram
agave-accounts-hash-cache-tool
)
source scripts/dcou-tainted-packages.sh

# convert to comma separeted (ref: https://stackoverflow.com/a/53839433)
printf -v allowed '"%s",' "${tainted_packages[@]}"
printf -v allowed '"%s",' "${dcou_tainted_packages[@]}"
allowed="${allowed%,}"

mode=${1:-full}
Expand Down
13 changes: 13 additions & 0 deletions scripts/dcou-tainted-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# shellcheck disable=SC2034 # This file is intended to be `source`d
declare dcou_tainted_packages=(
solana-accounts-bench
solana-banking-bench
agave-ledger-tool
solana-bench-tps
agave-store-tool
agave-store-histogram
agave-accounts-hash-cache-tool
solana-dos
)

0 comments on commit b1de2e0

Please sign in to comment.