Skip to content

Commit

Permalink
Merge the protobuf and upb Bazel repos
Browse files Browse the repository at this point in the history
A couple weeks ago we moved upb into the protobuf Git repo, and this change
continues the merger of the two repos by making them into a single Bazel repo.
This was mostly a matter of deleting upb's WORKSPACE file and fixing up a bunch
of references to reflect the new structure.

Most of the changes are pretty mechanical, but one thing that needed more
invasive changes was the Python script for generating CMakeLists.txt,
make_cmakelists.py. The WORKSPACE file it relied on no longer exists with this
change, so I updated it to hardcode the information it needed from that file.

PiperOrigin-RevId: 564810016
  • Loading branch information
acozzette authored and Copybara-Service committed Sep 12, 2023
1 parent f175757 commit 7286ffc
Show file tree
Hide file tree
Showing 341 changed files with 1,978 additions and 2,170 deletions.
2 changes: 0 additions & 2 deletions .bazelignore
@@ -1,6 +1,4 @@
# These are fetched as external repositories.
third_party/abseil-cpp
third_party/googletest
# upb is its own Bazel repository for now.
upb/
_build/
4 changes: 2 additions & 2 deletions .github/workflows/test_python.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
version: [ "3.7", "3.8", "3.9", "3.10" ]
include:
- type: Pure
targets: //python/... @upb//python/... //python:python_version
targets: //python/... //upb/python/... //python:python_version
flags: --define=use_fast_cpp_protos=false
- type: C++
targets: //python/... //python:python_version
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
version: [ "3.10" ]
include:
- type: Pure
targets: //python/... @upb//python/... //python:python_version
targets: //python/... //upb/python/... //python:python_version
- type: C++
targets: //python/... //python:python_version
flags: --define=use_fast_cpp_protos=true
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/test_upb.yml
Expand Up @@ -19,10 +19,10 @@ jobs:
config:
- { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt" }
- { name: "FastTable", flags: "--@upb//:fasttable_enabled=true" }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-@upb//benchmarks:benchmark -@upb//python/..." }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-@upb//benchmarks:benchmark -@upb//python/... -@upb//lua/..." }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-@upb//benchmarks:benchmark -@upb//python/..." }
- { name: "FastTable", flags: "--//upb:fasttable_enabled=true" }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//upb/benchmarks:benchmark -//upb/python/..." }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//upb/benchmarks:benchmark -//upb/python/... -//upb/lua/..." }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//upb/benchmarks:benchmark -//upb/python/..." }
# TODO: b/297027295 - Add 32-bit ASAN test

name: ${{ matrix.config.name }}
Expand All @@ -39,7 +39,7 @@ jobs:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 @upb//... ${{ matrix.config.flags }}
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //upb/... ${{ matrix.config.flags }}
exclude-targets: ${{ matrix.config.exclude-targets }}

linux-gcc:
Expand All @@ -58,12 +58,7 @@ jobs:
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-6.3.0-518b4fcd8d0ded2484c94f02e835526cacfdac2d"
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-gcc"
# The other test runs use the protobuf workspace. For this one let's
# cd into upb and use its workspace instead, to make sure we cover
# that use case.
bash: >-
cd upb &&
bazel test $BAZEL_FLAGS --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //...
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //upb/...

windows:
strategy:
Expand All @@ -80,7 +75,7 @@ jobs:
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-windows"
bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 @upb//upb/... @upb//upbc/... @upb//python/... @upb//protos/... @upb//protos_generator/...
bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/upb/... //upb/upbc/... //upb/python/... //upb/protos/... //upb/protos_generator/...

macos:
strategy:
Expand All @@ -101,7 +96,7 @@ jobs:
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-macos"
bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} @upb//...
bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //upb/...

