Skip to content

Commit

Permalink
Reorganize upb file structure
Browse files Browse the repository at this point in the history
This change moves almost everything in the `upb/` directory up one level, so
that for example `upb/upb/generated_code_support.h` becomes just
`upb/generated_code_support.h`. The only exceptions I made to this were that I
left `upb/cmake` and `upb/BUILD` where they are, mostly because that avoids
conflict with other files and the current locations seem reasonable for now.

The `python/` directory is a little bit of a challenge because we had to merge
the existing directory there with `upb/python/`. I made `upb/python/BUILD` into
the BUILD file for the merged directory, and it effectively loads the contents
of the other BUILD file via `python/build_targets.bzl`, but I plan to clean
this up soon.

PiperOrigin-RevId: 568651768
  • Loading branch information
acozzette authored and Copybara-Service committed Sep 26, 2023
1 parent 30a7b23 commit 501ecec
Show file tree
Hide file tree
Showing 454 changed files with 1,889 additions and 1,854 deletions.
13 changes: 8 additions & 5 deletions .github/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@
# of Xcode.
xcode_version(
name = "version14_2_14C18",
version = "14.2.14C18",
aliases = ["14C18"],
default_ios_sdk_version = "16.2",
default_tvos_sdk_version = "16.1",
default_macos_sdk_version = "13.1",
default_tvos_sdk_version = "16.1",
default_watchos_sdk_version = "9.1",
version = "14.2.14C18",
)

xcode_version(
name = "version14_1_0_14B47b",
version = "14.1.0.14B47b",
aliases = ["14B47b"],
default_ios_sdk_version = "16.1",
default_tvos_sdk_version = "16.1",
default_macos_sdk_version = "13.0",
default_tvos_sdk_version = "16.1",
default_watchos_sdk_version = "9.1",
version = "14.1.0.14B47b",
)

xcode_config(
name = "host_xcodes",
versions = [":version14_2_14C18", ":version14_1_0_14B47b"],
default = ":version14_1_0_14B47b",
versions = [
":version14_2_14C18",
":version14_1_0_14B47b",
],
)
6 changes: 4 additions & 2 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
version: ["3.8", "3.9", "3.10", "3.11" ]
include:
- type: Pure
targets: //python/... //upb/python/... //python:python_version_test
targets: //python/... //python:python_version_test
flags: --define=use_fast_cpp_protos=false
- type: C++
targets: //python/... //python:python_version_test
Expand All @@ -46,6 +46,7 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }}
bazel: test ${{ matrix.targets }} ${{ matrix.flags }} --test_env=KOKORO_PYTHON_VERSION
exclude-targets: -//python/pb_unit_tests/...


macos:
Expand All @@ -57,7 +58,7 @@ jobs:
version: [ "3.11" ]
include:
- type: Pure
targets: //python/... //upb/python/... //python:python_version_test
targets: //python/... //python:python_version_test
- type: C++
targets: //python/... //python:python_version_test
flags: --define=use_fast_cpp_protos=true
Expand Down Expand Up @@ -95,3 +96,4 @@ jobs:
test ${{ matrix.targets }} ${{ matrix.flags }}
--test_env=KOKORO_PYTHON_VERSION=${{ matrix.version }}
--macos_minimum_os=10.9
exclude-targets: -//python/pb_unit_tests/...
21 changes: 11 additions & 10 deletions .github/workflows/test_upb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
- { 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: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//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 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/... ${{ matrix.config.flags }}
exclude-targets: ${{ matrix.config.exclude-targets }}

linux-gcc:
Expand All @@ -58,7 +58,7 @@ jobs:
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-6.3.0-63dd26c0c7a808d92673a3e52e848189d4ab0f17"
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-gcc"
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //upb/...
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/...

windows:
strategy:
Expand All @@ -75,7 +75,8 @@ 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/... //upbc/... //python/... //protos/... //protos_generator/...
exclude-targets: -//python:conformance_test -//upb:def_builder_test

macos:
strategy:
Expand All @@ -96,7 +97,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 }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/...

