diff --git a/rust/internal.rs b/rust/internal.rs index afb169ad71b2..5b08dc51619d 100644 --- a/rust/internal.rs +++ b/rust/internal.rs @@ -19,10 +19,17 @@ pub use crate::ProtoStr; use crate::Proxied; pub use std::fmt::Debug; +#[cfg(all(bzl, cpp_kernel))] +#[path = "cpp.rs"] +pub mod runtime; +#[cfg(any(not(bzl), upb_kernel))] +#[path = "upb.rs"] +pub mod runtime; + // TODO: Temporarily re-export these symbols which are now under -// __runtime under __internal since some external callers using it through -// __internal. -pub use crate::__runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField}; +// runtime under __internal directly since some external callers using it +// through __internal. +pub use runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField}; /// Used to protect internal-only items from being used accidentally. #[derive(Debug)] diff --git a/rust/map.rs b/rust/map.rs index 9df11f52d2b7..612210ba84cb 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -8,8 +8,8 @@ use crate::{ AsMut, AsView, IntoMut, IntoProxied, IntoView, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, + __internal::runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter}, __internal::{Private, SealedInternal}, - __runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter}, }; use std::marker::PhantomData; @@ -104,7 +104,11 @@ where } impl> Proxied for Map { - type View<'msg> = MapView<'msg, K, V> where K: 'msg, V: 'msg; + type View<'msg> + = MapView<'msg, K, V> + where + K: 'msg, + V: 'msg; } impl> AsView for Map { @@ -116,7 +120,11 @@ impl> AsView for Map { } impl> MutProxied for Map { - type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg; + type Mut<'msg> + = MapMut<'msg, K, V> + where + K: 'msg, + V: 'msg; } impl> AsMut for Map { diff --git a/rust/protobuf.rs b/rust/protobuf.rs index 172739a36534..d7f9bff9a71f 100644 --- a/rust/protobuf.rs +++ b/rust/protobuf.rs @@ -11,9 +11,9 @@ //! is a thin re-export of the `shared.rs` file but is needed for two reasons: //! - To create a single `protobuf` crate name for either cpp and upb kernels //! from user code (toggled at compile time). -//! - Blocks the __internal and __runtime modules from being re-exported to -//! application code, unless they use one of our visibility-restricted targets -//! (gencode does have access to them). +//! - Blocks the __internal module from being re-exported to application code, +//! unless they use one of our visibility-restricted targets (gencode does +//! have access to them). #[cfg(cpp_kernel)] use protobuf_cpp as kernel; @@ -31,8 +31,4 @@ use protobuf_upb as kernel; #[allow(non_upper_case_globals)] pub const __internal: () = (); -#[doc(hidden)] -#[allow(non_upper_case_globals)] -pub const __runtime: () = (); - pub use kernel::*; diff --git a/rust/repeated.rs b/rust/repeated.rs index 9d14faa1131c..479acb70d766 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -5,6 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +use std::fmt::{self, Debug}; use std::iter; use std::iter::FusedIterator; /// Repeated scalar fields are implemented around the runtime-specific @@ -12,13 +13,12 @@ use std::iter::FusedIterator; /// runtime-specific representation of a repeated scalar (`upb_Array*` on upb, /// and `RepeatedField*` on cpp). use std::marker::PhantomData; -use std::fmt::{self, Debug}; use crate::{ AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View, ViewProxy, + __internal::runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField}, __internal::{Private, SealedInternal}, - __runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField}, }; /// Views the elements in a `repeated` field of `T`. @@ -379,7 +379,10 @@ impl Proxied for Repeated where T: ProxiedInRepeated, { - type View<'msg> = RepeatedView<'msg, T> where Repeated: 'msg; + type View<'msg> + = RepeatedView<'msg, T> + where + Repeated: 'msg; } impl SealedInternal for Repeated where T: ProxiedInRepeated {} @@ -399,7 +402,10 @@ impl MutProxied for Repeated where T: ProxiedInRepeated, { - type Mut<'msg> = RepeatedMut<'msg, T> where Repeated: 'msg; + type Mut<'msg> + = RepeatedMut<'msg, T> + where + Repeated: 'msg; } impl AsMut for Repeated diff --git a/rust/shared.rs b/rust/shared.rs index ff8c88a94e5f..8e49f75bf7ac 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -5,10 +5,6 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -//! Kernel-agnostic logic for the Rust Protobuf Runtime. -//! -//! For kernel-specific logic this crate delegates to the respective `__runtime` -//! crate. #![deny(unsafe_op_in_unsafe_fn)] use std::fmt; @@ -38,22 +34,24 @@ pub use crate::string::{ProtoBytes, ProtoStr, ProtoString, Utf8Error}; pub mod prelude; -/// Everything in `__internal` is allowed to change without it being considered -/// a breaking change for the protobuf library. Nothing in here should be -/// exported in `protobuf.rs`. +/// The `__internal` module is for necessary encapsulation breaks between +/// generated code and the runtime. +/// +/// These symbols are never intended to be used by application code under any +/// circumstances. +/// +/// In blaze/bazel builds, this symbol is actively hidden from application +/// code by having a shim crate in front that does not re-export this symbol, +/// and a different BUILD visibility-restricted target that is used by the +/// generated code. +/// +/// In Cargo builds we have no good way to technically hide this +/// symbol while still allowing it from codegen, so it is only by private by +/// convention. As application code should never use this module, anything +/// changes under `__internal` is not considered a semver breaking change. #[path = "internal.rs"] pub mod __internal; -/// Everything in `__runtime` is allowed to change without it being considered -/// a breaking change for the protobuf library. Nothing in here should be -/// exported in `protobuf.rs`. -#[cfg(all(bzl, cpp_kernel))] -#[path = "cpp.rs"] -pub mod __runtime; -#[cfg(any(not(bzl), upb_kernel))] -#[path = "upb.rs"] -pub mod __runtime; - mod codegen_traits; mod cord; #[path = "enum.rs"] diff --git a/rust/string.rs b/rust/string.rs index 9ff984716e55..bddbdde827d0 100644 --- a/rust/string.rs +++ b/rust/string.rs @@ -9,8 +9,8 @@ #![allow(dead_code)] #![allow(unused)] +use crate::__internal::runtime::{InnerProtoString, PtrAndLen, RawMessage}; use crate::__internal::{Private, SealedInternal}; -use crate::__runtime::{InnerProtoString, PtrAndLen, RawMessage}; use crate::{ utf8::Utf8Chunks, AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied, Proxy, View, ViewProxy, diff --git a/rust/test/cpp/interop/main.rs b/rust/test/cpp/interop/main.rs index 4376311787ce..5751a0a8fa96 100644 --- a/rust/test/cpp/interop/main.rs +++ b/rust/test/cpp/interop/main.rs @@ -8,7 +8,7 @@ use googletest::prelude::*; use protobuf_cpp::prelude::*; -use protobuf_cpp::__runtime::PtrAndLen; +use protobuf_cpp::__internal::runtime::PtrAndLen; use protobuf_cpp::{MessageMutInterop, MessageViewInterop, OwnedMessageInterop}; use std::ffi::c_void; @@ -31,7 +31,9 @@ extern "C" { fn TakeOwnershipAndGetOptionalInt64(msg: *mut c_void) -> i64; fn DeserializeInteropTestMessage(data: *const u8, len: usize) -> *mut c_void; fn MutateInteropTestMessage(msg: *mut c_void); - fn SerializeInteropTestMessage(msg: *const c_void) -> protobuf_cpp::__runtime::SerializedData; + fn SerializeInteropTestMessage( + msg: *const c_void, + ) -> protobuf_cpp::__internal::runtime::SerializedData; fn DeleteInteropTestMessage(msg: *mut c_void); fn NewWithExtension() -> *mut c_void; diff --git a/rust/test/shared/no_internal_access_test.rs b/rust/test/shared/no_internal_access_test.rs index 4470faf445d2..10f05fc508a1 100644 --- a/rust/test/shared/no_internal_access_test.rs +++ b/rust/test/shared/no_internal_access_test.rs @@ -1,11 +1,10 @@ -use protobuf::{__internal, __runtime}; +use protobuf::__internal; #[googletest::test] #[allow(clippy::unit_cmp)] fn test_no_internal_access() { - // This test is to ensure that the `__internal` and `__runtime` mods are - // 'blocked' by instead being a unit type instead of a module. + // This test is to ensure that the `__internal` is 'blocked' by instead being a + // unit type instead of a module. assert_eq!(__internal, ()); - assert_eq!(__runtime, ()); } diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index c12a7fad49c2..21c608bf9c97 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -150,7 +150,7 @@ bool RustGenerator::Generate(const FileDescriptor* file, {"std", "::std"}, {"pb", "::protobuf"}, {"pbi", "::protobuf::__internal"}, - {"pbr", "::protobuf::__runtime"}, + {"pbr", "::protobuf::__internal::runtime"}, {"NonNull", "::std::ptr::NonNull"}, {"Phantom", "::std::marker::PhantomData"}, {"Result", "::std::result::Result"},