Skip to content

Switch bazel default spawn strategy to sandboxed #9168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,20 @@ build --config=short_logs
# PyTorch/XLA uses exceptions to communicate with Python.
build --copt=-fexceptions

# Force GCC because clang/bazel has issues.
build --action_env=CC=gcc
build --action_env=CXX=g++
build --spawn_strategy=standalone

###########################################################################

build:clang --action_env=CC=/usr/bin/clang-17
build:clang --action_env=CXX=/usr/bin/clang++-17

# clang requires the sandbox mode. Without this, `bazel build` generates an
# error like:
# Why we use the sandbox mode:
#
# 1. it's a good practice that enforces explicit dependency declarations
# (see https://bazel.build/docs/user-manual#spawn-strategy).
# 2. clang requires the sandbox mode. Without this, `bazel build` generates an
# error like:
#
# ERROR: .../external/llvm-project/llvm/BUILD.bazel:2006:11: Compiling
# llvm/lib/CodeGenTypes/LowLevelType.cpp failed: undeclared inclusion(s) in
# rule '@llvm-project//llvm:CodeGenTypes':
# this rule is missing dependency declarations for the following files
# included by 'llvm/lib/CodeGenTypes/LowLevelType.cpp':
# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/config.cppmap'
# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/Demangle.cppmap'
# ERROR: .../external/llvm-project/llvm/BUILD.bazel:2006:11: Compiling
# llvm/lib/CodeGenTypes/LowLevelType.cpp failed: undeclared inclusion(s) in
# rule '@llvm-project//llvm:CodeGenTypes':
# this rule is missing dependency declarations for the following files
# included by 'llvm/lib/CodeGenTypes/LowLevelType.cpp':
# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/config.cppmap'
# 'bazel-out/k8-opt/bin/external/llvm-project/llvm/Demangle.cppmap'
#
# The sandbox mode requires all source files to be readable by others, as
# inside the docker we build PyTorch/XLA as root, not the original user who
Expand All @@ -57,7 +51,16 @@ build:clang --action_env=CXX=/usr/bin/clang++-17
# execute permission to directories, and to files only if they already have
# execute permission for the owner (or group or others). This is generally
# safer than o+rx.
build:clang --spawn_strategy=sandboxed
build --spawn_strategy=sandboxed

# Use GCC for C/C++ compilation.
build --action_env=CC=gcc
build --action_env=CXX=g++

###########################################################################

build:clang --action_env=CC=/usr/bin/clang-17
build:clang --action_env=CXX=/usr/bin/clang++-17

###########################################################################

Expand Down
9 changes: 3 additions & 6 deletions torch_xla/csrc/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <iterator>
#include <limits>

#include "absl/status/status.h"
#include "absl/strings/str_join.h"
#include "torch_xla/csrc/convert_ops.h"
#include "torch_xla/csrc/dtype.h"
Expand Down Expand Up @@ -1043,11 +1042,9 @@ absl::StatusOr<xla::XlaComputation> XlaHelpers::WrapXlaComputation(
xla::XlaOp orig_result = xla::Call(&builder, computation, inner_params);

// Rebuild aliasing.
if (buffer_donor_indices.size() > 0) {
for (size_t i : buffer_donor_indices) {
builder.AddBufferDonor(/*param_number=*/0,
/*param_index=*/xla::ShapeIndex({i}));
}
for (const int64_t i : buffer_donor_indices) {
builder.AddBufferDonor(/*param_number=*/0,
/*param_index=*/xla::ShapeIndex({i}));
}

return builder.Build(orig_result);
Expand Down