|
|
|
# Copyright (c) 2009-2021, Google LLC
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file or at
|
|
|
|
# https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
|
|
|
|
load(
|
|
|
|
"//upb/bazel:build_defs.bzl",
|
|
|
|
"make_shell_script",
|
|
|
|
)
|
|
|
|
load(
|
|
|
|
":build_defs.bzl",
|
|
|
|
"staleness_test",
|
|
|
|
)
|
|
|
|
|
|
|
|
licenses(["notice"])
|
|
|
|
|
|
|
|
exports_files(["staleness_test.py"])
|
|
|
|
|
|
|
|
py_library(
|
|
|
|
name = "staleness_test_lib",
|
|
|
|
testonly = 1,
|
|
|
|
srcs = ["staleness_test_lib.py"],
|
|
|
|
# This is public only for use by the staleness_test() macro. Please do not
|
|
|
|
# depend on this target directly.
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
|
|
|
|
|
|
|
py_binary(
|
|
|
|
name = "make_cmakelists",
|
|
|
|
srcs = ["make_cmakelists.py"],
|
|
|
|
)
|
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = "gen_cmakelists",
|
|
|
|
srcs = [
|
|
|
|
"//upb:BUILD",
|
|
|
|
],
|
|
|
|
outs = ["generated-in/CMakeLists.txt"],
|
|
|
|
cmd = "$(location :make_cmakelists) " +
|
|
|
|
"$(location //upb:BUILD) $@",
|
|
|
|
tools = [":make_cmakelists"],
|
|
|
|
)
|
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = "copy_protos",
|
|
|
|
srcs = [
|
Fixed layering check violations once and for all in upb bootstrapping.
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
4 months ago
|
|
|
"//src/google/protobuf:descriptor_upb_c_proto",
|
|
|
|
"//src/google/protobuf:descriptor_upb_minitable_proto",
|
|
|
|
],
|
|
|
|
outs = [
|
|
|
|
"generated-in/google/protobuf/descriptor.upb.h",
|
|
|
|
"generated-in/google/protobuf/descriptor.upb_minitable.c",
|
|
|
|
"generated-in/google/protobuf/descriptor.upb_minitable.h",
|
|
|
|
],
|
|
|
|
cmd = "cp $(SRCS) $(@D)/generated-in/google/protobuf",
|
|
|
|
)
|
|
|
|
|
|
|
|
staleness_test(
|
|
|
|
name = "test_generated_files",
|
|
|
|
outs = [
|
|
|
|
"CMakeLists.txt",
|
|
|
|
"google/protobuf/descriptor.upb.h",
|
|
|
|
"google/protobuf/descriptor.upb_minitable.c",
|
|
|
|
"google/protobuf/descriptor.upb_minitable.h",
|
|
|
|
],
|
|
|
|
generated_pattern = "generated-in/%s",
|
|
|
|
tags = ["manual"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Test the CMake build #########################################################
|
|
|
|
|
|
|
|
make_shell_script(
|
|
|
|
name = "gen_run_cmake_build",
|
|
|
|
out = "run_cmake_build.sh",
|
|
|
|
contents = "set -ex\n" +
|
|
|
|
"cd $(dirname $1) && cp -r . .. && cd ../..\n" +
|
|
|
|
"mkdir build && cd build && cmake ../cmake && make -j8 && make test",
|
|
|
|
)
|
|
|
|
|
|
|
|
sh_test(
|
|
|
|
name = "cmake_build",
|
|
|
|
srcs = ["run_cmake_build.sh"],
|
|
|
|
args = ["$(location :gen_cmakelists)"],
|
|
|
|
data = [
|
|
|
|
":copy_protos",
|
|
|
|
":gen_cmakelists",
|
|
|
|
"//third_party/utf8_range:utf8_range_srcs",
|
|
|
|
"//upb:source_files",
|
|
|
|
"//upb/base:source_files",
|
|
|
|
"//upb/hash:source_files",
|
|
|
|
"//upb/lex:source_files",
|
|
|
|
"//upb/mem:source_files",
|
|
|
|
"//upb/message:source_files",
|
|
|
|
"//upb/mini_descriptor:source_files",
|
|
|
|
"//upb/mini_table:source_files",
|
|
|
|
"//upb/port:source_files",
|
|
|
|
"//upb/reflection:source_files",
|
|
|
|
"//upb/text:source_files",
|
|
|
|
"//upb/wire:source_files",
|
|
|
|
],
|
|
|
|
target_compatible_with = select({
|
|
|
|
"@platforms//os:windows": ["@platforms//:incompatible"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
|
|
|
)
|
|
|
|
|
|
|
|
pkg_files(
|
|
|
|
name = "upb_cmake_dist",
|
|
|
|
srcs = [
|
|
|
|
":copy_protos",
|
|
|
|
":gen_cmakelists",
|
|
|
|
"//third_party/utf8_range:utf8_range_srcs",
|
|
|
|
"//upb:source_files",
|
|
|
|
"//upb/base:source_files",
|
|
|
|
"//upb/hash:source_files",
|
|
|
|
"//upb/lex:source_files",
|
|
|
|
"//upb/mem:source_files",
|
|
|
|
"//upb/message:source_files",
|
|
|
|
"//upb/mini_descriptor:source_files",
|
|
|
|
"//upb/mini_table:source_files",
|
|
|
|
"//upb/port:source_files",
|
|
|
|
"//upb/reflection:source_files",
|
|
|
|
"//upb/text:source_files",
|
|
|
|
"//upb/wire:source_files",
|
|
|
|
],
|
|
|
|
strip_prefix = strip_prefix.from_root(""),
|
|
|
|
visibility = ["//rust:__pkg__"],
|
|
|
|
)
|