Put shared.rs and cpp.rs/upb.rs into the same crate.

The motivation is to make the setup simpler and more flexible.

PiperOrigin-RevId: 538189061
pull/12992/head
Marcel Hlopko 2 years ago committed by Copybara-Service
parent f92edc13c2
commit ff750bb4c3
  1. 3
      .github/workflows/test_rust.yml
  2. 23
      rust/BUILD
  3. 7
      rust/cpp.rs
  4. 23
      rust/cpp_kernel/BUILD
  5. 8
      rust/shared.rs
  6. 0
      rust/upb.rs
  7. 23
      rust/upb_kernel/BUILD

@ -28,6 +28,5 @@ jobs:
bazel-cache: rust_linux
bazel: |
test //rust:protobuf_upb_test //rust:protobuf_cpp_test \
//rust/upb_kernel:upb_test //rust/cpp_kernel:cpp_test \
//rust/test/rust_proto_library_unit_test:rust_upb_aspect_test \
//rust/upb_kernel:upb_test //src/google/protobuf/compiler/rust/...
//src/google/protobuf/compiler/rust/...

@ -48,9 +48,17 @@ rust_library(
# unittesting).
rust_library(
name = "protobuf_upb",
srcs = ["shared.rs"],
srcs = [
"shared.rs",
"upb.rs",
],
crate_root = "shared.rs",
rustc_flags = ["--cfg=upb_kernel"],
deps = ["//rust/upb_kernel:upb"],
visibility = [
"//src/google/protobuf:__subpackages__",
"//rust:__subpackages__",
],
deps = ["//rust/upb_kernel:upb_c_api"],
)
rust_test(
@ -72,9 +80,16 @@ rust_test(
# See the comment for `:protobuf` for discussion of `shared.rs` file.
rust_library(
name = "protobuf_cpp",
srcs = ["shared.rs"],
srcs = [
"cpp.rs",
"shared.rs",
],
crate_root = "shared.rs",
rustc_flags = ["--cfg=cpp_kernel"],
deps = ["//rust/cpp_kernel:cpp"],
visibility = [
"//src/google/protobuf:__subpackages__",
"//rust:__subpackages__",
],
)
rust_test(

@ -32,7 +32,6 @@
use std::alloc;
use std::alloc::Layout;
use std::boxed::Box;
use std::cell::UnsafeCell;
use std::fmt;
use std::marker::PhantomData;
@ -51,6 +50,7 @@ use std::slice;
///
/// Note that this type is neither `Sync` nor `Send`.
pub struct Arena {
#[allow(dead_code)]
ptr: NonNull<u8>,
_not_sync: PhantomData<UnsafeCell<()>>,
}
@ -74,7 +74,7 @@ impl Arena {
///
/// `layout`'s alignment must be less than `UPB_MALLOC_ALIGN`.
#[inline]
pub unsafe fn alloc(&self, layout: Layout) -> &mut [MaybeUninit<u8>] {
pub unsafe fn alloc(&self, _layout: Layout) -> &mut [MaybeUninit<u8>] {
unimplemented!()
}
@ -86,7 +86,7 @@ impl Arena {
/// be the layout `ptr` was allocated with via [`Arena::alloc()`]. `new`'s
/// alignment must be less than `UPB_MALLOC_ALIGN`.
#[inline]
pub unsafe fn resize(&self, ptr: *mut u8, old: Layout, new: Layout) -> &[MaybeUninit<u8>] {
pub unsafe fn resize(&self, _ptr: *mut u8, _old: Layout, _new: Layout) -> &[MaybeUninit<u8>] {
unimplemented!()
}
}
@ -146,6 +146,7 @@ impl fmt::Debug for SerializedData {
#[cfg(test)]
mod tests {
use super::*;
use std::boxed::Box;
// We need to allocate the byte array so SerializedData can own it and
// deallocate it in its drop. This function makes it easier to do so for our

@ -1,24 +1,6 @@
# This package contains Rust protobuf runtime implementation built on top of the C++ backend.
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "cpp",
srcs = ["cpp.rs"],
visibility = [
"//src/google/protobuf:__subpackages__",
"//rust:__subpackages__",
],
)
rust_test(
name = "cpp_test",
crate = ":cpp",
tags = [
# TODO(b/270274576): Enable testing on arm once we have a Rust Arm toolchain.
"not_build:arm",
],
)
load("@rules_rust//rust:defs.bzl", "rust_library")
cc_library(
name = "cpp_api",
@ -36,4 +18,7 @@ cc_library(
rust_library(
name = "rust_alloc_for_cpp_api",
srcs = ["rust_alloc_for_cpp_api.rs"],
visibility = [
"//rust:__subpackages__",
],
)

@ -34,9 +34,11 @@
//! crate.
#[cfg(cpp_kernel)]
pub extern crate cpp as __runtime;
#[path = "cpp.rs"]
pub mod __runtime;
#[cfg(upb_kernel)]
pub extern crate upb as __runtime;
#[path = "upb.rs"]
pub mod __runtime;
pub use __runtime::SerializedData;
@ -67,4 +69,4 @@ impl PtrAndLen {
pub unsafe fn as_ref<'a>(self) -> &'a [u8] {
slice::from_raw_parts(self.ptr, self.len)
}
}
}

@ -1,29 +1,12 @@
# This package contains Rust protobuf runtime implementation built on top of UPB.
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "upb",
srcs = ["upb.rs"],
cc_library(
name = "upb_c_api",
srcs = ["upb_api.c"],
visibility = [
"//src/google/protobuf:__subpackages__",
"//rust:__subpackages__",
],
deps = [":upb_c_api"],
)
rust_test(
name = "upb_test",
crate = ":upb",
tags = [
# TODO(b/270274576): Enable testing on arm once we have a Rust Arm toolchain.
"not_build:arm",
],
)
cc_library(
name = "upb_c_api",
srcs = ["upb_api.c"],
deps = [
"@upb//:upb",
],

Loading…
Cancel
Save