Unverified Commit f91b59c6 authored by thunderfyc's avatar thunderfyc Committed by GitHub
Browse files

Initial checkin of sequence_projection (#9153)



* Initial checkin of sequence_projection

* Fix the path

* Fix paths and deps

* Fix path and deps
Co-authored-by: default avatarLearn2Compress <expander-robot@google.com>
parent 67efd3ab
licenses(["notice"])
exports_files(["LICENSE"])
package(
default_visibility = ["//visibility:public"],
)
cc_library(
name = "icu4c",
srcs = glob(
[
"icu4c/source/common/*.c",
"icu4c/source/common/*.cpp",
"icu4c/source/stubdata/*.cpp",
],
),
hdrs = glob([
"icu4c/source/common/*.h",
]) + glob([
"icu4c/source/common/unicode/*.h",
]),
copts = [
"-DU_COMMON_IMPLEMENTATION",
"-Wno-deprecated-declarations",
],
linkopts = [
"-ldl",
],
)
_CHECK_VERSION = """
PROTOC_VERSION=$$($(location @protobuf_protoc//:protoc_bin) --version \
| cut -d' ' -f2 | sed -e 's/\\./ /g')
PROTOC_VERSION=$$(printf '%d%03d%03d' $${PROTOC_VERSION})
TF_PROTO_VERSION=$$(grep '#define PROTOBUF_MIN_PROTOC_VERSION' \
$(location tf_includes/google/protobuf/port_def.inc) | cut -d' ' -f3)
if [ "$${PROTOC_VERSION}" -ne "$${TF_PROTO_VERSION}" ]; then
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1>&2
echo Your protoc version does not match the tensorflow proto header \
required version: "$${PROTOC_VERSION}" vs. "$${TF_PROTO_VERSION}" 1>&2
echo Please update the PROTOC_VERSION in your WORKSPACE file. 1>&2
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1>&2
false
else
touch $@
fi
"""
genrule(
name = "compare_protobuf_version",
outs = ["versions_compared"],
srcs = [
"tf_includes/google/protobuf/port_def.inc",
],
tools = ["@protobuf_protoc//:protoc_bin"],
cmd = _CHECK_VERSION,
)
cc_library(
name = "includes",
data = [":versions_compared"],
hdrs = glob([
"tf_includes/google/protobuf/*.h",
"tf_includes/google/protobuf/*.inc",
"tf_includes/google/protobuf/**/*.h",
"tf_includes/google/protobuf/**/*.inc",
]),
includes = ["tf_includes"],
visibility = ["//visibility:public"],
)
licenses(["restricted"])
package(default_visibility = ["//visibility:public"])
# Point both runtimes to the same python binary to ensure we always
# use the python binary specified by ./configure.py script.
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
py_runtime(
name = "py2_runtime",
interpreter_path = "%{PYTHON_BIN_PATH}",
python_version = "PY2",
)
py_runtime(
name = "py3_runtime",
interpreter_path = "%{PYTHON_BIN_PATH}",
python_version = "PY3",
)
py_runtime_pair(
name = "py_runtime_pair",
py2_runtime = ":py2_runtime",
py3_runtime = ":py3_runtime",
)
toolchain(
name = "py_toolchain",
toolchain = ":py_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
"""Repository rule for Python autoconfiguration.
`python_configure` depends on the following environment variables:
* `PYTHON_BIN_PATH`: location of python binary.
"""
_PYTHON_BIN_PATH = "PYTHON_BIN_PATH"
def _tpl(repository_ctx, tpl, substitutions = {}, out = None):
if not out:
out = tpl
repository_ctx.template(
out,
Label("//third_party/py:%s.tpl" % tpl),
substitutions,
)
def _fail(msg):
"""Output failure message when auto configuration fails."""
red = "\033[0;31m"
no_color = "\033[0m"
fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg))
def _get_python_bin(repository_ctx):
"""Gets the python bin path."""
python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH)
if python_bin != None:
return python_bin
python_bin_path = repository_ctx.which("python")
if python_bin_path != None:
return str(python_bin_path)
_fail("Cannot find python in PATH, please make sure " +
"python is installed and add its directory in PATH, or --define " +
"%s='/something/else'.\nPATH=%s" % (
_PYTHON_BIN_PATH,
repository_ctx.os.environ.get("PATH", ""),
))
def _create_local_python_repository(repository_ctx):
"""Creates the repository containing files set up to build with Python."""
python_bin = _get_python_bin(repository_ctx)
_tpl(repository_ctx, "BUILD", {
"%{PYTHON_BIN_PATH}": python_bin,
})
def _python_autoconf_impl(repository_ctx):
"""Implementation of the python_autoconf repository rule."""
_create_local_python_repository(repository_ctx)
python_configure = repository_rule(
implementation = _python_autoconf_impl,
environ = [
_PYTHON_BIN_PATH,
],
)
"""Detects and configures the local Python toolchain.
Add the following to your WORKSPACE FILE:
```python
load("//third_party/py:python_configure.bzl", "python_configure")
python_configure(name = "local_config_py_toolchain")
register_toolchains("@local_config_py_toolchain//:py_toolchain")
```
Args:
name: A unique name for this workspace rule.
"""
package(default_visibility = ["//visibility:public"])
cc_library(
name = "pybind11",
hdrs = glob(
include = [
"include/pybind11/*.h",
"include/pybind11/detail/*.h",
],
exclude = [
"include/pybind11/common.h",
"include/pybind11/eigen.h",
],
),
copts = [
"-fexceptions",
"-Wno-undefined-inline",
"-Wno-pragma-once-outside-header",
],
includes = ["include"],
strip_include_prefix = "include",
deps = [
"@org_tensorflow//third_party/python_runtime:headers",
],
)
licenses(["notice"]) # New BSD, Python Software Foundation
package(default_visibility = ["//visibility:public"])
alias(
name = "headers",
actual = "@local_config_python//:python_headers",
)
# Copyright 2020 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.
"""Utilities for defining TensorFlow Lite Support Bazel dependencies."""
_SINGLE_URL_WHITELIST = []
def _is_windows(ctx):
return ctx.os.name.lower().find("windows") != -1
def _wrap_bash_cmd(ctx, cmd):
if _is_windows(ctx):
bazel_sh = _get_env_var(ctx, "BAZEL_SH")
if not bazel_sh:
fail("BAZEL_SH environment variable is not set")
cmd = [bazel_sh, "-l", "-c", " ".join(["\"%s\"" % s for s in cmd])]
return cmd
def _get_env_var(ctx, name):
if name in ctx.os.environ:
return ctx.os.environ[name]
else:
return None
# Checks if we should use the system lib instead of the bundled one
def _use_system_lib(ctx, name):
syslibenv = _get_env_var(ctx, "TF_SYSTEM_LIBS")
if syslibenv:
for n in syslibenv.strip().split(","):
if n.strip() == name:
return True
return False
# Executes specified command with arguments and calls 'fail' if it exited with
# non-zero code
def _execute_and_check_ret_code(repo_ctx, cmd_and_args):
result = repo_ctx.execute(cmd_and_args, timeout = 60)
if result.return_code != 0:
fail(("Non-zero return code({1}) when executing '{0}':\n" + "Stdout: {2}\n" +
"Stderr: {3}").format(
" ".join([str(x) for x in cmd_and_args]),
result.return_code,
result.stdout,
result.stderr,
))
# Apply a patch_file to the repository root directory
# Runs 'patch -p1' on both Windows and Unix.
def _apply_patch(ctx, patch_file):
patch_command = ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)]
cmd = _wrap_bash_cmd(ctx, patch_command)
_execute_and_check_ret_code(ctx, cmd)
def _apply_delete(ctx, paths):
for path in paths:
if path.startswith("/"):
fail("refusing to rm -rf path starting with '/': " + path)
if ".." in path:
fail("refusing to rm -rf path containing '..': " + path)
cmd = _wrap_bash_cmd(ctx, ["rm", "-rf"] + [ctx.path(path) for path in paths])
_execute_and_check_ret_code(ctx, cmd)
def _third_party_http_archive(ctx):
"""Downloads and creates Bazel repos for dependencies.
This is a swappable replacement for both http_archive() and
new_http_archive() that offers some additional features. It also helps
ensure best practices are followed.
"""
if ("mirror.tensorflow.org" not in ctx.attr.urls[0] and
(len(ctx.attr.urls) < 2 and
ctx.attr.name not in _SINGLE_URL_WHITELIST.to_list())):
fail("third_party_http_archive(urls) must have redundant URLs. The " +
"mirror.tensorflow.org URL must be present and it must come first. " +
"Even if you don't have permission to mirror the file, please " +
"put the correctly formatted mirror URL there anyway, because " +
"someone will come along shortly thereafter and mirror the file.")
use_syslib = _use_system_lib(ctx, ctx.attr.name)
# Use "BUILD.bazel" to avoid conflict with third party projects that contain a
# file or directory called "BUILD"
buildfile_path = ctx.path("BUILD.bazel")
if use_syslib:
if ctx.attr.system_build_file == None:
fail("Bazel was configured with TF_SYSTEM_LIBS to use a system " +
"library for %s, but no system build file for %s was configured. " +
"Please add a system_build_file attribute to the repository rule" +
"for %s." % (ctx.attr.name, ctx.attr.name, ctx.attr.name))
ctx.symlink(Label(ctx.attr.system_build_file), buildfile_path)
else:
ctx.download_and_extract(
ctx.attr.urls,
"",
ctx.attr.sha256,
ctx.attr.type,
ctx.attr.strip_prefix,
)
if ctx.attr.delete:
_apply_delete(ctx, ctx.attr.delete)
if ctx.attr.patch_file != None:
_apply_patch(ctx, ctx.attr.patch_file)
ctx.symlink(Label(ctx.attr.build_file), buildfile_path)
link_dict = {}
if use_syslib:
link_dict.update(ctx.attr.system_link_files)
for internal_src, external_dest in ctx.attr.link_files.items():
# if syslib and link exists in both, use the system one
if external_dest not in link_dict.values():
link_dict[internal_src] = external_dest
for internal_src, external_dest in link_dict.items():
ctx.symlink(Label(internal_src), ctx.path(external_dest))
# For link_files, specify each dict entry as:
# "//path/to/source:file": "localfile"
third_party_http_archive = repository_rule(
attrs = {
"sha256": attr.string(mandatory = True),
"urls": attr.string_list(
mandatory = True,
allow_empty = False,
),
"strip_prefix": attr.string(),
"type": attr.string(),
"delete": attr.string_list(),
"build_file": attr.string(mandatory = True),
"system_build_file": attr.string(mandatory = False),
"patch_file": attr.label(),
"link_files": attr.string_dict(),
"system_link_files": attr.string_dict(),
},
environ = [
"TF_SYSTEM_LIBS",
],
implementation = _third_party_http_archive,
)
cc_library(
name = "utf",
srcs = [
"libutf/rune.c",
"libutf/runestrcat.c",
"libutf/runestrchr.c",
"libutf/runestrcmp.c",
"libutf/runestrcpy.c",
"libutf/runestrdup.c",
"libutf/runestrecpy.c",
"libutf/runestrlen.c",
"libutf/runestrncat.c",
"libutf/runestrncmp.c",
"libutf/runestrncpy.c",
"libutf/runestrrchr.c",
"libutf/runestrstr.c",
"libutf/runetype.c",
"libutf/utfecpy.c",
"libutf/utflen.c",
"libutf/utfnlen.c",
"libutf/utfrrune.c",
"libutf/utfrune.c",
"libutf/utfutf.c",
],
hdrs = [
"libutf/utf.h",
"libutf/utfdef.h",
"libutf/plan9.h",
],
includes = [
".",
"libutf",
],
copts = [
"-Wno-parentheses",
],
visibility = ["//visibility:public"],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment