Commit Graph

77 Commits (main)

Author SHA1 Message Date
Joshua Haberman 8e3e09937e Refactored the Java generator into separate packages and targets.
PiperOrigin-RevId: 626057584
2024-04-18 09:33:28 -07:00
Sandy Zhang 6483c4755d Update protoc release to include editions language features protos for Java and C++
Fixes https://github.com/protocolbuffers/protobuf/issues/16211

PiperOrigin-RevId: 618954029
2024-03-25 14:11:11 -07:00
Protobuf Team Bot 87b1c592a3 Move the IfnDefGuard from third_party/protobuf/io/cpp_utils to the existing third_party/protobuf/compiler/cpp, which is a more logical location.
PiperOrigin-RevId: 618485105
2024-03-23 12:54:56 -07:00
Protobuf Team Bot 1087274e7d Add an RAII ifndef helper for C++ codegen.
This can be used in headers to automatically generate ifdef guards.

PiperOrigin-RevId: 618204633
2024-03-22 09:40:16 -07:00
Mike Kruskal 6898451f5e Setup upb installation with cmake.
This installs a upb's static library, headers, and three protoc plugin binaries (upb, upbdefs, upb_minitable).  These will now be enabled by default, but can be disabled by setting protobuf_BUILD_LIBUPB=OFF.

To qualify this, we hook into our existing install test infrastructure which attempts to build and run our tests without any of the installation artifacts available from the source tree.  Public headers are deleted, and builds of exported libraries/binaries are disabled.

PiperOrigin-RevId: 617376961
2024-03-19 20:17:58 -07:00
Mike Kruskal b6032d72e3 Add basic upb cmake support.
libupb will always be statically linked, and currently doesn't ever install itself.

PiperOrigin-RevId: 615136389
2024-03-12 12:43:16 -07:00
aiuto 3ab1276bbb Update Bazel references to rules_pkg to the supported file locations. (#15780)
WIP:  I want to see this pass CI first.

Fixes: #15779

3 scripted transforms:
```
  -load("@rules_pkg//:mappings.bzl", ...)
  +load("@rules_pkg//pkg:mappings.bzl", ...)
```
```
  -load("@rules_pkg//:pkg.bzl", "pkg_tar")
  +load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
```
```
  -load("@rules_pkg//:pkg.bzl", "pkg_zip")
  +load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
```

Closes #15780

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15780 from aiuto:rules_pkg a630276341
PiperOrigin-RevId: 606641398
2024-02-13 09:08:42 -08:00
Adam Cozzette 220548f30c Add missing alias targets for C++ util libraries
Until recently, these targets were dependencies of `//:protobuf` and could thus
be accessed through that target. But now that we are adhering to the layering
check, we need to provide proper access in a way that respects that check. This
change uses top-level alias targets following the existing pattern.

PiperOrigin-RevId: 605123979
2024-02-07 15:57:49 -08:00
Marcel Hlopko 6860c38119 Read crate mapping in protoc
This enables us to get the correct crate names for Rust gencode.

PiperOrigin-RevId: 597850176
2024-01-12 08:48:11 -08:00
Mike Kruskal 93b219f4e8 Remove edition getter from C++ descriptor APIs
PiperOrigin-RevId: 597686725
2024-01-11 16:48:20 -08:00
Adam Cozzette a7b0421c78 Breaking change: make protobuf comply with the C++ layering check
This check enforces that each C++ build target has the correct dependencies for
all headers that it includes. We have many targets that were not correct with
respect to this check, so I fixed them up.

I also cleaned up the C++ targets related to the well-known types. I created a
cc_proto_library() target for each one and removed the :wkt_cc_protos target,
since this was necessary to satisfy the layering check. I deleted the
//src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt,
because the distinction between the :protobuf and :protobuf_nowkt targets was
not really correct. Neither one exposed the headers for the well-known types in
a way that was valid with respect to the layering check, and the idea of
bundling all the well-known types together is not idiomatic in Bazel anyway.
This is a breaking change, because the //:protobuf target no longer bundles the
well-known types. From now on they should be accessed through the new
//:*_cc_proto aliases in our top-level package.

I renamed the :port_def target to :port, which simplifies things a bit by
matching our internal name.

The original motivation for this change was that to move utf8_range onto our CI
infrastructure, we needed to make its dependency rules_fuzzing compatible with
Bazel 6. The rules_fuzzing project builds with the layering check, and I found
that the process of upgrading it to Bazel 6 made it take a dependency on
protobuf, which caused it to break due to layering violations. I was able to
work around this, but it would still be nice to comply with the layering check
so that we don't have to worry about this kind of thing in the future.

PiperOrigin-RevId: 595516736
2024-01-03 15:20:05 -08:00
Protobuf Team Bot 454a780602 Internal change.
PiperOrigin-RevId: 586452605
2023-11-29 21:23:02 -08:00
Adam Cozzette 5ca84008fc Move utf8_range into the protobuf repo
This makes third_party/utf8_range no longer a Git subtree, but instead the
permanent location and source of truth for utf8_range. It is also now
incorporated into the @com_google_protobuf Bazel repo. Utf8_range still has its
own separate CMake build for now, though.

PiperOrigin-RevId: 580682733
2023-11-08 15:43:35 -08:00
Adam Cozzette 77aa913e68 Update `cc_file_list_aspect` to handle targets with missing `hdrs/textual_hdrs`
Our stale file regeneration logic broke with Bazel 6.4.0, and I suspect it was
caused by this change: https://github.com/bazelbuild/bazel/pull/19534 Our logic
assumed that any target with a `CcInfo` provider must have `hdrs` and
`textual_hdrs` attributes, but it seems that this is no longer true for
`cc_proto_library` starting with Bazel 6.4.0. The fix is just to use `getattr`
and treat the item as an empty list if it's missing.

PiperOrigin-RevId: 575473886
2023-10-21 09:40:32 -07:00
Sandy Zhang 6889aed460 Check-in bootstrapped Java features for Bazel and CMake
PiperOrigin-RevId: 573014410
2023-10-12 14:36:01 -07:00
Adam Cozzette 501ececd39 Reorganize upb file structure
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
2023-09-26 14:38:35 -07:00
Joshua Haberman db20f5ffc9 Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full.
PiperOrigin-RevId: 564013990
2023-09-09 09:01:30 -07:00
Mike Kruskal c3b72b99b4 Migrate internal C++-only test protos to editions.
This is some low hanging fruit that can increase our test coverage of editions.  Since only the C++ backend is implemented today, we can't yet migrate any protos that are public, are used outside C++, or are depended on by any proto outside C++.

PiperOrigin-RevId: 546076822
2023-07-06 13:28:14 -07:00
Martijn Vels dc9b2bf857 Add InternalVisibility and Arena enabled copy constructor to Map
PiperOrigin-RevId: 546026711
2023-07-06 10:25:46 -07:00
Mike Kruskal 4f9e41767a Release prototype of Protobuf Editions.
This represents the future direction of protobuf, replacing proto2/proto3 syntax with editions.  These will enable more incremental evolution of protobuf APIs through features, which are individual behaviors (such as whether field presence is explicit or implicit).  For more details see https://protobuf.dev/editions/overview/.

This PR contains a working implementation of editions for the protoc frontend and C++ code generation, along with various infrastructure improvements to support it.  It gives early access for anyone who wants to a preview of editions, but has no effect on proto2/proto3 syntax.  It is flag-guarded behind the `--experimental_editions` flag, and is an experimental feature with no guarantees.

PiperOrigin-RevId: 544805690
2023-06-30 20:18:49 -07:00
Adam Cozzette 80df4b29e0 Add `source_file_descriptors` to `CodeGeneratorRequest`
PiperOrigin-RevId: 542949247
2023-06-23 13:59:57 -07:00
Mike Kruskal 8f84e43231 Split out shared infrastructure from code generator unittest.
This will allow us to easily expand it to be used for generator unit-tests.

PiperOrigin-RevId: 542651612
2023-06-22 13:32:50 -07:00
Mike Kruskal 3c279623a0 Internal changes
PiperOrigin-RevId: 528038754
2023-04-28 18:55:27 -07:00
Mike Kruskal f51923041d Remove ODR violation from WKT codegen (#12406)
Closes #12406

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12406 from mkruskal-google:wkt 1c6748e6aa
PiperOrigin-RevId: 522418175
2023-04-06 13:19:50 -07:00
Deanna Garcia 4b3844e596 Delete unused bazel distribution rules.
We intended to use these for our release page, but we instead removed language-specific source files and use github commands to generate the full zip/tar file we release.

PiperOrigin-RevId: 520979818
2023-03-31 12:02:26 -07:00
deannagarcia 15bd2c21cf Merge 22.x back to main (#12169)
Closes #12169

PiperOrigin-RevId: 515161008
2023-03-08 15:38:14 -08:00
Mike Kruskal f174908946 Fix released protoc path
PiperOrigin-RevId: 514551233
2023-03-06 15:55:28 -08:00
Mike Kruskal 77e3f2c38d Rename protoc_static for release
PiperOrigin-RevId: 514500346
2023-03-06 13:04:31 -08:00
Mike Kruskal 723bd4c3c1 Modify release artifacts for protoc to statically link system libraries.
Closes #12063

PiperOrigin-RevId: 513034570
2023-02-28 14:13:48 -08:00
Protobuf Team Bot 7cc46f50de Internal change
PiperOrigin-RevId: 513015917
2023-02-28 13:00:46 -08:00
Jakob Buchgraber 77b1db01c9 Add the Rust codegen to protoc
After this change, the Rust codegen can be enabled via the protoc flag '--rust_out'. Due to its experimental nature we require a magic value to be provided '--rust_out=experimental-codegen=enabled:<out>'.

Make the 'RustGenerator' create an empty *.pb.rs file.

PiperOrigin-RevId: 512644570
2023-02-27 09:12:39 -08:00
Protobuf Team Bot d41deb9dc6 Internal change that helps identify the origin of reflection calls.
PiperOrigin-RevId: 510255963
2023-02-16 15:12:22 -08:00
Mike Kruskal d36a64116f Add missing test utility to CMake rules.
PiperOrigin-RevId: 501157741
2023-01-10 19:43:18 -08:00
Adam Cozzette dea15165c6 Add simple golden test for CMake file list generation
I updated our Bazel CI jobs to cover `//pkg/...` and thereby exercise this new
test. That made me realize that `//pkg/...` was not fully buildable because
there was a reference to the non-existent target `@utf8_range//:dist_files`, so
I also fixed that.

PiperOrigin-RevId: 498437497
2022-12-29 13:10:49 -08:00
Adam Cozzette b3ec9ec291 Fix staleness test by avoiding version-specific Bazel behavior
PiperOrigin-RevId: 498069823
2022-12-27 18:24:15 -08:00
archpaleus 2dcd7d8f70 use @utf8_range to reference //third_party/utf8_range (#11352)
Closes #11352

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/11352 from archpaleus:archpaleus/reference-utf8-range-workspace 75424976c7
PiperOrigin-RevId: 496993989
2022-12-21 13:32:09 -08:00
Adam Cozzette da09f7f78b Make CMake file list generation consistent across Bazel versions
It looks like Bazel 6.0 changed the stringification of Label objects:
b1113f801d

That is causing some problems for our staleness test, since different
Bazel versions get different results. This CL fixes the problem by
tweaking the logic so that we explicitly format the label string.

PiperOrigin-RevId: 496790722
2022-12-20 17:35:19 -08:00
Adam Cozzette 57a8846802 Make CMake test_util and lite_test_util mutually exclusive
This sets up these targets to be consistent with how the full and lite test
protos are currently handled.

PiperOrigin-RevId: 486233655
2022-11-04 14:39:26 -07:00
Adam Cozzette 7043b882a3 Make the CMake targets for test_util and lite_test_util independent
This should fix one more problem in the CMake build.

PiperOrigin-RevId: 486199507
2022-11-04 12:10:19 -07:00
Adam Cozzette 4ee1f529c6 Update CMake file generation to avoid including Bazel-specific WKT paths
To allow checked-in and generated versions of the well-known type
generated code to coexist in the repo, we have to give the checked-in
versions a long file path (e.g.
//src/google/protobuf:wkt/google/protobuf/any.pb.cc). However, this path
inadvertently leaked into the generated file_lists.cmake file, so this
commit corrects that problem.
2022-11-04 17:56:58 +00:00
Adam Cozzette b146519bde Update cc_dist_library() to include transitive sources
The cc_dist_library() rule originally included only the sources from
direct dependencies. This resulted in a less than ideal developer
experience, because if you ever added a new cc_library() then you would
have to carefully update the necessary cc_dist_library() targets to
ensure that the change was correctly reflected in the CMake build.

This commit addresses that issue by making cc_dist_library() include
transitive sources. We have to be careful to avoid introducing ODR
violations (e.g. from libprotoc duplicating sources from libprotobuf),
so we introduce a new dist_deps attribute on cc_dist_library(). Anything
in dist_deps is assumed to be covered by a separate cc_dist_library()
and is not included. We also make sure to exclude anything that's not
part of our repo (i.e. Abseil and zlib).
2022-11-04 15:12:55 +00:00
Mike Kruskal 983fc2d065 Migrate remaining compiler code to from std::map to Swiss tables.
This cl hit an issue during the shared library cmake build from ODR violations, leading to mismatched absl hash seeds.  The problem was pre-existing but didn't manifest until now, and can be traced to the fact that in shared library builds we linked Abseil statically.  All of the cmake changes here remove the underlying ODR violation.

PiperOrigin-RevId: 485787671
2022-11-02 23:25:39 -07:00
Deanna Garcia 7b855794e5 Fix pkg build rules 2022-10-14 20:29:25 +00:00
Mike Kruskal b2e1d7d8a1 Fix some superficial issues with GCC 4.9, MSVC, and CMake 2022-10-07 10:29:32 -07:00
Mike Kruskal 32bea52ee6 Sync from Piper @mkruskal/protobuf-absl
PROTOBUF_SYNC_PIPER
2022-10-06 16:48:39 -07:00
Thomas Van Lenten f6e284f8e5 Add the new compiler/objectivec:line_consumer target.
Without this the CMake list updated seems to way to drop the files.
2022-10-04 18:24:34 -04:00
Adam Cozzette 7ad2210641
Add a staleness test for src/file_lists.cmake (#10684)
* Upgrade upb to latest head

My motivation for this is that I plan to make use of upb's
staleness_test() macro, which was recently renamed
(protocolbuffers/upb#810).

* Add a staleness test for src/file_lists.cmake

This test is tagged "manual", because ordinarily no one should be
directly running this test. If we were to run this test regularly during
development then we would expect it to fail occasionally, because
file_lists.cmake will sometimes be temporarily stale until it is
auto-updated by our post-merge GitHub action. We want to run this test
nightly just as a safeguard to alert us if anything ever goes wrong with
the auto-update.
2022-09-30 04:37:38 -07:00
Mike Kruskal 388e3d744f Sync from Piper @mkruskal/footmitten
PROTOBUF_SYNC_PIPER
2022-09-27 12:31:15 -07:00
Mike Kruskal 01fe22219a
Open up visibility for some compiler internals (#10608)
* Expose language-specific naming utilities in Bazel for downstream code generators

* Expose language generators without exposing implementation details

* Update cmake configs

* Revert "Expose language generators without exposing implementation details"

This reverts commit b073d9b4ebf28b825a6340ea0dfc60f1e43ae4c1.

* Give gRPC privileged access to our python generator

* Naming cleanup

* Add linkage for public names.h helpers

* Fixing build/merge issues

* Fix extension docstring
2022-09-26 12:36:06 -07:00
Mike Kruskal b0c76ccc21 Sync from Piper @mkruskal/footmitten
PROTOBUF_SYNC_PIPER
2022-09-23 19:21:58 -07:00