Skip to content

Commit e499fa6

Browse files
Chandhana Solainathanmeta-codesync[bot]
authored andcommitted
Add Rust FFI bridge for Manifold uploads
Summary: Rust crate wrapping corpmanifold for cross-platform Manifold writes Reviewed By: janezhang10 Differential Revision: D98157675 fbshipit-source-id: c1378109332a468df4d3d9fd38a8328906927489
1 parent 0bbe8cc commit e499fa6

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

eden/fs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ members = [
9595
"inodes/overlay/services",
9696
"rust/edenfs-asserted-states",
9797
"rust/edenfs-asserted-states-client",
98+
"rust/manifold_ffi",
9899
"rust/redirect_ffi",
99100
"service",
100101
"service/clients",

eden/fs/rust/manifold_ffi/BUCK

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")
2+
3+
oncall("scm_client_infra")
4+
5+
rust_library(
6+
name = "manifold-ffi",
7+
srcs = glob(["src/**/*.rs"]),
8+
crate_root = "src/lib.rs",
9+
cxx_bridge = "src/lib.rs",
10+
deps = [
11+
"fbsource//third-party/rust:anyhow",
12+
"fbsource//third-party/rust:cxx",
13+
"//common/rust/shed/fbinit:fbinit",
14+
"//eden/scm/lib/edenfs_ffi/cxxerror:cxxerror",
15+
"//scm/telemetry/corpmanifold:corpmanifold",
16+
],
17+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# @generated by autocargo from //eden/fs/rust/manifold_ffi:manifold-ffi
2+
3+
[package]
4+
name = "manifold-ffi"
5+
version = "0.1.0"
6+
authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
7+
edition = "2024"
8+
license = "GPLv2+"
9+
10+
[dependencies]
11+
anyhow = "1.0.102"
12+
cxx = "1.0.119"
13+
cxxerror = { version = "0.1.0", path = "../../../scm/lib/edenfs_ffi/cxxerror" }
14+
fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This software may be used and distributed according to the terms of the
5+
* GNU General Public License version 2.
6+
*/
7+
8+
use anyhow::Context;
9+
use corpmanifold::manifold::ManifoldClient;
10+
use corpmanifold::manifold::RequestContext;
11+
use cxxerror::Result;
12+
13+
#[cxx::bridge(namespace = "facebook::eden")]
14+
mod ffi {
15+
extern "Rust" {
16+
/// Upload content to a Manifold bucket.
17+
fn manifold_write(
18+
bucket: &str,
19+
api_key: &str,
20+
key: &str,
21+
content: &[u8],
22+
timeout_msec: i32,
23+
expiration_secs: u32,
24+
client_identity: &str,
25+
) -> Result<()>;
26+
}
27+
}
28+
29+
fn manifold_write(
30+
bucket: &str,
31+
api_key: &str,
32+
key: &str,
33+
content: &[u8],
34+
timeout_msec: i32,
35+
expiration_secs: u32,
36+
client_identity: &str,
37+
) -> Result<()> {
38+
let client = ManifoldClient::new(
39+
unsafe { fbinit::assume_init() },
40+
client_identity,
41+
RequestContext {
42+
bucket_name: bucket.to_owned(),
43+
api_key: api_key.to_owned(),
44+
timeout_msec,
45+
},
46+
)
47+
.with_context(|| format!("Failed to create Manifold client for bucket {}", bucket))?;
48+
49+
client
50+
.write(key.to_owned(), content.to_vec(), expiration_secs)
51+
.with_context(|| format!("Failed to write key {} to Manifold bucket {}", key, bucket))?;
52+
53+
Ok(())
54+
}

0 commit comments

Comments
 (0)