no-python:
strategy:
Expand All @@ -123,4 +118,4 @@ jobs:
which python3 &&
mv `which python3` /tmp &&
! which python3 &&
bazel test $BAZEL_FLAGS --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 @upb//python/... -- -@upb//python/dist:source_wheel
bazel test $BAZEL_FLAGS --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //upb/python/... -- -//upb/python/dist:source_wheel
4 changes: 2 additions & 2 deletions BUILD.bazel
Expand Up @@ -294,13 +294,13 @@ alias(
alias(
name = "python_srcs",
actual = "//python:python_srcs",
visibility = ["@upb//:__subpackages__"],
visibility = ["//upb:__subpackages__"],
)

alias(
name = "python_test_srcs",
actual = "//python:python_test_srcs",
visibility = ["@upb//:__subpackages__"],
visibility = ["//upb:__subpackages__"],
)

alias(
Expand Down
21 changes: 6 additions & 15 deletions WORKSPACE
Expand Up @@ -7,15 +7,6 @@ local_repository(
path = "examples",
)

# We will soon merge upb and protobuf into the same Bazel repository, but for
# now we depend on the separate Bazel repo in the upb/ directory. This is
# important to ensure that the CI tests exercise upb at head instead of relying
# on a stale version from protobuf_deps.bzl.
local_repository(
name = "upb",
path = "upb",
)

# Load common dependencies first to ensure we use the correct version
load("//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps")

Expand Down Expand Up @@ -116,13 +107,13 @@ ruby_bundle(
gemfile = "//ruby:Gemfile",
)

load("@upb//bazel:workspace_deps.bzl", "upb_deps")
load("//upb/bazel:workspace_deps.bzl", "upb_deps")

upb_deps()

http_archive(
name = "lua",
build_file = "@upb//bazel:lua.BUILD",
build_file = "//upb/bazel:lua.BUILD",
sha256 = "b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b",
strip_prefix = "lua-5.2.4",
urls = [
Expand All @@ -143,11 +134,11 @@ http_archive(
urls = ["https://github.com/googleapis/googleapis/archive/30ed2662a85403cbdeb9ea38df1e414a2a276b83.zip"],
strip_prefix = "googleapis-30ed2662a85403cbdeb9ea38df1e414a2a276b83",
sha256 = "4dfc28101127d22abd6f0f6308d915d490c4594c0cfcf7643769c446d6763a46",
build_file = "@upb//benchmarks:BUILD.googleapis",
build_file = "//upb/benchmarks:BUILD.googleapis",
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
)

load("@upb//bazel:system_python.bzl", "system_python")
load("//upb/bazel:system_python.bzl", "system_python")

system_python(
name = "system_python",
Expand All @@ -158,9 +149,9 @@ load("@system_python//:pip.bzl", "pip_parse")

pip_parse(
name = "pip_deps",
requirements = "@upb//python:requirements.txt",
requirements = "//upb/python:requirements.txt",
requirements_overrides = {
"3.11": "@upb//python:requirements_311.txt",
"3.11": "//upb/python:requirements_311.txt",
},
)

Expand Down
2 changes: 1 addition & 1 deletion objectivec/BUILD.bazel
@@ -1,6 +1,6 @@
load("@rules_cc//cc:defs.bzl", "objc_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//upb/cmake:build_defs.bzl", "staleness_test")
load("//conformance:defs.bzl", "conformance_test")
load(":defs.bzl", "objc_proto_camel_case_name")

Expand Down
6 changes: 3 additions & 3 deletions php/BUILD.bazel
Expand Up @@ -4,7 +4,7 @@

load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//upb/cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION", "PROTOC_VERSION")
Expand Down Expand Up @@ -85,14 +85,14 @@ conformance_test(

genrule(
name = "copy_php_amalgamation_h",
srcs = ["@upb//:php-upb.h"],
srcs = ["//upb:php-upb.h"],
outs = ["generated-in/ext/google/protobuf/php-upb.h"],
cmd = "cp $< $@",
)

genrule(
name = "copy_php_amalgamation_c",
srcs = ["@upb//:php-upb.c"],
srcs = ["//upb:php-upb.c"],
outs = ["generated-in/ext/google/protobuf/php-upb.c"],
cmd = "cp $< $@",
)
Expand Down
8 changes: 4 additions & 4 deletions python/BUILD.bazel
Expand Up @@ -46,7 +46,7 @@ internal_py_proto_library(
srcs_version = "PY2AND3",
visibility = [
"//:__pkg__",
"@upb//:__subpackages__",
"//upb:__subpackages__",
],
)

Expand Down Expand Up @@ -152,7 +152,7 @@ py_library(
srcs_version = "PY2AND3",
visibility = [
"//:__pkg__",
"@upb//:__subpackages__",
"//upb:__subpackages__",
],
)

Expand All @@ -170,7 +170,7 @@ py_library(
srcs_version = "PY3",
visibility = [
"//:__pkg__",
"@upb//:__subpackages__",
"//upb:__subpackages__",
],
)

Expand Down Expand Up @@ -437,7 +437,7 @@ pkg_files(
"tox.ini",
],
strip_prefix = "",
visibility = ["@upb//:__subpackages__"],
visibility = ["//upb:__subpackages__"],
)

pkg_files(
Expand Down
6 changes: 3 additions & 3 deletions python/README.md
Expand Up @@ -21,8 +21,8 @@ If for some reason you wish to build the packages directly from this repo, you
can use the following Bazel commands:

```
$ bazel build @upb//python/dist:source_wheel
$ bazel build @upb//python/dist:binary_wheel
$ bazel build //upb/python/dist:source_wheel
$ bazel build //upb/python/dist:binary_wheel
```

The binary wheel will build against whatever version of Python is installed on
Expand All @@ -49,7 +49,7 @@ following values:
better performance than any of the previous backends, and it is now the
default. It is distributed in our PyPI packages, and requires no special
installation. The code for this module lives in
[@upb/python](https://github.com/protocolbuffers/upb/tree/main/python).
[upb/python](https://github.com/protocolbuffers/protobuf/tree/main/upb/python).
1. **cpp**: This extension module wraps the C++ protobuf library. It is
deprecated and is no longer released in our PyPI packages, however it is
still used in some legacy cases where apps want to perform zero-copy message
Expand Down
2 changes: 1 addition & 1 deletion python/google/protobuf/internal/numpy/BUILD.bazel
Expand Up @@ -18,6 +18,6 @@ internal_py_test(
],
visibility = [
"//python:__pkg__",
"@upb//python/pb_unit_tests:__pkg__",
"//upb/python/pb_unit_tests:__pkg__",
]
)
2 changes: 1 addition & 1 deletion regenerate_stale_files.sh
Expand Up @@ -18,7 +18,7 @@ ${BazelBin} test src/google/protobuf:well_known_types_staleness_test "$@" || ./b
${BazelBin} test objectivec:well_known_types_staleness_test "$@" || ./bazel-bin/objectivec/well_known_types_staleness_test --fix
${BazelBin} test php:test_amalgamation_staleness "$@" || ./bazel-bin/php/test_amalgamation_staleness --fix
${BazelBin} test ruby/ext/google/protobuf_c:test_amalgamation_staleness "$@" || ./bazel-bin/ruby/ext/google/protobuf_c/test_amalgamation_staleness --fix
(cd upb; ${BazelBin} test cmake:test_generated_files "$@" || ./bazel-bin/cmake/test_generated_files --fix)
${BazelBin} test upb/cmake:test_generated_files "$@" || ./bazel-bin/upb/cmake/test_generated_files --fix

# Generate C# code.
# This doesn't currently have Bazel staleness tests, but there's an existing
Expand Down
8 changes: 4 additions & 4 deletions ruby/ext/google/protobuf_c/BUILD.bazel
@@ -1,6 +1,6 @@
load("@build_bazel_rules_apple//apple:apple_binary.bzl", "apple_binary")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//upb/cmake:build_defs.bzl", "staleness_test")

package(default_visibility = ["//ruby:__subpackages__"])

Expand Down Expand Up @@ -31,7 +31,7 @@ genrule(
name = "copy_sources",
srcs = PROTOBUF_C_SOURCES + [
"glue.c",
"@upb//:gen_ruby_amalgamation",
"//upb:gen_ruby_amalgamation",
],
outs = ["copy/%s" % src for src in PROTOBUF_C_SOURCES] + [
"copy/glue.c",
Expand Down Expand Up @@ -155,14 +155,14 @@ pkg_files(

genrule(
name = "copy_ruby_amalgamation_h",
srcs = ["@upb//:ruby-upb.h"],
srcs = ["//upb:ruby-upb.h"],
outs = ["generated-in/ruby-upb.h"],
cmd = "cp $< $@",
)

genrule(
name = "copy_ruby_amalgamation_c",
srcs = ["@upb//:ruby-upb.c"],
srcs = ["//upb:ruby-upb.c"],
outs = ["generated-in/ruby-upb.c"],
cmd = "cp $< $@",
)
Expand Down
2 changes: 1 addition & 1 deletion rust/aspects.bzl
Expand Up @@ -9,7 +9,7 @@ load("@rules_rust//rust/private:providers.bzl", "CrateInfo", "DepInfo", "DepVari
# buildifier: disable=bzl-visibility
load("@rules_rust//rust/private:rustc.bzl", "rustc_compile_action")
load("@rules_rust//rust:defs.bzl", "rust_common")
load("@upb//bazel:upb_proto_library.bzl", "UpbWrappedCcInfo", "upb_proto_library_aspect")
load("//upb/bazel:upb_proto_library.bzl", "UpbWrappedCcInfo", "upb_proto_library_aspect")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

proto_common = proto_common_do_not_use
Expand Down
2 changes: 1 addition & 1 deletion rust/upb_kernel/BUILD
Expand Up @@ -8,6 +8,6 @@ cc_library(
"//rust:__subpackages__",
],
deps = [
"@upb//:upb",
"//upb",
],
)
2 changes: 1 addition & 1 deletion rust/upb_kernel/upb_api.c
Expand Up @@ -8,4 +8,4 @@

#define UPB_BUILD_API

#include "upb/mem/arena.h" // IWYU pragma: keep
#include "upb/upb/mem/arena.h" // IWYU pragma: keep
2 changes: 1 addition & 1 deletion src/BUILD.bazel
Expand Up @@ -4,7 +4,7 @@

# Most rules are under google/protobuf. This package exists for convenience.
load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//upb/cmake:build_defs.bzl", "staleness_test")
load("//conformance:defs.bzl", "conformance_test")

pkg_files(
Expand Down
7 changes: 3 additions & 4 deletions src/google/protobuf/BUILD.bazel
Expand Up @@ -5,7 +5,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//upb/cmake:build_defs.bzl", "staleness_test")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")

package(
Expand Down Expand Up @@ -636,7 +636,6 @@ filegroup(
],
visibility = [
"//:__subpackages__",
"@upb//:__subpackages__",
],
)

Expand Down Expand Up @@ -786,7 +785,7 @@ proto_library(
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
"@upb//:__subpackages__",
"//upb:__subpackages__",
],
)

Expand All @@ -797,7 +796,7 @@ proto_library(
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
"@upb//:__subpackages__",
"//upb:__subpackages__",
],
deps = [
":any_proto",
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/BUILD.bazel
Expand Up @@ -200,7 +200,7 @@ filegroup(
filegroup(
name = "plugin_proto_src",
srcs = ["plugin.proto"],
visibility = ["@upb//:__subpackages__"],
visibility = ["//upb:__subpackages__"],
)

exports_files(
Expand Down

0 comments on commit 7286ffc

Please sign in to comment.