Skip to content

Commit

Permalink
add --incompatible_strict_action_env
Browse files Browse the repository at this point in the history
I kept running into a problem where bazel would rebuild every time I changed from being in a python virtualenv to not doing that (which happens because I was using the python scripts). I found out this is because PATH changes cause a full rebuild. This flag avoids that.

PiperOrigin-RevId: 626403108
  • Loading branch information
j2kun authored and Copybara-Service committed Apr 19, 2024
1 parent 1c6fadc commit 22a8293
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ common --action_env=BAZEL_CXXOPTS=-std=gnu++17
common --cxxopt='-std=gnu++17'
common --copt=-fdiagnostics-color=always
common --test_output=errors
# compilation_mode options below are `dbg` (debug symbols) `fastbuild`
# (build as quickly as possible), and `opt` (turn on all optimizations)
common -c dbg
common --noenable_bzlmod
# prevents changes to PATH from causing a full rebuild
common --incompatible_strict_action_env
8 changes: 6 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ jobs:
restore-keys: |
${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }}-
# --noincompatible_strict_action_env is used below to inherit the path
# from the parent process, which is required for the build to be cached
# and reused in the `Test rust codegen targets` step below, as that step
# requires the `PATH` to find the `cargo` binary.
- name: "Run `bazel build`"
run: |
bazel build -c fastbuild //...
bazel build --noincompatible_strict_action_env -c fastbuild //...
- name: "Run `bazel test`"
run: |
bazel test -c fastbuild //...
bazel test --noincompatible_strict_action_env -c fastbuild //...
# Tests specifically for the tfhe-rs codegen
- name: rustup toolchain install
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/run_rust_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
set -eux
set -o pipefail

bazel query "filter('.mlir.test$', //tests/tfhe_rust/end_to_end/...)" | xargs bazel test -c fastbuild --sandbox_writable_path=$HOME/.cargo "$@"
# noincompatible_strict_action_env is used to inherit the PATH environment
# variable from the parent process, which is needed to find the `cargo`
# executable.

bazel query "filter('.mlir.test$', //tests/tfhe_rust/end_to_end/...)" \
| xargs bazel test \
--noincompatible_strict_action_env \
-c fastbuild \
--sandbox_writable_path=$HOME/.cargo \
"$@"
20 changes: 20 additions & 0 deletions docs/content/en/docs/ide_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ file changes.
If you encounter errors like `*.h.inc` not found, or syntax errors inside these
files, you may need to build those targets and then re-run the `refresh_all`
command above.

## Tips for working with Bazel

Bazel is notoriously fickle when it comes to deciding whether a full rebuild is
necessary, which is bad for HEIR because rebuilding LLVM from scratch takes 15
minutes or more.

The main things that cause a rebuild are:

- A change to the command-line flags passed to bazel, e.g., `-c opt` vs `-c
dbg` for optimization level and debug symbols.
- A change to the `.bazelrc` that implicitly causes a flag change. Note HEIR
has its own project-specific `.bazelrc` in the root directory.
- A change to relevant command-line variables, such as `PATH`, which is
avoided by the `incompatible_strict_action_env` flag. Note activating a
python virtualenv triggers a `PATH` change.

Bazel compilation flags are set by default in the project root's `.bazelrc` in
such a way as to avoid rebuilds during development as much as possible. This
includes setting `-c dbg` and `--incompatible_strict_action_env`.

0 comments on commit 22a8293

Please sign in to comment.