Skip to content

Commit f621a0f

Browse files
committed
feat(oss/rust): make iobuf available via cargo
1 parent 0f9b76d commit f621a0f

14 files changed

Lines changed: 287 additions & 74 deletions

File tree

.buckconfig.d/common.buckconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ prelude = prelude
33
none = none
44

55
[cell_aliases]
6+
antlir = gh_facebookincubator_antlir
67
config = prelude
78
ovr_config = prelude
89
bazel_skylib = gh_facebook_buck2_shims_meta

.buckconfig.d/external_cells/facebook/buck2-shims-meta/external_cell.buckconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ gh_facebook_buck2_shims_meta = git
66

77
[external_cell_gh_facebook_buck2_shims_meta]
88
git_origin = https://github.com/ben--/buck2-shims-meta.git
9-
commit_hash = 7809beb5cb5c4d6ee33688c9b9e02f3a2d456795
9+
commit_hash = 6854536eec883e6fb99e9a78616fea61dba45b3a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[cells]
2+
gh_facebookincubator_antlir = gh_facebookincubator_antlir
3+
4+
[external_cells]
5+
gh_facebookincubator_antlir = git
6+
7+
[external_cell_gh_facebookincubator_antlir]
8+
git_origin = https://github.com/facebookincubator/antlir.git
9+
commit_hash = de5b0f6e8b434a72a03f5868fd62533629004a44

folly/cli/BUCK

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@fbcode//folly:defs.bzl", "folly_xplat_library")
12
load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target")
23
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
34
load(
@@ -10,7 +11,6 @@ load(
1011
"MACOSX",
1112
"WINDOWS",
1213
)
13-
load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library")
1414
load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou")
1515

1616
oncall("fbcode_entropy_wardens_folly")

folly/rust/iobuf/BUCK

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "IOS", "MACOSX", "WINDOWS")
22
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
3-
load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
43
load("@fbsource//tools/build_defs:fb_xplat_rust_library.bzl", "fb_xplat_rust_library")
54
load("@fbsource//tools/build_defs:fb_xplat_suffixed_aliases.bzl", "create_forwarding_aliases")
6-
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode_compatible", "is_fbcode_mode_mac", "is_fbcode_mode_win", "is_xplat")
7-
load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library")
5+
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_xplat")
86

97
oncall("rust_libraries")
108

@@ -13,80 +11,69 @@ oncall("rust_libraries")
1311
# in the same build graph.
1412
create_forwarding_aliases(
1513
name = "iobuf",
16-
actual_name = select({
17-
"DEFAULT": "fbsource//xplat/folly/rust/iobuf:_iobuf",
18-
"ovr_config//os:linux": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_compatible() else "fbsource//xplat/folly/rust/iobuf:_iobuf",
19-
"ovr_config//os:macos": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_mode_mac() else "fbsource//xplat/folly/rust/iobuf:_iobuf",
20-
"ovr_config//os:windows": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_mode_win() else "fbsource//xplat/folly/rust/iobuf:_iobuf",
21-
}),
14+
actual_name = get_cell_name() + "//" + package_name() + ":_iobuf",
2215
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
2316
sdks = (IOS, MACOSX),
2417
visibility = ["PUBLIC"],
2518
) if is_xplat() else None
2619

27-
create_forwarding_aliases(
28-
name = "iobuf-ffi",
29-
actual_name = select({
30-
"DEFAULT": "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
31-
"ovr_config//os:linux": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_compatible() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
32-
"ovr_config//os:macos": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_mac() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
33-
"ovr_config//os:windows": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_win() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
34-
}),
35-
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
36-
sdks = (IOS, MACOSX),
37-
visibility = ["PUBLIC"],
38-
) if is_xplat() else None
20+
# create_forwarding_aliases(
21+
# name = "iobuf-ffi",
22+
# actual_name = get_cell_name() + "//" + package_name() + ":_iobuf-ffi"
23+
# platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
24+
# sdks = (IOS, MACOSX),
25+
# visibility = ["PUBLIC"],
26+
# ) if is_xplat() else None
3927

