mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Forward-port Rust crate swap (#29397)
Cherrypick crate fixes from 36.x to main
Closes #29397
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/29397 from protocolbuffers:forward_port_crate_swap 2b5bb9fe65
PiperOrigin-RevId: 970589358
This commit is contained in:
parent
d17cf67434
commit
3df019d491
11 changed files with 90 additions and 56 deletions
|
|
@ -100,17 +100,12 @@ const fn split_version(version: &str) -> (u32, u32, u32, u32) {
|
||||||
|
|
||||||
// Indicates whether the given gencode and runtime versions are compatible with
|
// Indicates whether the given gencode and runtime versions are compatible with
|
||||||
// each other. Generally they are compatible if the gencode is no newer than the
|
// each other. Generally they are compatible if the gencode is no newer than the
|
||||||
// runtime, but the exception is that we consider gencode at 4.33 and older to
|
// runtime.
|
||||||
// be incompatible no matter what.
|
|
||||||
#[cfg(not(bzl))]
|
#[cfg(not(bzl))]
|
||||||
const fn are_versions_compatible(gencode: &str, runtime: &str) -> bool {
|
const fn are_versions_compatible(gencode: &str, runtime: &str) -> bool {
|
||||||
let gencode = split_version(gencode);
|
let gencode = split_version(gencode);
|
||||||
let runtime = split_version(runtime);
|
let runtime = split_version(runtime);
|
||||||
|
|
||||||
if gencode.0 < 4 || (gencode.0 == 4 && gencode.1 <= 33) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if gencode.0 != runtime.0 {
|
if gencode.0 != runtime.0 {
|
||||||
return gencode.0 < runtime.0;
|
return gencode.0 < runtime.0;
|
||||||
}
|
}
|
||||||
|
|
@ -134,18 +129,19 @@ const fn are_versions_compatible(gencode: &str, runtime: &str) -> bool {
|
||||||
/// the current runtime version. We require that the generated code cannot be
|
/// the current runtime version. We require that the generated code cannot be
|
||||||
/// newer than the runtime version.
|
/// newer than the runtime version.
|
||||||
///
|
///
|
||||||
/// 4.34 is the first stable release, so any gencode older than that is not
|
|
||||||
/// compatible going forward.
|
|
||||||
///
|
|
||||||
/// If you are seeing this fail, it means that your generated code was built
|
/// If you are seeing this fail, it means that your generated code was built
|
||||||
/// with a protoc version newer than the runtime crate version (or you have
|
/// with a protoc version newer than the runtime crate version.
|
||||||
/// pre-4.34 gencode).
|
|
||||||
#[cfg(not(bzl))]
|
#[cfg(not(bzl))]
|
||||||
pub const fn assert_compatible_gencode_version(gencode_version: &'static str) {
|
pub const fn assert_compatible_gencode_version(gencode_version: &'static str) {
|
||||||
let runtime_version = env!("CARGO_PKG_VERSION");
|
let runtime_version = env!("CARGO_PKG_VERSION");
|
||||||
assert!(
|
assert!(
|
||||||
are_versions_compatible(gencode_version, runtime_version),
|
are_versions_compatible(gencode_version, runtime_version),
|
||||||
"Gencode version is not compatible with runtime version",
|
concat!(
|
||||||
|
"Gencode version (see callsite) is not compatible with runtime ",
|
||||||
|
"version (runtime is ",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
")"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,11 +166,7 @@ mod tests {
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn test_are_versions_compatible() {
|
fn test_are_versions_compatible() {
|
||||||
// Pre-4.34 gencode is never considered compatible.
|
// Exact matches are always fine.
|
||||||
expect_false!(are_versions_compatible("4.33.0", "4.33.1"));
|
|
||||||
expect_false!(are_versions_compatible("3.33.0", "3.33.0"));
|
|
||||||
|
|
||||||
// Otherwise, exact matches are always fine.
|
|
||||||
expect_true!(are_versions_compatible("4.34.0-rc.1", "4.34.0-rc.1"));
|
expect_true!(are_versions_compatible("4.34.0-rc.1", "4.34.0-rc.1"));
|
||||||
expect_true!(are_versions_compatible("4.34.1", "4.34.1"));
|
expect_true!(are_versions_compatible("4.34.1", "4.34.1"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ pkg_filegroup(
|
||||||
name = "google_protobuf_crate",
|
name = "google_protobuf_crate",
|
||||||
srcs = [
|
srcs = [
|
||||||
":crate_root_files",
|
":crate_root_files",
|
||||||
|
"//rust:rust_protobuf_libupb_src",
|
||||||
|
"//rust:rust_protobuf_src_dir",
|
||||||
"//rust/release_crates:license",
|
"//rust/release_crates:license",
|
||||||
],
|
],
|
||||||
prefix = "google_protobuf",
|
prefix = "google_protobuf",
|
||||||
|
|
@ -24,6 +26,10 @@ substitute_rust_release_version(
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "srcs",
|
name = "srcs",
|
||||||
srcs = ["Cargo.toml"] + glob(["**/*"]),
|
srcs = [
|
||||||
visibility = ["//rust:__subpackages__"],
|
"Cargo.toml",
|
||||||
|
"README.md",
|
||||||
|
"build.rs",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,32 @@
|
||||||
|
# Protocol Buffers - Google's data interchange format
|
||||||
|
# Copyright 2024 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
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "google-protobuf"
|
name = "google-protobuf"
|
||||||
version = "{PROTOBUF_RUST_VERSION}"
|
version = "{PROTOBUF_RUST_VERSION}"
|
||||||
edition = "2021"
|
edition = "2021" # The Rust edition (not to be confused with Protobuf Edition).
|
||||||
|
links = "upb"
|
||||||
license = "BSD-3-Clause"
|
license = "BSD-3-Clause"
|
||||||
|
rust-version = "1.79"
|
||||||
description = "Protocol Buffers - Google's data interchange format"
|
description = "Protocol Buffers - Google's data interchange format"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/shared.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protobuf = { version = "{PROTOBUF_LEGACY_VERSION}", path = "../protobuf" }
|
linkme = "0.3.35"
|
||||||
|
paste = { package = "paste-complete", version = "1.0.15"}
|
||||||
|
protobuf-macros = { version = "{PROTOBUF_RUST_VERSION}", path = "../protobuf_macros", package = "protobuf-macros" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
googletest = "0.14.2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cc = "1.1.6"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bzl)', 'cfg(cpp_kernel)', 'cfg(upb_kernel)', 'cfg(lite_runtime)'] }
|
||||||
|
|
|
||||||
39
rust/release_crates/google_protobuf/README.md
Normal file
39
rust/release_crates/google_protobuf/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
The runtime of the official Google Rust Protobuf implementation.
|
||||||
|
|
||||||
|
This is currently a beta release: the API is subject to change, and there may be
|
||||||
|
some rough edges, including missing documentation and features.
|
||||||
|
|
||||||
|
An example for how to use this crate can be found in the
|
||||||
|
[protobuf_example crate](http://crates.io/crates/protobuf_example)
|
||||||
|
|
||||||
|
# Ownership and implementation change
|
||||||
|
|
||||||
|
This crate is officially supported by the Protobuf team at Google.
|
||||||
|
|
||||||
|
This is a completely new implementation with a different API, as well as a
|
||||||
|
fundamentally different approach than prior versions of the `protobuf` crate. It
|
||||||
|
focuses on delivering a high-quality Rust API which is backed by either a pure C
|
||||||
|
implementation (upb) or the Protobuf C++ implementation. This choice was made
|
||||||
|
for performance, feature parity, development velocity, and security reasons.
|
||||||
|
|
||||||
|
It is not planned for the pure Rust lineage to be actively developed going
|
||||||
|
forward. While it is not expected to receive significant further development, as
|
||||||
|
a stable and high quality pure Rust implementation, many open source projects
|
||||||
|
may reasonably continue to stay on the `protobuf` crate.
|
||||||
|
|
||||||
|
Development was previously done under the `protobuf` crate by a community
|
||||||
|
project by [stepancheg](https://github.com/stepancheg) who generously donated
|
||||||
|
the crate name to Google. V4.36.0 of the `protobuf` crate corresponds to V0.36.0
|
||||||
|
of this crate.
|
||||||
|
|
||||||
|
# How to get a compatible version of protoc
|
||||||
|
|
||||||
|
The protoc binary that you use to generate code needs to have a version that
|
||||||
|
exactly matches the version of the protobuf crate you are using. More
|
||||||
|
specifically, if you are using Rust protobuf `x.y.z` then you need to use protoc
|
||||||
|
`y.z`. See [here](https://protobuf.dev/support/version-support/) for more
|
||||||
|
details on our versioning scheme.
|
||||||
|
|
||||||
|
The easiest way to get ahold of protoc is to download a prebuilt binary from the
|
||||||
|
matching release [here](https://github.com/protocolbuffers/protobuf/releases).
|
||||||
|
Just make sure protoc is on your `$PATH` when you run `cargo`.
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
pub use protobuf::*;
|
|
||||||
|
|
@ -5,8 +5,6 @@ pkg_filegroup(
|
||||||
name = "protobuf_crate",
|
name = "protobuf_crate",
|
||||||
srcs = [
|
srcs = [
|
||||||
":crate_root_files",
|
":crate_root_files",
|
||||||
"//rust:rust_protobuf_libupb_src",
|
|
||||||
"//rust:rust_protobuf_src_dir",
|
|
||||||
"//rust/release_crates:license",
|
"//rust/release_crates:license",
|
||||||
],
|
],
|
||||||
prefix = "protobuf",
|
prefix = "protobuf",
|
||||||
|
|
@ -26,10 +24,6 @@ substitute_rust_release_version(
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "srcs",
|
name = "srcs",
|
||||||
srcs = [
|
srcs = ["Cargo.toml"] + glob(["**/*"]),
|
||||||
"Cargo.toml",
|
visibility = ["//rust:__subpackages__"],
|
||||||
"README.md",
|
|
||||||
"build.rs",
|
|
||||||
],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,9 @@
|
||||||
# Protocol Buffers - Google's data interchange format
|
|
||||||
# Copyright 2024 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
|
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "protobuf"
|
name = "protobuf"
|
||||||
version = "{PROTOBUF_LEGACY_VERSION}"
|
version = "{PROTOBUF_LEGACY_VERSION}"
|
||||||
edition = "2021" # The Rust edition (not to be confused with Protobuf Edition).
|
edition = "2021"
|
||||||
links = "upb"
|
|
||||||
license = "BSD-3-Clause"
|
license = "BSD-3-Clause"
|
||||||
rust-version = "1.79"
|
|
||||||
description = "Protocol Buffers - Google's data interchange format"
|
description = "Protocol Buffers - Google's data interchange format"
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/shared.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
linkme = "0.3.35"
|
google_protobuf = { package = "google-protobuf", version = "{PROTOBUF_RUST_VERSION}", path = "../google_protobuf" }
|
||||||
paste = { package = "paste-complete", version = "1.0.15"}
|
|
||||||
protobuf-macros = { version = "{PROTOBUF_RUST_VERSION}", path = "../protobuf_macros", package = "protobuf-macros" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
googletest = "0.14.2"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
cc = "1.1.6"
|
|
||||||
|
|
||||||
[lints.rust]
|
|
||||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bzl)', 'cfg(cpp_kernel)', 'cfg(upb_kernel)', 'cfg(lite_runtime)'] }
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ some rough edges, including missing documentation and features.
|
||||||
An example for how to use this crate can be found in the
|
An example for how to use this crate can be found in the
|
||||||
[protobuf_example crate](http://crates.io/crates/protobuf_example)
|
[protobuf_example crate](http://crates.io/crates/protobuf_example)
|
||||||
|
|
||||||
|
As of V4.36.0, this crate is a shallow wrapper around the `google_protobuf`
|
||||||
|
crate that it reexports.
|
||||||
|
|
||||||
# V4 ownership and implementation change
|
# V4 ownership and implementation change
|
||||||
|
|
||||||
V4 of this crate is officially supported by the Protobuf team at Google. Prior
|
V4 of this crate is officially supported by the Protobuf team at Google. Prior
|
||||||
|
|
|
||||||
1
rust/release_crates/protobuf/src/lib.rs
Normal file
1
rust/release_crates/protobuf/src/lib.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub use google_protobuf::*;
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
#define PROTOBUF_CPP_VERSION_STRING "7.37.0-dev"
|
#define PROTOBUF_CPP_VERSION_STRING "7.37.0-dev"
|
||||||
#define PROTOBUF_JAVA_VERSION_STRING "4.37.0-dev"
|
#define PROTOBUF_JAVA_VERSION_STRING "4.37.0-dev"
|
||||||
#define PROTOBUF_PYTHON_VERSION_STRING "7.37.0-dev"
|
#define PROTOBUF_PYTHON_VERSION_STRING "7.37.0-dev"
|
||||||
#define PROTOBUF_RUST_VERSION_STRING "4.37.0-dev"
|
#define PROTOBUF_RUST_VERSION_STRING "0.37.0-dev"
|
||||||
|
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue