Adds an initial Cargo.toml for the protobuf crate.
Adds a new 'bzl' feature that is used to adjust import paths that need to change in the Cargo build vs Blaze build. This protobuf rust crate is a single crate that merges all of our current crates (protobuf, rust/upb, and utf8). PiperOrigin-RevId: 656405153
This commit is contained in:
Родитель
1e6abadc2b
Коммит
6f58085577
|
@ -77,7 +77,10 @@ rust_library(
|
|||
proc_macro_deps = [
|
||||
"@crate_index//:paste",
|
||||
],
|
||||
rustc_flags = ["--cfg=upb_kernel"],
|
||||
rustc_flags = [
|
||||
"--cfg=upb_kernel",
|
||||
"--cfg=bzl",
|
||||
],
|
||||
visibility = [
|
||||
"//rust:__subpackages__",
|
||||
"//src/google/protobuf:__subpackages__",
|
||||
|
@ -93,6 +96,7 @@ rust_test(
|
|||
crate = ":protobuf_upb",
|
||||
rustc_flags = [
|
||||
"--cfg=upb_kernel",
|
||||
"--cfg=bzl",
|
||||
],
|
||||
deps = [
|
||||
"@crate_index//:googletest",
|
||||
|
@ -136,6 +140,7 @@ rust_test(
|
|||
crate = ":protobuf_cpp",
|
||||
rustc_flags = [
|
||||
"--cfg=cpp_kernel",
|
||||
"--cfg=bzl",
|
||||
],
|
||||
deps = [
|
||||
"@crate_index//:googletest",
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "protobuf"
|
||||
version = "4.27.3-beta.0"
|
||||
edition = "2021"
|
||||
links = "upb"
|
||||
|
||||
[lib]
|
||||
path = "src/shared.rs"
|
||||
|
||||
[dependencies]
|
||||
paste = "1.0.15"
|
||||
|
||||
[dev-dependencies]
|
||||
googletest = {git = "https://github.com/google/googletest-rust.git" }
|
||||
|
||||
[build-dependencies]
|
||||
cmake = "0.1.50"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bzl)', 'cfg(cpp_kernel)', 'cfg(upb_kernel)'] }
|
|
@ -0,0 +1,16 @@
|
|||
fn main() {
|
||||
cc::Build::new()
|
||||
.flag("-std=c99")
|
||||
// TODO: Come up with a way to enable lto
|
||||
// .flag("-flto=thin")
|
||||
.warnings(false)
|
||||
.include("src")
|
||||
.file("src/upb.c")
|
||||
.file("src/utf8_range.c")
|
||||
.file("src/upb/upb_api.c")
|
||||
.define("UPB_BUILD_API", Some("1"))
|
||||
.define("PROTOBUF_CARGO", Some("1"))
|
||||
.compile("upb");
|
||||
let path = std::path::Path::new("src");
|
||||
println!("cargo:include={}", path.canonicalize().unwrap().display())
|
||||
}
|
|
@ -108,7 +108,7 @@ pub trait AsView {
|
|||
///
|
||||
/// For example, the call to `.as_view()` in the following snippet
|
||||
/// wouldn't be necessary in concrete code:
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn reborrow<'a, 'b, T>(x: &'b View<'a, T>) -> View<'b, T>
|
||||
/// where 'a: 'b, T: Proxied
|
||||
/// {
|
||||
|
@ -136,7 +136,7 @@ pub trait IntoView<'msg>: AsView {
|
|||
/// `into_view` to explicitly perform the operation that in concrete
|
||||
/// code coercion would perform implicitly.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn reborrow_generic_view_into_view<'a, 'b, T>(
|
||||
/// x: View<'a, T>,
|
||||
/// y: View<'b, T>,
|
||||
|
@ -182,7 +182,7 @@ pub trait IntoMut<'msg>: AsMut {
|
|||
/// `into_mut` to explicitly perform the operation that in concrete code
|
||||
/// coercion would perform implicitly.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn reborrow_generic_mut_into_mut<'a, 'b, T>(x: Mut<'a, T>, y: Mut<'b, T>) -> [Mut<'b, T>; 2]
|
||||
/// where
|
||||
/// T: Proxied,
|
||||
|
|
|
@ -56,10 +56,10 @@ 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(cpp_kernel)]
|
||||
#[cfg(all(bzl, cpp_kernel))]
|
||||
#[path = "cpp.rs"]
|
||||
pub mod __runtime;
|
||||
#[cfg(upb_kernel)]
|
||||
#[cfg(any(not(bzl), upb_kernel))]
|
||||
#[path = "upb.rs"]
|
||||
pub mod __runtime;
|
||||
|
||||
|
@ -75,6 +75,18 @@ mod proxied;
|
|||
mod repeated;
|
||||
mod string;
|
||||
|
||||
#[cfg(not(bzl))]
|
||||
#[path = "upb/lib.rs"]
|
||||
mod upb;
|
||||
|
||||
#[cfg(not(bzl))]
|
||||
mod utf8;
|
||||
|
||||
// Forces the utf8 crate to be accessible from crate::.
|
||||
#[cfg(bzl)]
|
||||
#[allow(clippy::single_component_path_imports)]
|
||||
use utf8;
|
||||
|
||||
// If the Upb and C++ kernels are both linked into the same binary, this symbol
|
||||
// will be defined twice and cause a link error.
|
||||
#[no_mangle]
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
use crate::__internal::Private;
|
||||
use crate::__runtime::{InnerProtoString, PtrAndLen, RawMessage};
|
||||
use crate::{
|
||||
AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied, Proxy, View,
|
||||
ViewProxy,
|
||||
utf8::Utf8Chunks, AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied,
|
||||
Proxy, View, ViewProxy,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
||||
|
@ -26,7 +26,6 @@ use std::ops::{Deref, DerefMut};
|
|||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use utf8::Utf8Chunks;
|
||||
|
||||
pub struct ProtoBytes {
|
||||
pub(crate) inner: InnerProtoString,
|
||||
|
|
|
@ -19,7 +19,10 @@ use std::ptr::{self, NonNull};
|
|||
use std::slice;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
#[cfg(bzl)]
|
||||
extern crate upb;
|
||||
#[cfg(not(bzl))]
|
||||
use crate::upb;
|
||||
|
||||
// Temporarily 'pub' since a lot of gencode is directly calling any of the ffi
|
||||
// fns.
|
||||
|
|
|
@ -28,6 +28,7 @@ rust_library(
|
|||
"text.rs",
|
||||
"wire.rs",
|
||||
],
|
||||
rustc_flags = ["--cfg=bzl"],
|
||||
visibility = [
|
||||
"//rust:__subpackages__",
|
||||
"//src/google/protobuf:__subpackages__",
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
#![cfg_attr(not(bzl), allow(unused_imports))]
|
||||
|
||||
mod arena;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ use std::str::from_utf8_unchecked;
|
|||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// use googletest::prelude::*;
|
||||
/// use utf8::Utf8Chunks;
|
||||
///
|
||||
|
@ -133,7 +133,7 @@ impl fmt::Debug for Debug<'_> {
|
|||
/// This can be used to create functionality similar to
|
||||
/// [`String::from_utf8_lossy`] without allocating heap memory:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// use utf8::Utf8Chunks;
|
||||
///
|
||||
/// fn from_utf8_lossy<F>(input: &[u8], mut push: F) where F: FnMut(&str) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче