diff --git a/.github/workflows/test_rust.yml b/.github/workflows/test_rust.yml index 29eef50ca5..ee86f6d64e 100644 --- a/.github/workflows/test_rust.yml +++ b/.github/workflows/test_rust.yml @@ -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/... \ No newline at end of file + //src/google/protobuf/compiler/rust/... \ No newline at end of file diff --git a/rust/BUILD b/rust/BUILD index e38f5644a2..6c2943d636 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -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( diff --git a/rust/cpp_kernel/cpp.rs b/rust/cpp.rs similarity index 95% rename from rust/cpp_kernel/cpp.rs rename to rust/cpp.rs index 64e202b74e..835726627a 100644 --- a/rust/cpp_kernel/cpp.rs +++ b/rust/cpp.rs @@ -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, _not_sync: PhantomData>, } @@ -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] { + pub unsafe fn alloc(&self, _layout: Layout) -> &mut [MaybeUninit] { 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] { + pub unsafe fn resize(&self, _ptr: *mut u8, _old: Layout, _new: Layout) -> &[MaybeUninit] { 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 diff --git a/rust/cpp_kernel/BUILD b/rust/cpp_kernel/BUILD index 3750498db5..0b9594b2e8 100644 --- a/rust/cpp_kernel/BUILD +++ b/rust/cpp_kernel/BUILD @@ -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__", + ], ) diff --git a/rust/shared.rs b/rust/shared.rs index b576ca6929..e088660b6c 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -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) } -} \ No newline at end of file +} diff --git a/rust/upb_kernel/upb.rs b/rust/upb.rs similarity index 100% rename from rust/upb_kernel/upb.rs rename to rust/upb.rs diff --git a/rust/upb_kernel/BUILD b/rust/upb_kernel/BUILD index 233c26024f..ecff4ce26f 100644 --- a/rust/upb_kernel/BUILD +++ b/rust/upb_kernel/BUILD @@ -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", ],