From 06a3c3337714ba4d6b64f2fd04228a5ecca0cb41 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 1 May 2025 15:12:39 -0700 Subject: [PATCH 1/8] Update to `zerocopy` v0.8 --- Cargo.lock | 28 ++++++++++++++++++++++++---- runtime/Cargo.toml | 2 +- runtime/src/lib.rs | 32 ++++++++++++++++++++++++-------- src/client.rs | 14 ++++++-------- src/server.rs | 14 ++++++++++---- 5 files changed, 65 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d188a28..bf74cb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ dependencies = [ "bitflags", "byteorder", "serde", - "zerocopy", + "zerocopy 0.6.1", ] [[package]] @@ -280,7 +280,7 @@ version = "0.1.0" dependencies = [ "counters", "userlib", - "zerocopy", + "zerocopy 0.8.25", ] [[package]] @@ -656,7 +656,7 @@ dependencies = [ "paste", "serde", "ssmarshal", - "zerocopy", + "zerocopy 0.6.1", ] [[package]] @@ -795,7 +795,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "332f188cc1bcf1fe1064b8c58d150f497e697f49774aa846f2dc949d9a25f236" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.3.1", +] + +[[package]] +name = "zerocopy" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive 0.8.25", ] [[package]] @@ -808,3 +817,14 @@ dependencies = [ "syn 1.0.109", "synstructure", ] + +[[package]] +name = "zerocopy-derive" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 85a7c27..1e58a9d 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" [dependencies] counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} -zerocopy = "0.6.1" +zerocopy = { version = "0.8.25", features = ["derive"] } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index afe2ce1..edc8c16 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -15,7 +15,7 @@ use userlib::{ sys_reply_fault, FromPrimitive, LeaseAttributes, RecvMessage, ReplyFaultReason, TaskId, }; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] @@ -539,7 +539,11 @@ impl Leased { /// These functions are available on any readable lease (that is, read-only or /// read-write) where the content type `T` is `Sized` and can be moved around by /// naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeRead, + T: Sized + Copy + FromZeros + FromBytes + IntoBytes, +{ /// Reads the leased value by copy. /// /// If the lending task has been restarted between the time we checked lease @@ -549,7 +553,7 @@ impl Leased { pub fn read(&self) -> Option { let mut temp = T::new_zeroed(); let (rc, len) = - sys_borrow_read(self.lender, self.index, 0, temp.as_bytes_mut()); + sys_borrow_read(self.lender, self.index, 0, temp.as_mut_bytes()); if rc != 0 || len != core::mem::size_of::() { None } else { @@ -561,7 +565,11 @@ impl Leased { /// These functions are available on any readable leased slice (that is, /// read-only or read-write) where the element type `T` is `Sized` and can be /// moved around by naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeRead, + T: Sized + Copy + FromZeros + FromBytes + IntoBytes, +{ /// Reads a single element of the leased slice by copy. /// /// Like indexing a native slice, `index` must be less than `self.len()`, or @@ -580,7 +588,7 @@ impl Leased { self.lender, self.index, offset, - temp.as_bytes_mut(), + temp.as_mut_bytes(), ); if rc != 0 || len != core::mem::size_of::() { None @@ -615,7 +623,7 @@ impl Leased { self.lender, self.index, offset, - dest.as_bytes_mut(), + dest.as_mut_bytes(), ); if rc != 0 || len != expected_len { @@ -629,7 +637,11 @@ impl Leased { /// These functions are available on any writable lease (that is, write-only or /// read-write) where the content type `T` is `Sized` and can be moved around by /// naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeWrite, + T: Sized + Copy + IntoBytes + Immutable, +{ /// Writes the leased value by copy. /// /// If the lending task has been restarted between the time we checked lease @@ -650,7 +662,11 @@ impl Leased { /// These functions are available on any writable leased slice (that is, /// write-only or read-write) where the element type `T` is `Sized` and can be /// moved around by naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeWrite, + T: Sized + Copy + IntoBytes + Immutable, +{ /// Writes a single element of the leased slice by copy. /// /// Like indexing a native slice, `index` must be less than `self.len()`, or diff --git a/src/client.rs b/src/client.rs index 96ee780..5a0ca44 100644 --- a/src/client.rs +++ b/src/client.rs @@ -200,7 +200,7 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => { quote! { - #[derive(zerocopy::AsBytes)] + #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] #[repr(C, packed)] } } @@ -323,7 +323,7 @@ impl Generator { let op_enum_name = iface_name.as_op_enum(); let buf = match op.encoding { syntax::Encoding::Zerocopy => { - quote! { zerocopy::AsBytes::as_bytes(&args) } + quote! { zerocopy::IntoBytes::as_bytes(&args) } } syntax::Encoding::Ssmarshal | syntax::Encoding::Hubpack => { quote! { &argsbuf[..arglen] } @@ -331,8 +331,8 @@ impl Generator { }; let leases = op.leases.iter().map(|(leasename, lease)| { let (ctor, asbytes) = match (lease.read, lease.write) { - (true, true) => ("read_write", "as_bytes_mut"), - (false, true) => ("write_only", "as_bytes_mut"), + (true, true) => ("read_write", "as_mut_bytes"), + (false, true) => ("write_only", "as_mut_bytes"), (true, false) => ("read_only", "as_bytes"), (false, false) => panic!("should have been caught above"), }; @@ -342,7 +342,7 @@ impl Generator { syn::Ident::new(asbytes, proc_macro2::Span::call_site()); let argname = leasename.arg_prefixed(); quote! { - userlib::Lease::#ctor(zerocopy::AsBytes::#asbytes(#argname)) + userlib::Lease::#ctor(zerocopy::IntoBytes::#asbytes(#argname)) } }); quote! { @@ -372,9 +372,7 @@ impl Generator { struct #reply_ty { value: #repr_ty, } - let lv = zerocopy::LayoutVerified::<_, #reply_ty>::new_unaligned(&reply[..]) - .unwrap_lite(); - let v: #repr_ty = lv.value; + let v: #repr_ty = zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); } } syntax::Encoding::Ssmarshal => quote! { diff --git a/src/server.rs b/src/server.rs index efb967a..e6c5061 100644 --- a/src/server.rs +++ b/src/server.rs @@ -213,7 +213,14 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => quote! { #[repr(C, packed)] - #[derive(Copy, Clone, zerocopy::FromBytes, zerocopy::Unaligned)] + #[derive( + Copy, + Clone, + zerocopy::FromBytes, + zerocopy::KnownLayout, + zerocopy::Immutable, + zerocopy::Unaligned, + )] }, syntax::Encoding::Ssmarshal => quote! { #[derive(Copy, Clone, serde::Deserialize)] @@ -307,8 +314,7 @@ impl Generator { match op.encoding { syntax::Encoding::Zerocopy => quote! { pub fn #read_fn(bytes: &[u8]) -> Option<&#struct_name> { - Some(zerocopy::LayoutVerified::<_, #struct_name>::new_unaligned(bytes)? - .into_ref()) + zerocopy::FromBytes::ref_from_bytes(bytes).ok() } }, syntax::Encoding::Ssmarshal => quote! { @@ -551,7 +557,7 @@ impl Generator { let reply = { let encode = match op.encoding { syntax::Encoding::Zerocopy => quote! { - userlib::sys_reply(rm.sender, 0, zerocopy::AsBytes::as_bytes(&val)); + userlib::sys_reply(rm.sender, 0, zerocopy::IntoBytes::as_bytes(&val)); }, syntax::Encoding::Hubpack | syntax::Encoding::Ssmarshal => { let reply_size = opname.as_reply_size(); From 76991311a461a33e2683a6309ebb4bfa10cf9770 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 7 May 2025 10:43:27 -0700 Subject: [PATCH 2/8] idol-runtime doesn't actually derive zerocopy --- Cargo.lock | 2 +- runtime/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf74cb2..c297a1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idol" -version = "0.4.0" +version = "0.5.0" dependencies = [ "indexmap 1.9.2", "once_cell", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 1e58a9d..3a91eb1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" [dependencies] counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} -zerocopy = { version = "0.8.25", features = ["derive"] } +zerocopy = "0.8.25" From 7c2c2e64cca2831f39050f00526b48caa7685b19 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 7 May 2025 10:46:47 -0700 Subject: [PATCH 3/8] bump versions --- Cargo.lock | 2 +- Cargo.toml | 2 +- runtime/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c297a1d..8bb91c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,7 +276,7 @@ dependencies = [ [[package]] name = "idol-runtime" -version = "0.1.0" +version = "0.2.0" dependencies = [ "counters", "userlib", diff --git a/Cargo.toml b/Cargo.toml index c05ce3f..2fcd783 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "idol" -version = "0.4.0" +version = "0.5.0" edition = "2021" [features] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 3a91eb1..47a64af 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "idol-runtime" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From a4eb976791a2d8cdc41f01285cc241e82b71b7e8 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 7 May 2025 10:53:14 -0700 Subject: [PATCH 4/8] change generated code to use zerocopy from idol_runtime --- Cargo.lock | 1 + runtime/Cargo.toml | 1 + runtime/src/lib.rs | 10 +++++++++- src/client.rs | 10 +++++----- src/server.rs | 12 ++++++------ src/syntax.rs | 6 +++--- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8bb91c2..c50a377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,6 +281,7 @@ dependencies = [ "counters", "userlib", "zerocopy 0.8.25", + "zerocopy-derive 0.8.25", ] [[package]] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 47a64af..d4f4bfc 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} zerocopy = "0.8.25" +zerocopy-derive = "0.8.25" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index edc8c16..9c6e982 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -5,6 +5,8 @@ //! Most uses of Idol don't need to pull this crate in, but generated servers //! often do. +use self::zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; +use self::zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; use core::marker::PhantomData; use core::num::NonZeroU32; use core::ops::Range; @@ -15,7 +17,13 @@ use userlib::{ sys_reply_fault, FromPrimitive, LeaseAttributes, RecvMessage, ReplyFaultReason, TaskId, }; -use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; + +/// Re-export of `zerocopy` and `zerocopy-derive` so that generated code need +/// not depend in imports in the client/server crate. +pub mod zerocopy { + pub use zerocopy::*; + pub use zerocopy_derive::*; +} #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] diff --git a/src/client.rs b/src/client.rs index 5a0ca44..e08b851 100644 --- a/src/client.rs +++ b/src/client.rs @@ -200,7 +200,7 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => { quote! { - #[derive(zerocopy::IntoBytes, zerocopy::Immutable)] + #[derive(idol_runtime::zerocopy::IntoBytes, idol_runtime::zerocopy::Immutable)] #[repr(C, packed)] } } @@ -323,7 +323,7 @@ impl Generator { let op_enum_name = iface_name.as_op_enum(); let buf = match op.encoding { syntax::Encoding::Zerocopy => { - quote! { zerocopy::IntoBytes::as_bytes(&args) } + quote! { idol_runtime::zerocopy::IntoBytes::as_bytes(&args) } } syntax::Encoding::Ssmarshal | syntax::Encoding::Hubpack => { quote! { &argsbuf[..arglen] } @@ -342,7 +342,7 @@ impl Generator { syn::Ident::new(asbytes, proc_macro2::Span::call_site()); let argname = leasename.arg_prefixed(); quote! { - userlib::Lease::#ctor(zerocopy::IntoBytes::#asbytes(#argname)) + userlib::Lease::#ctor(idol_runtime::zerocopy::IntoBytes::#asbytes(#argname)) } }); quote! { @@ -367,12 +367,12 @@ impl Generator { let repr_ty = t.repr_ty(); quote! { let _len = len; - #[derive(zerocopy::FromBytes, zerocopy::Unaligned)] + #[derive(idol_runtime::zerocopy::FromBytes, idol_runtime::zerocopy::Unaligned)] #[repr(C, packed)] struct #reply_ty { value: #repr_ty, } - let v: #repr_ty = zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); + let v: #repr_ty = idol_runtime::zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); } } syntax::Encoding::Ssmarshal => quote! { diff --git a/src/server.rs b/src/server.rs index e6c5061..e304997 100644 --- a/src/server.rs +++ b/src/server.rs @@ -216,10 +216,10 @@ impl Generator { #[derive( Copy, Clone, - zerocopy::FromBytes, - zerocopy::KnownLayout, - zerocopy::Immutable, - zerocopy::Unaligned, + idol_runtime::zerocopy::FromBytes, + idol_runtime::zerocopy::KnownLayout, + idol_runtime::zerocopy::Immutable, + idol_runtime::zerocopy::Unaligned, )] }, syntax::Encoding::Ssmarshal => quote! { @@ -314,7 +314,7 @@ impl Generator { match op.encoding { syntax::Encoding::Zerocopy => quote! { pub fn #read_fn(bytes: &[u8]) -> Option<&#struct_name> { - zerocopy::FromBytes::ref_from_bytes(bytes).ok() + idol_runtime::zerocopy::FromBytes::ref_from_bytes(bytes).ok() } }, syntax::Encoding::Ssmarshal => quote! { @@ -557,7 +557,7 @@ impl Generator { let reply = { let encode = match op.encoding { syntax::Encoding::Zerocopy => quote! { - userlib::sys_reply(rm.sender, 0, zerocopy::IntoBytes::as_bytes(&val)); + userlib::sys_reply(rm.sender, 0, idol_runtime::zerocopy::IntoBytes::as_bytes(&val)); }, syntax::Encoding::Hubpack | syntax::Encoding::Ssmarshal => { let reply_size = opname.as_reply_size(); diff --git a/src/syntax.rs b/src/syntax.rs index efc67f6..bf6f986 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -275,11 +275,11 @@ pub struct Lease { #[serde(rename = "type")] pub ty: Ty, /// The server will be able to read from this lease. The type being leased - /// must implement `zerocopy::AsBytes`. + /// must implement `idol_runtime::zerocopy::AsBytes`. #[serde(default)] pub read: bool, /// The server will be able to write to this lease. The type being leased - /// must implement both `zerocopy::AsBytes` and `zerocopy::FromBytes`. + /// must implement both `idol_runtime::zerocopy::AsBytes` and `idol_runtime::zerocopy::FromBytes`. #[serde(default)] pub write: bool, /// The server cannot accept leases longer than this. @@ -538,7 +538,7 @@ impl quote::ToTokens for Error { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum RecvStrategy { /// The received bytes should be directly reinterpreted as the type using - /// `zerocopy::FromBytes`. + /// `idol_runtime::zerocopy::FromBytes`. FromBytes, /// The received bytes should be the named type, which will then be /// converted into the target type using `num_traits::FromPrimitive` (which From c7be85aabf81dd36500d0b8673b2219e6fa4cc2c Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 7 May 2025 15:17:41 -0700 Subject: [PATCH 5/8] let's not set ourselves up for sadness later --- runtime/src/lib.rs | 9 +++------ src/client.rs | 10 ++++++++-- src/server.rs | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9c6e982..6fd6f5e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -5,8 +5,6 @@ //! Most uses of Idol don't need to pull this crate in, but generated servers //! often do. -use self::zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; -use self::zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; use core::marker::PhantomData; use core::num::NonZeroU32; use core::ops::Range; @@ -17,13 +15,12 @@ use userlib::{ sys_reply_fault, FromPrimitive, LeaseAttributes, RecvMessage, ReplyFaultReason, TaskId, }; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; /// Re-export of `zerocopy` and `zerocopy-derive` so that generated code need /// not depend in imports in the client/server crate. -pub mod zerocopy { - pub use zerocopy::*; - pub use zerocopy_derive::*; -} +pub use zerocopy; +pub use zerocopy_derive; #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] diff --git a/src/client.rs b/src/client.rs index e08b851..b276f25 100644 --- a/src/client.rs +++ b/src/client.rs @@ -200,7 +200,10 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => { quote! { - #[derive(idol_runtime::zerocopy::IntoBytes, idol_runtime::zerocopy::Immutable)] + #[derive( + idol_runtime::zerocopy_derive::IntoBytes, + idol_runtime::zerocopy_derive::Immutable, + )] #[repr(C, packed)] } } @@ -367,7 +370,10 @@ impl Generator { let repr_ty = t.repr_ty(); quote! { let _len = len; - #[derive(idol_runtime::zerocopy::FromBytes, idol_runtime::zerocopy::Unaligned)] + #[derive( + idol_runtime::zerocopy_derive::FromBytes, + idol_runtime::zerocopy_derive::Unaligned, + )] #[repr(C, packed)] struct #reply_ty { value: #repr_ty, diff --git a/src/server.rs b/src/server.rs index e304997..b3b7fd1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -216,10 +216,10 @@ impl Generator { #[derive( Copy, Clone, - idol_runtime::zerocopy::FromBytes, - idol_runtime::zerocopy::KnownLayout, - idol_runtime::zerocopy::Immutable, - idol_runtime::zerocopy::Unaligned, + idol_runtime::zerocopy_derive::FromBytes, + idol_runtime::zerocopy_derive::KnownLayout, + idol_runtime::zerocopy_derive::Immutable, + idol_runtime::zerocopy_derive::Unaligned, )] }, syntax::Encoding::Ssmarshal => quote! { From b9da07a46fc97a94e21cabd81173104047d61959 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 8 May 2025 09:17:50 -0700 Subject: [PATCH 6/8] remove zerocopy reexport It turns out that the re-export of zerocopy doesn't actually help that much, as crates embedding `idol`-generated code must still depend on `zerocopy` explicitly. This is because the `zercopy_derive` macros generate implementations for zerocopy's traits that reference them as `zerocopy::`, which breaks when there isn't a `zerocopy` crate in scope when the generated code is compiled. --- Cargo.lock | 1 - runtime/Cargo.toml | 1 - runtime/src/lib.rs | 5 ----- src/client.rs | 14 +++++++------- src/server.rs | 12 ++++++------ 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c50a377..8bb91c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,7 +281,6 @@ dependencies = [ "counters", "userlib", "zerocopy 0.8.25", - "zerocopy-derive 0.8.25", ] [[package]] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d4f4bfc..47a64af 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -9,4 +9,3 @@ edition = "2021" counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} zerocopy = "0.8.25" -zerocopy-derive = "0.8.25" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6fd6f5e..edc8c16 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -17,11 +17,6 @@ use userlib::{ }; use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; -/// Re-export of `zerocopy` and `zerocopy-derive` so that generated code need -/// not depend in imports in the client/server crate. -pub use zerocopy; -pub use zerocopy_derive; - #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] pub enum ClientError { diff --git a/src/client.rs b/src/client.rs index b276f25..144c7ce 100644 --- a/src/client.rs +++ b/src/client.rs @@ -201,8 +201,8 @@ impl Generator { syntax::Encoding::Zerocopy => { quote! { #[derive( - idol_runtime::zerocopy_derive::IntoBytes, - idol_runtime::zerocopy_derive::Immutable, + zerocopy_derive::IntoBytes, + zerocopy_derive::Immutable, )] #[repr(C, packed)] } @@ -326,7 +326,7 @@ impl Generator { let op_enum_name = iface_name.as_op_enum(); let buf = match op.encoding { syntax::Encoding::Zerocopy => { - quote! { idol_runtime::zerocopy::IntoBytes::as_bytes(&args) } + quote! { zerocopy::IntoBytes::as_bytes(&args) } } syntax::Encoding::Ssmarshal | syntax::Encoding::Hubpack => { quote! { &argsbuf[..arglen] } @@ -345,7 +345,7 @@ impl Generator { syn::Ident::new(asbytes, proc_macro2::Span::call_site()); let argname = leasename.arg_prefixed(); quote! { - userlib::Lease::#ctor(idol_runtime::zerocopy::IntoBytes::#asbytes(#argname)) + userlib::Lease::#ctor(zerocopy::IntoBytes::#asbytes(#argname)) } }); quote! { @@ -371,14 +371,14 @@ impl Generator { quote! { let _len = len; #[derive( - idol_runtime::zerocopy_derive::FromBytes, - idol_runtime::zerocopy_derive::Unaligned, + zerocopy_derive::FromBytes, + zerocopy_derive::Unaligned, )] #[repr(C, packed)] struct #reply_ty { value: #repr_ty, } - let v: #repr_ty = idol_runtime::zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); + let v: #repr_ty = zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); } } syntax::Encoding::Ssmarshal => quote! { diff --git a/src/server.rs b/src/server.rs index b3b7fd1..6bd2ee9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -216,10 +216,10 @@ impl Generator { #[derive( Copy, Clone, - idol_runtime::zerocopy_derive::FromBytes, - idol_runtime::zerocopy_derive::KnownLayout, - idol_runtime::zerocopy_derive::Immutable, - idol_runtime::zerocopy_derive::Unaligned, + zerocopy_derive::FromBytes, + zerocopy_derive::KnownLayout, + zerocopy_derive::Immutable, + zerocopy_derive::Unaligned, )] }, syntax::Encoding::Ssmarshal => quote! { @@ -314,7 +314,7 @@ impl Generator { match op.encoding { syntax::Encoding::Zerocopy => quote! { pub fn #read_fn(bytes: &[u8]) -> Option<&#struct_name> { - idol_runtime::zerocopy::FromBytes::ref_from_bytes(bytes).ok() + zerocopy::FromBytes::ref_from_bytes(bytes).ok() } }, syntax::Encoding::Ssmarshal => quote! { @@ -557,7 +557,7 @@ impl Generator { let reply = { let encode = match op.encoding { syntax::Encoding::Zerocopy => quote! { - userlib::sys_reply(rm.sender, 0, idol_runtime::zerocopy::IntoBytes::as_bytes(&val)); + userlib::sys_reply(rm.sender, 0, zerocopy::IntoBytes::as_bytes(&val)); }, syntax::Encoding::Hubpack | syntax::Encoding::Ssmarshal => { let reply_size = opname.as_reply_size(); From 3f975670a83fc33d006c507f83d5d0e17df99219 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 8 May 2025 09:23:44 -0700 Subject: [PATCH 7/8] oh actually we can just import it, duh --- Cargo.lock | 1 + runtime/Cargo.toml | 3 ++- runtime/src/lib.rs | 5 +++++ src/client.rs | 2 ++ src/server.rs | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8bb91c2..c50a377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,6 +281,7 @@ dependencies = [ "counters", "userlib", "zerocopy 0.8.25", + "zerocopy-derive 0.8.25", ] [[package]] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 47a64af..5f1c7da 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -8,4 +8,5 @@ edition = "2021" [dependencies] counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} -zerocopy = "0.8.25" +zerocopy = { version = "0.8.25", default-features = false } +zerocopy-derive = "0.8.25" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index edc8c16..6fd6f5e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -17,6 +17,11 @@ use userlib::{ }; use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; +/// Re-export of `zerocopy` and `zerocopy-derive` so that generated code need +/// not depend in imports in the client/server crate. +pub use zerocopy; +pub use zerocopy_derive; + #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] pub enum ClientError { diff --git a/src/client.rs b/src/client.rs index 144c7ce..6c60b04 100644 --- a/src/client.rs +++ b/src/client.rs @@ -603,6 +603,8 @@ impl Generator { Ok(quote! { #[allow(unused_imports)] use userlib::UnwrapLite; + #[allow(unused_imports)] + use idol_runtime::{zerocopy, zerocopy_derive}; #[derive(Clone, Debug)] pub struct #iface_name { diff --git a/src/server.rs b/src/server.rs index 6bd2ee9..231b24c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -666,6 +666,9 @@ impl Generator { .unwrap_or_default(); Ok(quote! { + #[allow(unused_imports)] + use idol_runtime::{zerocopy, zerocopy_derive}; + #trait_def #counters From f746beb50cfc704c938dff43b17ca0754d048d7c Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 8 May 2025 09:26:38 -0700 Subject: [PATCH 8/8] Revert "oh actually we can just import it, duh" This reverts commit 3f975670a83fc33d006c507f83d5d0e17df99219. Turns out that actually doesn't work either: I think we just *need* to continue having explicit `zerocopy` deps in embedding crates: ``` error[E0433]: failed to resolve: could not find `zerocopy` in the list of imported crates --> /hubris/target/thumbv7em-none-eabihf/release/build/drv-user-leds-api-8a28786152326190/out/client_stub.rs:215:46 | 215 | #[derive(zerocopy_derive::IntoBytes, zerocopy_derive::Immutable)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `zerocopy` in the list of imported crates | = note: this error originates in the derive macro `zerocopy_derive::Immutable` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these crates --> drv/user-leds-api/src/lib.rs:9:1 | 9 + use crate::zerocopy; --> |drv/user-leds-api/src/lib.rs:9:1 | 9 + use idol_runtime::zerocopy; ``` --- Cargo.lock | 1 - runtime/Cargo.toml | 3 +-- runtime/src/lib.rs | 5 ----- src/client.rs | 2 -- src/server.rs | 3 --- 5 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c50a377..8bb91c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -281,7 +281,6 @@ dependencies = [ "counters", "userlib", "zerocopy 0.8.25", - "zerocopy-derive 0.8.25", ] [[package]] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 5f1c7da..47a64af 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -8,5 +8,4 @@ edition = "2021" [dependencies] counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} -zerocopy = { version = "0.8.25", default-features = false } -zerocopy-derive = "0.8.25" +zerocopy = "0.8.25" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6fd6f5e..edc8c16 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -17,11 +17,6 @@ use userlib::{ }; use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; -/// Re-export of `zerocopy` and `zerocopy-derive` so that generated code need -/// not depend in imports in the client/server crate. -pub use zerocopy; -pub use zerocopy_derive; - #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] pub enum ClientError { diff --git a/src/client.rs b/src/client.rs index 6c60b04..144c7ce 100644 --- a/src/client.rs +++ b/src/client.rs @@ -603,8 +603,6 @@ impl Generator { Ok(quote! { #[allow(unused_imports)] use userlib::UnwrapLite; - #[allow(unused_imports)] - use idol_runtime::{zerocopy, zerocopy_derive}; #[derive(Clone, Debug)] pub struct #iface_name { diff --git a/src/server.rs b/src/server.rs index 231b24c..6bd2ee9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -666,9 +666,6 @@ impl Generator { .unwrap_or_default(); Ok(quote! { - #[allow(unused_imports)] - use idol_runtime::{zerocopy, zerocopy_derive}; - #trait_def #counters