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
+161
View File
@@ -0,0 +1,161 @@
# Packaging for TensorFlow artifacts other than the Python API (pip whl).
# This includes the C API, Java API, and protocol buffer files.
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load("@xla//xla/tsl/mkl:build_defs.bzl", "if_enable_mkl", "if_mkl")
load("//tensorflow:tensorflow.bzl", "VERSION", "VERSION_MAJOR", "if_macos")
load("//tensorflow/core/platform:build_config_root.bzl", "tf_additional_license_deps")
package(default_visibility = ["//visibility:private"])
pkg_zip(
name = "libtensorflow_proto",
srcs = ["//tensorflow/core:protos_all_proto_srcs"],
strip_prefix = "/external/tsl",
)
# Shared objects that all TensorFlow libraries depend on.
pkg_tar(
name = "common_deps",
srcs = ["//tensorflow:tensorflow_framework"],
symlinks = if_macos(
{
"libtensorflow_framework.dylib": "libtensorflow_framework.%s.dylib" % VERSION_MAJOR,
"libtensorflow_framework.%s.dylib" % VERSION_MAJOR: "libtensorflow_framework.%s.dylib" % VERSION,
},
{
"libtensorflow_framework.so": "libtensorflow_framework.so.%s" % VERSION_MAJOR,
"libtensorflow_framework.so.%s" % VERSION_MAJOR: "libtensorflow_framework.so.%s" % VERSION,
},
),
tags = ["manual"],
)
pkg_tar(
name = "cheaders",
srcs = [
"//tensorflow/c:headers",
],
package_dir = "include/",
# TODO(ddunleavy): Remove `tsl` after TSL move is completed.
remap_paths = {
"external/xla/xla": "xla",
"external/tsl/tsl": "tsl",
},
strip_prefix = ".",
# Mark as "manual" till
# https://github.com/bazelbuild/bazel/issues/2352
# and https://github.com/bazelbuild/bazel/issues/1580
# are resolved, otherwise these rules break when built
# with Python 3.
tags = ["manual"],
)
pkg_tar(
name = "eager_cheaders",
srcs = [
"//tensorflow/c/eager:headers",
],
package_dir = "include/tensorflow/c/eager",
# Mark as "manual" till
# https://github.com/bazelbuild/bazel/issues/2352
# and https://github.com/bazelbuild/bazel/issues/1580
# are resolved, otherwise these rules break when built
# with Python 3.
tags = ["manual"],
)
pkg_tar(
name = "clib",
srcs = ["//tensorflow"],
package_dir = "lib",
symlinks = if_macos(
{
"lib/libtensorflow.dylib": "libtensorflow.%s.dylib" % VERSION_MAJOR,
"lib/libtensorflow.%s.dylib" % VERSION_MAJOR: "libtensorflow.%s.dylib" % VERSION,
},
{
"lib/libtensorflow.so": "libtensorflow.so.%s" % VERSION_MAJOR,
"lib/libtensorflow.so.%s" % VERSION_MAJOR: "libtensorflow.so.%s" % VERSION,
},
),
# Mark as "manual" till
# https://github.com/bazelbuild/bazel/issues/2352
# and https://github.com/bazelbuild/bazel/issues/1580
# are resolved, otherwise these rules break when built
# with Python 3.
tags = ["manual"],
deps = [":common_deps"],
)
pkg_tar(
name = "clicenses",
srcs = [
":THIRD_PARTY_TF_C_LICENSES",
"//:LICENSE",
],
# Mark as "manual" till
# https://github.com/bazelbuild/bazel/issues/2352
# and https://github.com/bazelbuild/bazel/issues/1580
# are resolved, otherwise these rules break when built
# with Python 3.
tags = ["manual"],
)
genrule(
name = "clicenses_generate",
srcs = [
"//third_party/icu/data:LICENSE",
"@curl//:COPYING",
"@ducc//:LICENSE",
"@gemmlowp//:LICENSE",
"@jpegxl//:LICENSE",
"@libjpeg_turbo//:LICENSE.md",
"@llvm-project//llvm:LICENSE.TXT",
"@llvm-project//mlir:LICENSE.TXT",
"@local_config_tensorrt//:LICENSE",
"@org_brotli//:LICENSE",
"@png//:LICENSE",
"@snappy//:COPYING",
"@stablehlo//:LICENSE",
"@tf_runtime//:LICENSE",
"@tsl//:LICENSE",
"@xla//:LICENSE",
"@XNNPACK//:LICENSE",
] + select({
"//tensorflow:android": [],
"//tensorflow:ios": [],
"//tensorflow:linux_s390x": [],
"//tensorflow:windows": [],
"//tensorflow:no_gcp_support": [],
"//conditions:default": [
"@com_github_googlecloudplatform_google_cloud_cpp//:LICENSE",
],
}) + if_cuda([
"@local_config_nccl//:LICENSE",
]) + if_mkl([
"@xla//third_party/mkl_dnn:LICENSE",
]) + if_enable_mkl(["@xla//xla/tsl/mkl:LICENSE"]) + tf_additional_license_deps(),
outs = ["THIRD_PARTY_TF_C_LICENSES"],
cmd = "$(location :concat_licenses.sh) $(SRCS) >$@",
tools = [":concat_licenses.sh"],
)
sh_test(
name = "libtensorflow_test",
size = "small",
srcs = ["libtensorflow_test.sh"],
data = [
"libtensorflow_test.c",
":libtensorflow.tar.gz",
],
# Mark as "manual" till
# https://github.com/bazelbuild/bazel/issues/2352
# and https://github.com/bazelbuild/bazel/issues/1580
# are resolved, otherwise these rules break when built
# with Python 3.
# Till then, this test is explicitly executed when building
# the release by tensorflow/tools/ci_build/builds/libtensorflow.sh
tags = ["manual"],
)
@@ -0,0 +1,24 @@
/* Copyright 2017 The TensorFlow 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.
==============================================================================*/
// Companion source file for libtensorflow_java_test.sh
import org.tensorflow.TensorFlow;
public class LibTensorFlowTest {
public static void main(String[] args) {
System.out.println(TensorFlow.version());
}
}
+32
View File
@@ -0,0 +1,32 @@
Bazel rules to package the TensorFlow APIs in languages other than Python into
archives.
## C library
The TensorFlow [C
API](https://www.tensorflow.org/code/tensorflow/c/c_api.h)
is typically a requirement of TensorFlow APIs in other languages such as
[Go](https://www.tensorflow.org/code/tensorflow/go)
and [Rust](https://github.com/tensorflow/rust).
The following commands:
```sh
bazel test --config opt //tensorflow/tools/lib_package:libtensorflow_test
bazel build --config opt //tensorflow/tools/lib_package:libtensorflow
```
test and produce the archive at
`bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz`, which can be
distributed and installed using something like:
```sh
tar -C /usr/local -xzf libtensorflow.tar.gz
```
## Release
Scripts to build these archives for TensorFlow releases are in
[tensorflow/tools/ci_build/linux](https://www.tensorflow.org/code/tensorflow/tools/ci_build/linux)
and
[tensorflow/tools/ci_build/osx](https://www.tensorflow.org/code/tensorflow/tools/ci_build/osx)
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Copyright 2016 The TensorFlow 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.
# ==============================================================================
#
# Script aimed to combining multiple license files into a single one.
for f in $@
do
echo "--------------------------------------------------------------------------------"
echo "BEGIN LICENSE FOR $f"
echo "--------------------------------------------------------------------------------"
cat $f
echo "--------------------------------------------------------------------------------"
echo "END LICENSE FOR $f"
echo "--------------------------------------------------------------------------------"
done
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Copyright 2016 The TensorFlow 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.
# ==============================================================================
set -ex
# Sanity test for the binary artifacts for the TensorFlow Java API.
# - Unarchive
# - Compile a trivial Java file that exercises the Java API and underlying
# native library.
# - Run it
# Tools needed: java, javac, tar
JAVA="${JAVA}"
JAVAC="${JAVAC}"
TAR="${TAR}"
[ -z "${JAVA}" ] && JAVA="java"
[ -z "${JAVAC}" ] && JAVAC="javac"
[ -z "${TAR}" ] && TAR="tar"
# bazel tests run with ${PWD} set to the root of the bazel workspace
TARFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow_jni.tar.gz"
JAVAFILE="${PWD}/tensorflow/tools/lib_package/LibTensorFlowTest.java"
JARFILE="${PWD}/tensorflow/java/libtensorflow.jar"
cd ${TEST_TMPDIR}
# Extract the archive into a subdirectory 'jni'
mkdir jni
${TAR} -xzf ${TARFILE} -Cjni
# Compile and run the .java file
${JAVAC} -cp ${JARFILE} -d . ${JAVAFILE}
OUTPUT=$(${JAVA} \
-cp "${JARFILE}:." \
-Djava.library.path=jni \
LibTensorFlowTest)
if [ -z "${OUTPUT}" ]
then
echo "Empty output, expecting version number"
exit 1
fi
@@ -0,0 +1,28 @@
/* Copyright 2016 The TensorFlow 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.
==============================================================================*/
// Companion source file for libtensorflow_test.sh
#include <tensorflow/c/c_api.h>
int main() {
TF_Status* s = TF_NewStatus();
TF_SetStatus(s, TF_UNKNOWN, "Some error");
if (TF_GetCode(s) != TF_UNKNOWN) {
return 1;
}
TF_DeleteStatus(s);
return 0;
}
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Copyright 2016 The TensorFlow 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.
# ==============================================================================
set -ex
# Sanity test for the package C-library archive.
# - Unarchive
# - Compile a trivial C file that uses the archive
# - Run it
# Tools needed: A C-compiler and tar
CC="${CC}"
TAR="${TAR}"
[ -z "${CC}" ] && CC="/usr/bin/gcc"
[ -z "${TAR}" ] && TAR="tar"
# bazel tests run with ${PWD} set to the root of the bazel workspace
TARFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow.tar.gz"
CFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow_test.c"
cd ${TEST_TMPDIR}
# Extract the archive into tensorflow/
mkdir tensorflow
${TAR} -xzf ${TARFILE} -Ctensorflow
# Compile the test .c file. Assumes with_framework_lib=True.
${CC} ${CFILE} -Itensorflow/include \
-Itensorflow/include/external/tsl \
-Itensorflow/include/external/xla \
-Ltensorflow/lib \
-ltensorflow_framework \
-ltensorflow \
-oa.out
# Execute it, with the shared library available.
# DYLD_LIBRARY_PATH is used on OS X, LD_LIBRARY_PATH on Linux.
#
# The tests for GPU require CUDA libraries to be accessible, which
# are in DYLD_LIBRARY_PATH in the test harness for OS X.
export DYLD_LIBRARY_PATH=tensorflow/lib:${DYLD_LIBRARY_PATH}
export LD_LIBRARY_PATH=tensorflow/lib:${LD_LIBRARY_PATH}
./a.out