Skip to content

Commit

Permalink
Disallow proc-macro-crate being used in Buck builds
Browse files Browse the repository at this point in the history
Summary: The `proc-macro-crate` crate involves looking at the filesystem for a Cargo.toml file in the directory given by $CARGO_MANIFEST_DIR, and parsing it to pick out names of crates. This crate is not possible to use correctly from a Buck build.

Reviewed By: capickett

Differential Revision: D61338693

fbshipit-source-id: 7236db8e54d9a872ab274678412fb57215fd27da
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Aug 15, 2024
1 parent 715b4ea commit e216676
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
18 changes: 17 additions & 1 deletion shed/facet/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,28 @@ rust_library(
name = "facet_proc_macros",
srcs = glob(["proc_macros/*.rs"]),
autocargo = {
"cargo_toml_config": {
"dependencies_override": {
"dependencies": {
"proc-macro-crate": {
"version": "1.1.0",
},
},
},
"lints": {
"rust": {
"unexpected_cfgs": {
"check-cfg": ["cfg(fb_buck_build)"],
"level": "warn",
},
},
},
},
"cargo_toml_dir": "proc_macros",
},
crate_root = "proc_macros/lib.rs",
proc_macro = True,
deps = [
"fbsource//third-party/rust:proc-macro-crate",
"fbsource//third-party/rust:proc-macro2",
"fbsource//third-party/rust:quote",
"fbsource//third-party/rust:syn",
Expand Down
3 changes: 3 additions & 0 deletions shed/facet/proc_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ proc-macro-crate = "1.1.0"
proc-macro2 = { version = "1.0.70", features = ["span-locations"] }
quote = "1.0.29"
syn = { version = "2.0.38", features = ["extra-traits", "fold", "full", "visit", "visit-mut"] }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fb_buck_build)"], level = "warn" } }
16 changes: 10 additions & 6 deletions shed/facet/proc_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
//!
//! See the crate-level documentation for the `facet` crate for details.
use proc_macro_crate::crate_name;
use proc_macro_crate::FoundCrate;

mod container_impl;
mod facet_impl;
mod factory_impl;
mod util;

fn facet_crate_name() -> String {
match crate_name("facet") {
Ok(FoundCrate::Name(n)) => n,
_ => "facet".to_string(),
#[cfg(not(fb_buck_build))]
{
use proc_macro_crate::crate_name;
use proc_macro_crate::FoundCrate;

if let Ok(FoundCrate::Name(name)) = crate_name("facet") {
return name;
}
}

"facet".to_string()
}

/// Mark a `struct` as a facet container. See the crate-level documentation
Expand Down

0 comments on commit e216676

Please sign in to comment.