Skip to content

Commit

Permalink
use separate 'target-dir' for 'infra_cli' (NomicFoundation#741)
Browse files Browse the repository at this point in the history
Rust Analyzer runs `cargo check` frequently (on every file save) on the
whole workspace. This locks `$REPO_ROOT/target` directory, and prevents
building/running any other `infra` commands until it is done. To avoid
this during local development, let`s use a separate target directory for
this binary.

Additionally, we cannot use `cargo run --bin infra_cli` directly,
because `cargo run` sets a bunch of `CARGO_*` environment variables, and
they get propagated to any child `cargo` commands that are spawned by
`infra_cli`. We have to build and run the binary directly to ensure it
has a clean env. Otherwise, they leak into things like cross-platform
NAPI builds, and cause build failures.
  • Loading branch information
OmarTawfik authored Jan 13, 2024
1 parent 2c90938 commit a7230b2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/bin/infra
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/../_common.sh"

#
# Rust Analyzer runs 'cargo check' frequently (on every file save) on the whole workspace. This locks
# '$REPO_ROOT/target' directory, and prevents building/running any other 'infra' commands until it is
# done. To avoid this during local development, let's use a separate target directory for this binary.
#
# Additionally, we cannot use 'cargo run --bin infra_cli' directly, because 'cargo run' sets a bunch
# of 'CARGO_*' environment variables, and they get propagated to any child `cargo` commands that are
# spawned by 'infra_cli'. We have to build and run the binary directly to ensure it has a clean env.
# Otherwise, they leak into things like cross-platform NAPI builds, and cause build failures.
#

(
# We cannot use 'cargo run' to run 'infra_cli', because 'cargo run' sets a bunch of
# 'CARGO_*' environment variables, and they get propagated to child `cargo` commands
# that 'infra_cli' spawns. We have to build and run the binary directly to make sure
# it has a clean environment:
crate_dir="${REPO_ROOT:?}/crates/infra/cli"

cargo build \
--bin "infra_cli" \
--manifest-path "${crate_dir}/Cargo.toml" \
--target-dir "${crate_dir}/target"

cargo build --bin "infra_cli"
"${REPO_ROOT:?}/target/debug/infra_cli" "$@"
"${crate_dir}/target/debug/infra_cli" "$@"
)

0 comments on commit a7230b2

Please sign in to comment.