Skip to content

Commit

Permalink
Clean up third-party package build rules
Browse files Browse the repository at this point in the history
Eliminate `template_rule` from `utils.bzl`.  This is now available as
`expand_template` from bazel_skylib.

Eliminate `cc_library_with_strip_include_prefix` from `utils.bzl`.
The Bazel bug (bazelbuild/bazel#6337) is
fixed as of Bazel 5.0.

Replace uses of `genrule` with `write_file` from bazel_skylib.

Eliminate unnecssary `constraint_value` -> `config_setting` aliases,
now that Bazel allows constraint_value targets to be used directly in
`select`.

Updates bazelisk.py to fix deprecation warning:
bazelbuild/bazelisk#379

PiperOrigin-RevId: 478621631
Change-Id: I2e647861a78ee456fd44bc6f23223611162a136f
  • Loading branch information
jbms authored and copybara-github committed Oct 3, 2022
1 parent 086608c commit 4920884
Show file tree
Hide file tree
Showing 28 changed files with 700 additions and 1,050 deletions.
642 changes: 330 additions & 312 deletions bazelisk.py

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions python/tensorstore/pybind11.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""Supports pybind11 extension modules"""

load("//:utils.bzl", "constraint_values_config_setting")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("//python/tensorstore:pybind11_cc_test.bzl", _pybind11_cc_googletest_test = "pybind11_cc_googletest_test")

Expand Down Expand Up @@ -91,7 +90,7 @@ def py_extension(
# On macOS, the linker does not support version scripts. Use
# the `-exported_symbol` option instead to restrict symbol
# visibility.
constraint_values_config_setting(["@platforms//os:macos"]): [
"@platforms//os:macos": [
"-Wl,-exported_symbol",
# On macOS, the symbol starts with an underscore.
"-Wl,_" + exported_symbol,
Expand All @@ -104,7 +103,7 @@ def py_extension(
],
})
cur_deps = cur_deps + select({
constraint_values_config_setting(["@platforms//os:macos"]): [],
"@platforms//os:macos": [],
"//conditions:default": [linker_script_name],
})
native.cc_binary(
Expand All @@ -130,7 +129,7 @@ def py_extension(
native.filegroup(
name = shared_objects_name,
data = select({
constraint_values_config_setting(["@platforms//os:windows"]): [
"@platforms//os:windows": [
":" + cc_binary_pyd_name,
],
"//conditions:default": [":" + cc_binary_so_name],
Expand Down
5 changes: 1 addition & 4 deletions tensorstore/non_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//:utils.bzl", "constraint_values_config_setting")
load("//tensorstore:tensorstore.bzl", "tensorstore_cc_test")

def cc_with_non_compile_test(
Expand All @@ -30,9 +29,7 @@ def cc_with_non_compile_test(
if deps == None:
deps = []

# This should really be detecting the compiler rather than the platform, but
# it is difficult to reliably detect the compiler.
msvc_config_setting = constraint_values_config_setting(["@platforms//os:windows"])
msvc_config_setting = "@com_google_tensorstore//:compiler_msvc"

# This just turns it into a regular test.
tensorstore_cc_test(
Expand Down
4 changes: 2 additions & 2 deletions third_party/bazel_skylib/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def repo():
maybe(
http_archive,
name = "bazel_skylib",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz"],
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz"],
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
)
4 changes: 1 addition & 3 deletions third_party/com_github_nlohmann_json/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
load("@com_google_tensorstore//:utils.bzl", "cc_library_with_strip_include_prefix")

licenses(["notice"])

exports_files(["LICENSE.MIT"])

cc_library_with_strip_include_prefix(
cc_library(
name = "nlohmann_json",
hdrs = glob(["include/**/*.hpp"]),
strip_include_prefix = "include",
Expand Down
4 changes: 1 addition & 3 deletions third_party/com_github_pybind_pybind11/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
load("@com_google_tensorstore//:utils.bzl", "cc_library_with_strip_include_prefix")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

exports_files(["LICENSE"])

cc_library_with_strip_include_prefix(
cc_library(
name = "pybind11",
hdrs = glob(include = ["include/pybind11/**/*.h"]),
strip_include_prefix = "include",
Expand Down
4 changes: 1 addition & 3 deletions third_party/com_google_libyuv/libyuv.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
# The libyuv package provides implementation yuv image conversion, rotation
# and scaling.

load("@com_google_tensorstore//:utils.bzl", "cc_library_with_strip_include_prefix")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

exports_files(["LICENSE"])

cc_library_with_strip_include_prefix(
cc_library(
name = "libyuv",
srcs = glob(
[
Expand Down
14 changes: 7 additions & 7 deletions third_party/com_google_snappy/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@com_google_tensorstore//:utils.bzl", "cc_library_with_strip_include_prefix")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

package(default_visibility = ["//visibility:public"])

Expand All @@ -9,10 +9,10 @@ filegroup(
srcs = ["COPYING"],
)

genrule(
write_file(
name = "configure",
outs = ["snappy-stubs-public.h"],
cmd = """cat <<'EOF' >$@
out = "snappy-stubs-public.h",
content = ["""
// Copyright 2011 Google Inc. All Rights Reserved.
// Author: sesse@google.com (Steinar H. Gunderson)
//
Expand Down Expand Up @@ -111,11 +111,11 @@ struct iovec {
} // namespace snappy

#endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
EOF
""",
"""],
newline = "unix",
)

cc_library_with_strip_include_prefix(
cc_library(
name = "snappy",
srcs = [
"snappy.cc",
Expand Down
Loading

0 comments on commit 4920884

Please sign in to comment.