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
@@ -0,0 +1,323 @@
"""Toolchain configs for cross-compiling TensorFlow"""
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
package(default_visibility = ["//visibility:public"])
licenses(["restricted"])
cc_toolchain_suite(
name = "cross_compile_toolchain_suite",
toolchains = {
"aarch64": ":linux_aarch64_cc_toolchain",
"k8": ":linux_x86_cc_toolchain",
"darwin": ":macos_x86_cc_toolchain",
},
)
filegroup(name = "empty")
# We define a wraper ("cc_wrapper.sh") around the compiler to replace all paths
# in the binary (bazel-out/.../path/to/original/library.so) by the paths
# relative to the binary. Without it, we run into "Library not loaded" error
# when trying run cross-compiled tests, see b/300002682.
filegroup(
name = "cc_wrapper_and_macos_sysroot",
srcs = ["cc_wrapper.sh"] + glob(["MacOSX.sdk/**"]),
)
cc_toolchain(
name = "linux_x86_cc_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":linux_x86_toolchain_config",
toolchain_identifier = "linux_x86_toolchain",
)
cc_toolchain_config(
name = "linux_x86_toolchain_config",
abi_libc_version = "local",
abi_version = "local",
builtin_sysroot = "/dt9",
compile_flags = [
"--target=x86_64-unknown-linux-gnu",
"-fstack-protector",
"-Wall",
"-Wthread-safety",
"-Wself-assign",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fcolor-diagnostics",
"-fno-omit-frame-pointer",
"-mavx",
],
compiler = "clang",
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
cpu = "k8",
cxx_builtin_include_directories = [
"/dt9/",
"/usr/lib/llvm-18/include/",
"/usr/lib/llvm-18/lib/clang/18/include",
],
dbg_compile_flags = ["-g"],
host_system_name = "linux",
link_flags = [
"--target=x86_64-unknown-linux-gnu",
"-fuse-ld=lld",
"--ld-path=/usr/lib/llvm-18/bin/ld.lld",
"-Wl,--undefined-version",
],
link_libs = [
"-lstdc++",
"-lm",
],
opt_compile_flags = [
"-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections",
],
opt_link_flags = ["-Wl,--gc-sections"],
supports_start_end_lib = True,
target_libc = "",
target_system_name = "x86_64-unknown-linux-gnu",
tool_paths = {
"gcc": "/usr/lib/llvm-18/bin/clang",
"ld": "/usr/lib/llvm-18/bin/ld.lld",
"ar": "/usr/lib/llvm-18/bin/llvm-ar",
"cpp": "/usr/lib/llvm-18/bin/clang++",
"llvm-cov": "/usr/lib/llvm-18/bin/llvm-cov",
"nm": "/usr/lib/llvm-18/bin/llvm-nm",
"objdump": "/usr/lib/llvm-18/bin/llvm-objdump",
"strip": "/usr/lib/llvm-18/bin/llvm-strip",
},
toolchain_identifier = "linux_x86_toolchain",
unfiltered_compile_flags = [
"-no-canonical-prefixes",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
"-Wno-unused-command-line-argument",
"-Wno-gnu-offsetof-extensions",
],
)
cc_toolchain(
name = "linux_aarch64_cc_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":linux_aarch64_toolchain_config",
toolchain_identifier = "linux_aarch64_toolchain",
)
cc_toolchain_config(
name = "linux_aarch64_toolchain_config",
abi_libc_version = "local",
abi_version = "local",
builtin_sysroot = "/dt10/",
compile_flags = [
"--target=aarch64-unknown-linux-gnu",
"-fstack-protector",
"-Wall",
"-Wthread-safety",
"-Wself-assign",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fcolor-diagnostics",
"-fno-omit-frame-pointer",
"-mtune=generic",
"-march=armv8-a",
],
compiler = "clang",
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
cpu = "aarch64",
cxx_builtin_include_directories = [
"/dt10/",
"/usr/lib/llvm-18/include/",
"/usr/lib/llvm-18/lib/clang/18/include",
],
dbg_compile_flags = ["-g"],
host_system_name = "linux",
link_flags = [
"--target=aarch64-unknown-linux-gnu",
"-fuse-ld=lld",
"--ld-path=/usr/lib/llvm-18/bin/ld.lld",
"-Wl,--undefined-version",
],
link_libs = [
"-lstdc++",
"-lm",
],
opt_compile_flags = [
"-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections",
],
opt_link_flags = ["-Wl,--gc-sections"],
supports_start_end_lib = True,
target_libc = "",
target_system_name = "aarch64-unknown-linux-gnu",
tool_paths = {
"gcc": "/usr/lib/llvm-18/bin/clang",
"ld": "/usr/lib/llvm-18/bin/ld.lld",
"ar": "/usr/lib/llvm-18/bin/llvm-ar",
"cpp": "/usr/lib/llvm-18/bin/clang++",
"llvm-cov": "/usr/lib/llvm-18/bin/llvm-cov",
"nm": "/usr/lib/llvm-18/bin/llvm-nm",
"objdump": "/usr/lib/llvm-18/bin/llvm-objdump",
"strip": "/usr/lib/llvm-18/bin/llvm-strip",
},
toolchain_identifier = "linux_aarch64_toolchain",
unfiltered_compile_flags = [
"-no-canonical-prefixes",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
"-Wno-unused-command-line-argument",
"-Wno-gnu-offsetof-extensions",
],
)
cc_toolchain(
name = "macos_x86_cc_toolchain",
all_files = ":cc_wrapper_and_macos_sysroot",
compiler_files = ":cc_wrapper_and_macos_sysroot",
dwp_files = ":empty",
linker_files = ":cc_wrapper_and_macos_sysroot",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":macos_x86_toolchain_config",
toolchain_identifier = "macos_x86_toolchain",
)
cc_toolchain_config(
name = "macos_x86_toolchain_config",
abi_libc_version = "darwin_x86_64",
abi_version = "darwin_x86_64",
builtin_sysroot = "tensorflow/tools/toolchains/cross_compile/cc/MacOSX.sdk",
compile_flags = [
"--target=x86_64-apple-darwin",
"-fstack-protector",
"-Wall",
"-Wthread-safety",
"-Wself-assign",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fcolor-diagnostics",
"-fno-omit-frame-pointer",
"-DOS_MACOSX",
"-DGRPC_BAZEL_BUILD",
"-stdlib=libc++",
"-mavx",
# Target Catalina as the minimum supported OS
"-mmacos-version-min=10.15",
],
compiler = "clang",
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
cpu = "darwin",
cxx_builtin_include_directories = [
"%sysroot%/usr/include",
"/usr/lib/llvm-18/include/",
"/usr/lib/llvm-18/lib/clang/18/include",
"%sysroot%/System/Library/Frameworks/Security.framework/Headers",
"%sysroot%/System/Library/Frameworks/CoreFoundation.framework/Headers",
"%sysroot%/System/Library/Frameworks/SystemConfiguration.framework/Headers",
],
dbg_compile_flags = ["-g"],
host_system_name = "linux",
link_flags = [
"--target=x86_64-apple-darwin",
"-lSystem",
"-fuse-ld=lld",
"--ld-path=/usr/lib/llvm-18/bin/ld64.lld",
"-headerpad_max_install_names",
"-Wl,-undefined,dynamic_lookup",
# Target Catalina as the minimum supported OS
"-Wl,-platform_version,macos,10.15.0,10.15",
],
link_libs = [
"-lc++",
"-lm",
],
opt_compile_flags = [
"-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections",
],
opt_link_flags = ["-Wl,-dead_strip"],
supports_start_end_lib = True,
target_libc = "macosx",
target_system_name = "x86_64-apple-macosx10.15",
tool_paths = {
"gcc": "cc_wrapper.sh",
"ld": "/usr/lib/llvm-18/bin/ld64.lld",
"ar": "/usr/lib/llvm-18/bin/llvm-libtool-darwin",
"cpp": "/usr/lib/llvm-18/bin/clang++",
"llvm-cov": "/usr/lib/llvm-18/bin/llvm-cov",
"nm": "/usr/lib/llvm-18/bin/llvm-nm",
"objdump": "/usr/lib/llvm-18/bin/llvm-objdump",
"strip": "/usr/lib/llvm-18/bin/llvm-strip",
},
toolchain_identifier = "macos_x86_toolchain",
unfiltered_compile_flags = [
"-no-canonical-prefixes",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
"-Wno-unused-command-line-argument",
"-Wno-gnu-offsetof-extensions",
],
)
toolchain(
name = "linux_x86_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":linux_x86_cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
toolchain(
name = "linux_aarch64_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
toolchain = ":linux_aarch64_cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,120 @@
#!/bin/bash
#
# Copyright 2015 The Bazel Authors. All rights reserved.
#
# 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.
#
# OS X relpath is not really working. This is a wrapper script around gcc
# to simulate relpath behavior.
#
# This wrapper uses install_name_tool to replace all paths in the binary
# (bazel-out/.../path/to/original/library.so) by the paths relative to
# the binary. It parses the command line to behave as rpath is supposed
# to work.
#
# See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
# on how to set those paths for Mach-O binaries.
#
set -eu
LIBS=
LIB_DIRS=
RPATHS=
OUTPUT=
function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=$opt
elif [[ "$opt" =~ ^-l(.*)$ ]]; then
LIBS="${BASH_REMATCH[1]} $LIBS"
elif [[ "$opt" =~ ^-L(.*)$ ]]; then
LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS"
elif [[ "$opt" =~ ^\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ "$opt" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
}
# let parse the option list
for i in "$@"; do
if [[ "$i" = @* && -r "${i:1}" ]]; then
while IFS= read -r opt
do
parse_option "$opt"
done < "${i:1}" || exit 1
else
parse_option "$i"
fi
done
# Call the C++ compiler
/usr/lib/llvm-18/bin/clang "$@"
function get_library_path() {
for libdir in ${LIB_DIRS}; do
if [ -f ${libdir}/lib$1.so ]; then
echo "${libdir}/lib$1.so"
elif [ -f ${libdir}/lib$1.dylib ]; then
echo "${libdir}/lib$1.dylib"
fi
done
}
# A convenient method to return the actual path even for non symlinks
# and multi-level symlinks, see b/300002682 for more details.
function get_realpath() {
local mangled=$(echo $1 | sed 's/[-_\/a-zA-Z0-9]*_solib_darwin[-_a-zA-Z0-9]*\///g')
if [[ "${mangled:0:3}" = "lib" ]]; then
mangled="${mangled:3}"
fi
if [[ "${mangled:0:2}" = "_U" ]]; then
mangled="${mangled:2}"
fi
local mangled_path=(${mangled//_S/ })
local demangled_path=()
for mangled in ${mangled_path[@]}; do
demangled_path+=(${mangled//_U/_})
done
demangled_path=${demangled_path[@]}
echo "bazel-out/darwin-opt/bin/${demangled_path// //}"
}
# Get the path of a lib inside a tool
function get_otool_path() {
# the lib path is the path of the original lib relative to the workspace
get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|'
}
# Do replacements in the output
for rpath in ${RPATHS}; do
for lib in ${LIBS}; do
unset libname
if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then
libname="lib${lib}.so"
elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then
libname="lib${lib}.dylib"
fi
# ${libname-} --> return $libname if defined, or undefined otherwise. This is to make
# this set -e friendly
if [[ -n "${libname-}" ]]; then
libpath=$(get_library_path ${lib})
if [ -n "${libpath}" ]; then
/usr/lib/llvm-18/bin/llvm-install-name-tool -change $(get_otool_path "${libpath}") \
"@loader_path/${rpath}/${libname}" "${OUTPUT}"
fi
fi
done
done