From 3f642253b91ec697e2e55027eb6cefe4d909fc95 Mon Sep 17 00:00:00 2001 From: Ben Rogers Date: Tue, 17 Jun 2025 14:32:32 -0400 Subject: [PATCH 1/2] fix(oss): Add folly/iobuf deps for backingstore --- eden/scm/lib/backingstore/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/eden/scm/lib/backingstore/Cargo.toml b/eden/scm/lib/backingstore/Cargo.toml index 828459498893d..d2cdf06985ec1 100644 --- a/eden/scm/lib/backingstore/Cargo.toml +++ b/eden/scm/lib/backingstore/Cargo.toml @@ -20,6 +20,7 @@ blob = { version = "0.1.0", path = "../blob" } cxx = "1.0.119" env_logger = { version = "0.11.8", features = ["color"] } flume = "0.11.1" +iobuf = { version = "0.1.0", git = "https://github.com/facebook/folly.git", branch = "main" } log = { version = "0.4.27", features = ["kv_unstable", "kv_unstable_std"] } parking_lot = { version = "0.12.1", features = ["send_guard"] } sapling-configloader = { version = "0.1.0", path = "../config/loader" } From 93b995a3603111d8126e70e349b83c4ae5edc942 Mon Sep 17 00:00:00 2001 From: Ben Rogers Date: Tue, 17 Jun 2025 14:32:32 -0400 Subject: [PATCH 2/2] feat(oss): Remove fbcode_build guards now that iobuf is available in oss --- eden/scm/lib/blob/src/lib.rs | 80 ++++++------------- .../lib/revisionstore/src/scmstore/tree.rs | 2 - .../revisionstore/src/scmstore/tree/fetch.rs | 2 - 3 files changed, 23 insertions(+), 61 deletions(-) diff --git a/eden/scm/lib/blob/src/lib.rs b/eden/scm/lib/blob/src/lib.rs index 3953c4737de3f..d332e812e8ce0 100644 --- a/eden/scm/lib/blob/src/lib.rs +++ b/eden/scm/lib/blob/src/lib.rs @@ -7,7 +7,6 @@ #![allow(unexpected_cfgs)] -#[cfg(fbcode_build)] use bytes::Buf; pub use minibytes::Bytes; use types::Blake3; @@ -16,7 +15,6 @@ use types::Sha1; #[derive(Clone, Debug)] pub enum Blob { Bytes(minibytes::Bytes), - #[cfg(fbcode_build)] IOBuf(iobuf::IOBufShared), } @@ -28,7 +26,6 @@ impl Blob { pub fn to_bytes(&self) -> minibytes::Bytes { match self { Self::Bytes(bytes) => bytes.clone(), - #[cfg(fbcode_build)] Self::IOBuf(buf) => minibytes::Bytes::from(Vec::::from(buf.clone())), } } @@ -36,7 +33,6 @@ impl Blob { pub fn into_bytes(self) -> minibytes::Bytes { match self { Self::Bytes(bytes) => bytes, - #[cfg(fbcode_build)] Self::IOBuf(buf) => minibytes::Bytes::from(Vec::::from(buf)), } } @@ -44,12 +40,10 @@ impl Blob { pub fn into_vec(self) -> Vec { match self { Self::Bytes(bytes) => bytes.into(), - #[cfg(fbcode_build)] Self::IOBuf(buf) => Vec::::from(buf), } } - #[cfg(fbcode_build)] pub fn into_iobuf(self) -> iobuf::IOBufShared { match self { // safety: `minibytes::Bytes`'s deref as `[u8]` is valid when `bytes` is alive. @@ -61,7 +55,6 @@ impl Blob { pub fn len(&self) -> usize { match self { Self::Bytes(bytes) => bytes.len(), - #[cfg(fbcode_build)] Self::IOBuf(buf) => buf.len(), } } @@ -69,7 +62,6 @@ impl Blob { pub fn is_empty(&self) -> bool { match self { Self::Bytes(bytes) => bytes.is_empty(), - #[cfg(fbcode_build)] Self::IOBuf(buf) => buf.is_empty(), } } @@ -113,7 +105,6 @@ impl Blob { ) -> std::io::Result<()> { match self { Self::Bytes(bytes) => f(bytes), - #[cfg(fbcode_build)] Self::IOBuf(buf) => { let mut cur = buf.clone().cursor(); loop { @@ -136,7 +127,6 @@ impl From> for Blob { } } -#[cfg(fbcode_build)] fn iobuf_from_bytes(bytes: minibytes::Bytes) -> iobuf::IOBufShared { unsafe { iobuf::IOBufShared::from_owner(bytes) } } @@ -145,13 +135,10 @@ impl PartialEq for Blob { fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::Bytes(l), Self::Bytes(r)) => l == r, - #[cfg(fbcode_build)] (Self::IOBuf(l), Self::IOBuf(r)) => l == r, - #[cfg(fbcode_build)] (Self::IOBuf(buf), Self::Bytes(bytes)) => { buf.len() == bytes.len() && buf == &iobuf_from_bytes(bytes.clone()) } - #[cfg(fbcode_build)] (Self::Bytes(bytes), Self::IOBuf(buf)) => { buf.len() == bytes.len() && buf == &iobuf_from_bytes(bytes.clone()) } @@ -170,7 +157,6 @@ pub enum Builder { // capacity Empty(usize), Bytes(Vec), - #[cfg(fbcode_build)] IOBuf(iobuf::IOBufShared), } @@ -186,23 +172,11 @@ impl Builder { pub fn append(&mut self, chunk: Bytes) { match self { Builder::Empty(size) => { - #[cfg(fbcode_build)] - { - // Using IOBuf - ignore size for pre-allocation. - let _ = size; - *self = Self::IOBuf(iobuf_from_bytes(chunk)); - } - - #[cfg(not(fbcode_build))] - { - // Not using IOBuf - pre-allocate with given size. - let mut data = Vec::with_capacity(*size); - data.extend_from_slice(chunk.as_ref()); - *self = Self::Bytes(data); - } + // Using IOBuf - ignore size for pre-allocation. + let _ = size; + *self = Self::IOBuf(iobuf_from_bytes(chunk)); } Builder::Bytes(data) => data.extend_from_slice(chunk.as_ref()), - #[cfg(fbcode_build)] Builder::IOBuf(iobuf) => iobuf.append_to_end(iobuf_from_bytes(chunk)), } } @@ -211,7 +185,6 @@ impl Builder { match self { Builder::Empty(_) => Blob::Bytes(Bytes::new()), Builder::Bytes(data) => Blob::Bytes(data.into()), - #[cfg(fbcode_build)] Builder::IOBuf(iobuf) => Blob::IOBuf(iobuf), } } @@ -221,7 +194,6 @@ impl Builder { mod test { use super::*; - #[cfg(fbcode_build)] #[test] fn test_iobuf_sha1_and_blake3() { let blob1 = Blob::Bytes(minibytes::Bytes::from("hello world!")); @@ -246,18 +218,15 @@ mod test { let b = Blob::Bytes(minibytes::Bytes::from("oops")); assert!(a != b); - #[cfg(fbcode_build)] - { - let a = Blob::Bytes(minibytes::Bytes::from("hello world!")); - let b = Blob::IOBuf(iobuf::IOBufShared::from("hello world!")); - assert_eq!(a, b); - assert_eq!(b, a); - - let a = Blob::Bytes(minibytes::Bytes::from("hello world!")); - let b = Blob::IOBuf(iobuf::IOBufShared::from("oops")); - assert!(a != b); - assert!(b != a); - } + let a = Blob::Bytes(minibytes::Bytes::from("hello world!")); + let b = Blob::IOBuf(iobuf::IOBufShared::from("hello world!")); + assert_eq!(a, b); + assert_eq!(b, a); + + let a = Blob::Bytes(minibytes::Bytes::from("hello world!")); + let b = Blob::IOBuf(iobuf::IOBufShared::from("oops")); + assert!(a != b); + assert!(b != a); } #[test] @@ -291,21 +260,18 @@ mod test { let res = a.each_chunk(|_| Err(std::io::Error::other("oops"))); assert!(res.is_err()); - #[cfg(fbcode_build)] - { - let mut iobuf = iobuf::IOBufShared::from("hello"); - iobuf.append_to_end(iobuf::IOBufShared::from("")); - iobuf.append_to_end(iobuf::IOBufShared::from(" world!")); + let mut iobuf = iobuf::IOBufShared::from("hello"); + iobuf.append_to_end(iobuf::IOBufShared::from("")); + iobuf.append_to_end(iobuf::IOBufShared::from(" world!")); - let a = Blob::IOBuf(iobuf); + let a = Blob::IOBuf(iobuf); - let mut got = Vec::new(); - let res = a.each_chunk(|chunk| { - got.extend_from_slice(chunk); - Ok(()) - }); - assert_eq!(got, b"hello world!"); - assert!(res.is_ok()); - } + let mut got = Vec::new(); + let res = a.each_chunk(|chunk| { + got.extend_from_slice(chunk); + Ok(()) + }); + assert_eq!(got, b"hello world!"); + assert!(res.is_ok()); } } diff --git a/eden/scm/lib/revisionstore/src/scmstore/tree.rs b/eden/scm/lib/revisionstore/src/scmstore/tree.rs index f54b48f4b8066..7693760f56749 100644 --- a/eden/scm/lib/revisionstore/src/scmstore/tree.rs +++ b/eden/scm/lib/revisionstore/src/scmstore/tree.rs @@ -236,8 +236,6 @@ impl TreeStore { TREE_STORE_FETCH_METRICS.cas.hit(1); let augmented_tree = match blob { Blob::Bytes(bytes) => AugmentedTree::try_deserialize(bytes.as_ref())?, - #[allow(unexpected_cfgs)] - #[cfg(fbcode_build)] Blob::IOBuf(buf) => AugmentedTree::try_deserialize(buf.cursor())?, }; self.cache_child_aux_data(tree_aux_store, &augmented_tree)?; diff --git a/eden/scm/lib/revisionstore/src/scmstore/tree/fetch.rs b/eden/scm/lib/revisionstore/src/scmstore/tree/fetch.rs index 8dd2ced376890..de9eeb377548d 100644 --- a/eden/scm/lib/revisionstore/src/scmstore/tree/fetch.rs +++ b/eden/scm/lib/revisionstore/src/scmstore/tree/fetch.rs @@ -322,8 +322,6 @@ impl FetchState { Ok(Some(data)) => { let deserialization_result = match data { Blob::Bytes(bytes) => AugmentedTree::try_deserialize(bytes.as_ref()), - #[allow(unexpected_cfgs)] - #[cfg(fbcode_build)] Blob::IOBuf(buf) => AugmentedTree::try_deserialize(buf.cursor()), }; match deserialization_result {