40-
rust_bindgen_library(
41-
name = "iobuf-sys",
42-
allowlist_funcs = [
43-
"facebook::rust::.*",
44-
],
45-
allowlist_types = [
46-
"folly::IOBuf",
47-
"facebook::rust::.*",
48-
],
49-
allowlist_vars = [
50-
"facebook::rust::.*",
51-
],
52-
blocklist_types = [
53-
# These seems to come from type_traits / make_signed via fbvector
54-
"folly::fbvector.*",
55-
"__type",
56-
"type_",
57-
],
58-
cpp_deps = [":_iobuf-ffi"],
59-
cxx_namespaces = True,
60-
generate = ("types", "vars", "functions"),
61-
header = "iobuf.h",
62-
opaque_types = [
63-
"std::.*",
64-
"folly::fbstring.*",
65-
],
66-
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
67-
src_includes = ["iobuf_sys.rs"],
68-
visibility = [],
69-
)
70-
71-
fb_xplat_cxx_library(
72-
name = "_iobuf-ffi",
73-
srcs = ["iobuf.cpp"],
74-
exported_headers = ["iobuf.h"],
75-
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
76-
preferred_linkage = "static",
77-
visibility = [
78-
"fbcode//folly/rust/iobuf/...",
79-
"fbsource//xplat/folly/rust/iobuf/...",
80-
],
81-
exported_deps = [
82-
"fbsource//xplat/folly/io:iobuf" if is_xplat() else "fbcode//folly/io:iobuf",
83-
],
84-
)
28+
# rust_bindgen_library(
29+
# name = "iobuf-sys",
30+
# allowlist_funcs = [
31+
# "facebook::rust::.*",
32+
# ],
33+
# allowlist_types = [
34+
# "folly::IOBuf",
35+
# "facebook::rust::.*",
36+
# ],
37+
# allowlist_vars = [
38+
# "facebook::rust::.*",
39+
# ],
40+
# blocklist_types = [
41+
# # These seems to come from type_traits / make_signed via fbvector
42+
# "folly::fbvector.*",
43+
# "__type",
44+
# "type_",
45+
# ],
46+
# cpp_deps = [":_iobuf-ffi"],
47+
# cxx_namespaces = True,
48+
# generate = ("types", "vars", "functions"),
49+
# header = "iobuf.h",
50+
# opaque_types = [
51+
# "std::.*",
52+
# "folly::fbstring.*",
53+
# ],
54+
# platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
55+
# src_includes = ["iobuf_sys.rs"],
56+
# visibility = [],
57+
# )
8558

59+
# fb_xplat_cxx_library(
60+
# name = "_iobuf-ffi",
61+
# srcs = ["iobuf.cpp"],
62+
# exported_headers = ["iobuf.h"],
63+
# platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
64+
# preferred_linkage = "static",
65+
# visibility = [
66+
# "fbcode//folly/rust/iobuf/...",
67+
# "fbsource//xplat/folly/rust/iobuf/...",
68+
# ],
69+
# exported_deps = [
70+
# "fbsource//xplat/folly/io:iobuf" if is_xplat() else "fbcode//folly/io:iobuf",
71+
# ],
72+
# )
73+
8674
fb_xplat_rust_library(
8775
name = "_iobuf",
8876
srcs = glob(["src/*.rs"]),
89-
cpp_deps = [":_iobuf-ffi"],
9077
crate = "iobuf",
9178
crate_root = "src/lib.rs",
9279
cxx_bridge = "src/lib.rs",
@@ -105,8 +92,8 @@ fb_xplat_rust_library(
10592
"fbsource//third-party/rust:cxx",
10693
"fbsource//third-party/rust:memmap2",
10794
"fbsource//xplat/thrift/lib/rust:fbthrift",
108-
":iobuf-sys",
109-
],
95+
get_cell_name() + "//" + package_name() + "_sys:iobuf-sys",
96+
]
11097
)
11198

11299
fb_native.alias(

folly/rust/iobuf/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "iobuf"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[features]
7+
minibytes = []
8+
9+
[dependencies]
10+
bytes = { version = "1.9.0", features = ["serde"] }
11+
cxx = "1.0"
12+
fbthrift = { version = "0.0.1+unstable", git = "https://github.com/facebook/fbthrift.git", branch = "main" }
13+
iobuf_sys = { version = "0.1.0", path = "../iobuf_sys" }
14+
memmap2 = "0.9"
15+
16+
[build-dependencies]
17+
cxx-build = "1.0"
18+
pkg-config = "0.3"

folly/rust/iobuf/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
let libfmt = pkg_config::probe_library("fmt")
3+
.expect("Couldn’t find fmt via pkg-config");
4+
let libfolly = pkg_config::probe_library("libfolly")
5+
.expect("Couldn’t find folly via pkg-config");
6+
7+
cxx_build::bridge("src/lib.rs")
8+
.file("../iobuf_sys/iobuf.cpp")
9+
.include("../../..")
10+
.includes(&libfmt.include_paths)
11+
.includes(&libfolly.include_paths)
12+
.compile("iobuf");
13+
}

