chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# Copyright 2024 The OpenXLA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
licenses = ["notice"],
)
+90
View File
@@ -0,0 +1,90 @@
# Copyright 2024 The OpenXLA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""A collection of Bazel aspects that can help detecting dependency violations
The dependency violation detection works by iterating through all targets in XLA
and comparing the applied tags of each target to the tags of all its dependencies.
If a target is tagged `gpu` it means it can only be used in an XLA build with the
GPU backend enabled. Hence all targets that are NOT tagged `gpu` may never depend
on a target that IS tagged `gpu` if we are building XLA with only the CPU backend
enabled.
The Bazel aspect runs after Bazel's analysis phase. That means all `select` expressions
(and its derivatives like the `if_gpu_is_configured` macro) have been evaluated and
the actual build configuration is taken into account.
The easiest way to run the aspect is during a build:
`bazel build --aspects build_tools/dependencies/aspects.bzl%validate_gpu_tag //xla/...`
But a cquery expression also works:
`bazel cquery --aspects build_tools/dependencies/aspects.bzl%validate_gpu_tag //xla/...`
The results are reported as debug prints and need to be fished out of stderr. There
are ways to make it less hacky but the complexity of the aspect would also increase
quite a bit.
"""
DependencyViolationInfo = provider(
"Internal provider needed by the dependency violation check",
fields = {
# We can't access the tags of a dependency through the context, so instead we
# "send" the tags to the dependee through this provider.
"tags": "Tags of the dependecy",
},
)
def _dependency_violation_aspect_impl(_, ctx, tag):
if not hasattr(ctx.rule.attr, "deps"):
return [DependencyViolationInfo(tags = ctx.rule.attr.tags)]
for dep in ctx.rule.attr.deps:
if DependencyViolationInfo not in dep:
continue
dep_tags = dep[DependencyViolationInfo].tags
if tag in dep_tags and tag not in ctx.rule.attr.tags:
print("[Violation] {} (not tagged {}) depends on {} (tagged {})".format(
ctx.label,
tag,
dep.label,
tag,
)) # buildifier: disable=print
return [DependencyViolationInfo(tags = ctx.rule.attr.tags)]
def _gpu_tag_violation_aspect_impl(target, ctx):
return _dependency_violation_aspect_impl(target, ctx, "gpu")
validate_gpu_tag = aspect(
implementation = _gpu_tag_violation_aspect_impl,
attr_aspects = ["deps"],
)
def _cuda_only_tag_violation_aspect_impl(target, ctx):
return _dependency_violation_aspect_impl(target, ctx, "cuda-only")
validate_cuda_only_tag = aspect(
implementation = _cuda_only_tag_violation_aspect_impl,
attr_aspects = ["deps"],
)
def _rocm_only_tag_violation_aspect_impl(target, ctx):
return _dependency_violation_aspect_impl(target, ctx, "rocm-only")
validate_rocm_only_tag = aspect(
implementation = _rocm_only_tag_violation_aspect_impl,
attr_aspects = ["deps"],
)
@@ -0,0 +1,61 @@
#!/bin/bash
# Copyright 2025 The OpenXLA Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Generates a patch file that disables the layering check for all cc_library
# targets in the archive. Both BUILD and BUILD.bazel files are taken into account.
#
# The script takes one argument: the URL of the .tar.gz archive to download.
#
# The following tools are needed (need to be installed on the machine):
# - curl
# - git
# - buildozer (from Bazel buildtools)
#
# The tool has originally been written for ortools but should work for similarly structured
# projects as well.
#
# Example:
# build_tools/dependencies/gen_disable_layering_check_patch.sh \
# https://github.com/google/or-tools/archive/v9.11.tar.gz \
# > third_party/ortools/layering_check.patch
set -euo pipefail
readonly TMP_DIR=$(mktemp -d)
trap 'rm -rf -- $TMP_DIR' EXIT
echo "Downloading archive $1..." >&2
curl -Lqo "$TMP_DIR/archive.tar.gz" "$1" 1>&2
echo "Extracting archive..." >&2
mkdir -p "$TMP_DIR/extracted" 1>&2
tar -x -C "$TMP_DIR/extracted" -f "$TMP_DIR/archive.tar.gz" --strip-components=1 1>&2
echo "Initialzing temporary git repo..." >&2
git -C "$TMP_DIR/extracted" init 1>&2
git -C "$TMP_DIR/extracted" add . 1>&2
git -C "$TMP_DIR/extracted" commit --no-verify -m "original state" -q 1>&2
echo "Patching build targets..." >&2
find $TMP_DIR/extracted -name BUILD.bazel -or -name BUILD | while read f; do
buildozer 'add features "-layering_check"' $(dirname $f):%cc_library 1>&2 || exit_code=$?
if [[ $exit_code -ne 0 && $exit_code -ne 3 ]]; then
echo "Buildozer command failed with exit code: $exit_code" >&2
exit $exit_code
fi
done
echo "Generating diff..." >&2
git -C "$TMP_DIR/extracted" --no-pager diff