no-python:
strategy:
Expand All @@ -118,7 +119,7 @@ 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 //python/... -- -//python/dist:source_wheel
build_wheels:
name: Build Wheels
Expand All @@ -135,7 +136,7 @@ jobs:
image: us-docker.pkg.dev/protobuf-build/release-containers/linux/apple@sha256:b3dc9b75d8e599b0e95ed245d89f44b5a4231112f975da89dd02006a484a58df
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel-python
bazel: build --crosstool_top=//toolchain:clang_suite --//toolchain:release=true --symlink_prefix=/ -c dbg //upb/python/dist //upb/python/dist:test_wheel //upb/python/dist:source_wheel
bazel: build --crosstool_top=//toolchain:clang_suite --//toolchain:release=true --symlink_prefix=/ -c dbg //python/dist //python/dist:test_wheel //python/dist:source_wheel
- name: Move Wheels
run: mkdir wheels && find _build/out \( -name 'protobuf*.whl' -o -name 'protobuf-*.tar.gz' \) -exec mv '{}' wheels ';'
- uses: actions/upload-artifact@v3
Expand All @@ -146,7 +147,7 @@ jobs:
with:
name: requirements
# Tests shouldn't have access to the whole upb repo, upload the one file we need
path: upb/python/requirements.txt
path: python/requirements.txt

test_wheels:
name: Test Wheels
Expand Down
28 changes: 14 additions & 14 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf.

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")