folly/rust/iobuf/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub mod bridge {
125125

126126
#[namespace = "facebook::rust"]
127127
unsafe extern "C++" {
128-
include!("folly/rust/iobuf/iobuf.h");
128+
include!("folly/rust/iobuf_sys/iobuf.h");
129129

130130
fn iobuf_create(cap: usize) -> UniquePtr<IOBuf>;
131131
fn iobuf_create_combined(cap: usize) -> UniquePtr<IOBuf>;

folly/rust/iobuf_sys/BUCK

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "WINDOWS")
2+
load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
3+
load("@fbsource//tools/build_defs:fb_xplat_suffixed_aliases.bzl", "create_forwarding_aliases")
4+
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode_compatible", "is_fbcode_mode_mac", "is_fbcode_mode_win", "is_xplat")
5+
load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library")
6+
7+
oncall("rust_libraries")
8+
9+
rust_bindgen_library(
10+
name = "iobuf-sys",
11+
allowlist_funcs = [
12+
"facebook::rust::.*",
13+
],
14+
allowlist_types = [
15+
"folly::IOBuf",
16+
"facebook::rust::.*",
17+
],
18+
allowlist_vars = [
19+
"facebook::rust::.*",
20+
],
21+
blocklist_types = [
22+
# These seems to come from type_traits / make_signed via fbvector
23+
"folly::fbvector.*",
24+
"__type",
25+
"type_",
26+
],
27+
cpp_deps = [":iobuf-ffi"],
28+
cxx_namespaces = True,
29+
generate = ("types", "vars", "functions"),
30+
header = "iobuf.h",
31+
opaque_types = [
32+
"std::.*",
33+
"folly::fbstring.*",
34+
],
35+
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
36+
src_includes = ["iobuf_sys.rs"],
37+
visibility = [],
38+
)
39+
40+
create_forwarding_aliases(
41+
name = "iobuf-ffi",
42+
actual_name = get_cell_name() + "//" + package_name() + ":_iobuf-ffi",
43+
# actual_name = select({
44+
# "DEFAULT": "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
45+
# "ovr_config//os:linux": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_compatible() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
46+
# "ovr_config//os:macos": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_mac() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
47+
# "ovr_config//os:windows": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_win() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi",
48+
# }),
49+
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
50+
visibility = ["PUBLIC"],
51+
)
52+
53+
fb_xplat_cxx_library(
54+
name = "_iobuf-ffi",
55+
srcs = ["iobuf.cpp"],
56+
exported_headers = ["iobuf.h"],
57+
platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS),
58+
preferred_linkage = "static",
59+
visibility = [
60+
"fbcode//folly/rust/iobuf/...",
61+
"fbsource//xplat/folly/rust/iobuf/...",
62+
],
63+
exported_deps = [
64+
select({
65+
"DEFAULT": "fbsource//xplat/folly/io:iobuf",
66+
"ovr_config//os:linux": "fbcode//folly/io:iobuf" if is_fbcode_compatible() else "fbsource//xplat/folly/io:iobuf",
67+
"ovr_config//os:macos": "fbcode//folly/io:iobuf" if is_fbcode_mode_mac() else "fbsource//xplat/folly/io:iobuf",
68+
"ovr_config//os:windows": "fbcode//folly/io:iobuf" if is_fbcode_mode_win() else "fbsource//xplat/folly/io:iobuf",
69+
}) if is_xplat() else "fbcode//folly/io:iobuf",
70+
],
71+
)

folly/rust/iobuf_sys/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "iobuf_sys"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
# [lib]
7+
8+
[dependencies]
9+
cxx = "1.0"
10+
11+
[build-dependencies]
12+
bindgen = "0.72"
13+
pkg-config = "0.3"

0 commit comments

Comments
 (0)