Expand Down Expand Up @@ -153,8 +153,8 @@ filegroup(
internal_ruby_proto_library(
name = "well_known_ruby_protos",
srcs = [":well_known_protos"],
includes = ["src"],
default_runtime = "",
includes = ["src"],
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
Expand Down Expand Up @@ -182,14 +182,14 @@ cc_binary(
cc_binary(
name = "protoc_static",
copts = COPTS,
linkopts = LINK_OPTS,
features = select({
# This isn't possible on mac because there is no static library for lcrt0.o
"@platforms//os:osx": [],
"//build_defs:config_osx": [],
# When cross-compiling we need to statically link all C++ libraries.
"//conditions:default": ["fully_static_link"],
# This isn't possible on mac because there is no static library for lcrt0.o
"@platforms//os:osx": [],
"//build_defs:config_osx": [],
# When cross-compiling we need to statically link all C++ libraries.
"//conditions:default": ["fully_static_link"],
}),
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
)
Expand All @@ -201,9 +201,9 @@ cc_binary(
# Expose the runtime for the proto_lang_toolchain so that it can also be used in
# a user-defined proto_lang_toolchain.
alias(
name = "protobuf_nowkt",
actual = "//src/google/protobuf:protobuf_nowkt",
visibility = ["//visibility:public"],
name = "protobuf_nowkt",
actual = "//src/google/protobuf:protobuf_nowkt",
visibility = ["//visibility:public"],
)

# The "lite" runtime works for .proto files that specify the option:
Expand Down Expand Up @@ -302,13 +302,13 @@ alias(
alias(
name = "python_srcs",
actual = "//python:python_srcs",
visibility = ["//upb:__subpackages__"],
visibility = ["//python:__subpackages__"],
)

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

alias(
Expand Down Expand Up @@ -545,11 +545,11 @@ internal_ruby_proto_library(
# The above must come first.
"src",
],
deps = [":well_known_ruby_protos"],
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
],
deps = [":well_known_ruby_protos"],
)

filegroup(
Expand Down
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ ruby_bundle(
gemfile = "//ruby:Gemfile",
)

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

upb_deps()

http_archive(
name = "lua",
build_file = "//upb/bazel:lua.BUILD",
build_file = "//bazel:lua.BUILD",
sha256 = "b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b",
strip_prefix = "lua-5.2.4",
urls = [
Expand All @@ -134,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 = "//benchmarks:BUILD.googleapis",
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
)

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

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

pip_parse(
name = "pip_deps",
requirements = "//upb/python:requirements.txt",
requirements = "//python:requirements.txt",
)

load("@pip_deps//:requirements.bzl", "install_deps")
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion upb/bazel/amalgamation.bzl → bazel/amalgamation.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ upb_amalgamation = rule(
"_amalgamator": attr.label(
executable = True,
cfg = "exec",
default = "//upb/bazel:amalgamate",
default = "//bazel:amalgamate",
),
"prefix": attr.string(
default = "",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions upb/bazel/python_downloads.bzl → bazel/python_downloads.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ cc_import(
hdrs = glob(["**/*.h"]),
shared_library = "python{0}.dll",
interface_library = "libs/python{0}.lib",
visibility = ["@com_google_protobuf//upb/python:__pkg__"],
visibility = ["@com_google_protobuf//python:__pkg__"],
)
cc_import(
name = "python_limited_api",
hdrs = glob(["**/*.h"]),
shared_library = "python{1}.dll",
interface_library = "libs/python{1}.lib",
visibility = ["@com_google_protobuf//upb/python:__pkg__"],
visibility = ["@com_google_protobuf//python:__pkg__"],
)
"""

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""upb_c_proto_library() exposes upb's generated C API for protobuf (foo.upb.h)"""

load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
load("//upb/bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//upb/bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//upb/bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
load("//bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")

UpbWrappedCcInfo = provider(
"Provider for cc_info for protos",
Expand Down Expand Up @@ -34,7 +34,7 @@ upb_c_proto_library_aspect = aspect(
"_gen_upb": attr.label(
executable = True,
cfg = "exec",
default = "//upb/upbc:protoc-gen-upb_stage1",
default = "//upbc:protoc-gen-upb_stage1",
),
"_protoc": attr.label(
executable = True,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)"""

load("//upb/bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//upb/bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//upb/bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
load("//bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")

UpbMinitableCcInfo = provider(
"Provider for cc_info for protos",
Expand Down Expand Up @@ -46,7 +46,7 @@ upb_minitable_proto_library_aspect = aspect(
"_gen_upb_minitable": attr.label(
executable = True,
cfg = "exec",
default = "//upb/upbc:protoc-gen-upb_minitable_stage1",
default = "//upbc:protoc-gen-upb_minitable_stage1",
),
"_protoc": attr.label(
executable = True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
"""

load(
"//upb/bazel:upb_c_proto_library.bzl",
"//bazel:upb_c_proto_library.bzl",
_UpbWrappedCcInfo = "UpbWrappedCcInfo",
_upb_c_proto_library = "upb_c_proto_library",
_upb_c_proto_library_aspect = "upb_c_proto_library_aspect",
)
load(
"//upb/bazel:upb_proto_library_internal/aspect.bzl",
"//bazel:upb_proto_library_internal/aspect.bzl",
_GeneratedSrcsInfo = "GeneratedSrcsInfo",
)
load(
"//upb/bazel:upb_proto_reflection_library.bzl",
"//bazel:upb_proto_reflection_library.bzl",
_upb_proto_reflection_library = "upb_proto_reflection_library",
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Implementation of the aspect that powers the upb_*_proto_library() rules."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("//upb/bazel:upb_proto_library_internal/cc_library_func.bzl", "cc_library_func")
load("//upb/bazel:upb_proto_library_internal/copts.bzl", "UpbProtoLibraryCoptsInfo")
load("//bazel:upb_proto_library_internal/cc_library_func.bzl", "cc_library_func")
load("//bazel:upb_proto_library_internal/copts.bzl", "UpbProtoLibraryCoptsInfo")

# begin:github_only
_is_google3 = False
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""upb_c_proto_reflection_library() exposes upb reflection for protobuf (foo.upbdefs.h)"""

load("//upb/bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
load("//upb/bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//upb/bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//upb/bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")
load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")
load("//bazel:upb_proto_library_internal/aspect.bzl", "upb_proto_aspect_impl")
load("//bazel:upb_proto_library_internal/cc_library_func.bzl", "upb_use_cpp_toolchain")
load("//bazel:upb_proto_library_internal/rule.bzl", "upb_proto_rule_impl")

_UpbDefsWrappedCcInfo = provider("Provider for cc_info for protos", fields = ["cc_info"])

Expand Down Expand Up @@ -31,7 +31,7 @@ _upb_proto_reflection_library_aspect = aspect(
"_gen_upbdefs": attr.label(
executable = True,
cfg = "exec",
default = "//upb/upbc:protoc-gen-upbdefs",
default = "//upbc:protoc-gen-upbdefs",
),
"_protoc": attr.label(
executable = True,
Expand Down
2 changes: 1 addition & 1 deletion upb/bazel/workspace_deps.bzl → bazel/workspace_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//upb/bazel:python_downloads.bzl", "python_nuget_package", "python_source_archive")
load("//bazel:python_downloads.bzl", "python_nuget_package", "python_source_archive")

def _github_archive(repo, commit, **kwargs):
repo_name = repo.split("/")[-1]
Expand Down

0 comments on commit 501ecec

Please sign in to comment.