Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 558447c

Browse files
committed
Fix proc-macro2
Signed-off-by: Eli Ma <eli@patch.sh>
1 parent f773153 commit 558447c

File tree

9 files changed

+136
-115
lines changed

9 files changed

+136
-115
lines changed

BUCK

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ cargo.rust_binary(
9595
"//third-party/rust/crates/static_assertions/1.1.0:static_assertions",
9696

9797
# syn
98-
# "//third-party/rust/crates/syn/2.0.81",
98+
# "//third-party/rust/crates/syn/2.0.81:syn",
9999
# ---
100100

101101
# Serde
102-
# "//third-party/rust/crates/serde/1.0.60:serde",
102+
#"//third-party/rust/crates/serde/1.0.60:serde",
103103
# ---
104104

105105
# Serde_derive
106-
# "//third-party/rust/crates/serde_derive/1.0.218:serde_derive",
106+
#"//third-party/rust/crates/serde_derive/1.0.218:serde_derive",
107107
# ---
108108

109109
# foreign-types

third-party/rust/crates/proc-macro2/1.0.83/BUCK

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,19 @@ rust_library(
1515
"//third-party/rust/crates/unicode-ident/1.0.17:unicode-ident",
1616
],
1717
visibility = ["PUBLIC"],
18+
)
19+
20+
# proc_macro2 library with proc-macro feature enabled
21+
rust_library(
22+
name = "proc-macro2-proc-macro",
23+
edition = "2021", # Using edition from Cargo.toml
24+
srcs = glob(["src/**/*.rs"]) + ["build/probe.rs"], # Include probe.rs that build.rs uses
25+
crate_root = "src/lib.rs",
26+
features = get_rust_features("proc-macro"),
27+
rustc_flags = get_rustc_flags(),
28+
env = get_env(),
29+
deps = [
30+
"//third-party/rust/crates/unicode-ident/1.0.17:unicode-ident",
31+
],
32+
visibility = ["PUBLIC"],
1833
)

third-party/rust/crates/quote/1.0.35/BUCK

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ rust_library(
1212
env = {},
1313
deps = [
1414
# Conditional configuration for proc-macro2 with features based on our features
15-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
15+
"//third-party/rust/crates/proc-macro2/1.0.83:proc-macro2",
1616
],
1717
visibility = ["PUBLIC"],
1818
)
1919

20-
# Test target for quote
21-
rust_test(
22-
name = "quote_test",
23-
srcs = glob(["tests/**/*.rs"]), # Include all test files
24-
crate = ":quote",
20+
rust_library(
21+
name = "quote-proc-macro",
22+
edition = "2018", # Using edition from Cargo.toml
23+
srcs = glob(["src/**/*.rs"]),
24+
crate_root = "src/lib.rs",
25+
features = get_rust_features("proc-macro"),
26+
rustc_flags = [],
27+
env = {},
2528
deps = [
26-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
27-
"//third-party/rust/crates/rustversion/1.0:rustversion",
28-
"//third-party/rust/crates/trybuild/1.0.66:trybuild",
29+
# Conditional configuration for proc-macro2 with features based on our features
30+
"//third-party/rust/crates/proc-macro2/1.0.83:proc-macro2",
2931
],
30-
features = get_rust_features(),
32+
visibility = ["PUBLIC"],
3133
)
Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,18 @@
1-
load("@prelude//rust:cargo_package.bzl", "cargo")
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/serde/1.0.60:build.bzl", "get_rustc_flags", "get_rust_features", "get_conditional_deps")
23

34
# This BUCK file is for the serde_derive crate
45
# It provides proc macro implementations of #[derive(Serialize, Deserialize)]
5-
cargo.rust_library(
6-
name = "serde_derive",
7-
edition = "2015", # Using original edition to avoid syntax compatibility issues
8-
srcs = glob(["src/**/*.rs", "crates-io.md"]),
6+
# Serde library implementation
7+
rust_library(
8+
name = "serde",
9+
# Note: Cargo.toml does not specify an edition, so we use 2015 (the default for older crates)
10+
edition = "2015",
11+
srcs = glob(["src/**/*.rs"]),
912
crate_root = "src/lib.rs",
13+
features = get_rust_features(),
14+
rustc_flags = get_rustc_flags(),
15+
env = {},
16+
deps = get_conditional_deps(),
1017
visibility = ["PUBLIC"],
11-
features = ["default"],
12-
deps = [
13-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
14-
"//third-party/rust/crates/quote/1.0.35:quote",
15-
"//third-party/rust/crates/syn/2.0.81:syn",
16-
],
17-
proc_macro = True,
18-
rustc_flags = [
19-
# Allow bare trait objects (no 'dyn' keyword)
20-
"-A", "bare_trait_objects",
21-
# Allow other deprecated syntax
22-
"-A", "deprecated",
23-
# Allow absolute paths in macro
24-
"-A", "absolute_paths_not_starting_with_crate",
25-
# Allow using old-style trait bounds
26-
"-A", "improper_ctypes_definitions",
27-
# These help with using newer dependencies with older code
28-
"--allow-features=impl_trait_in_bindings",
29-
"--allow-features=proc_macro_span",
30-
],
31-
)
32-
33-
# Version with deserialize_in_place feature
34-
cargo.rust_library(
35-
name = "serde_derive-deserialize_in_place",
36-
edition = "2015", # Using original edition to avoid syntax compatibility issues
37-
srcs = glob(["src/**/*.rs", "crates-io.md"]),
38-
crate_root = "src/lib.rs",
39-
visibility = ["PUBLIC"],
40-
features = ["deserialize_in_place"],
41-
deps = [
42-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
43-
"//third-party/rust/crates/quote/1.0.35:quote",
44-
"//third-party/rust/crates/syn/2.0.81:syn",
45-
],
46-
proc_macro = True,
47-
rustc_flags = [
48-
"-A", "bare_trait_objects",
49-
"-A", "deprecated",
50-
"-A", "absolute_paths_not_starting_with_crate",
51-
"-A", "improper_ctypes_definitions",
52-
"--allow-features=impl_trait_in_bindings",
53-
"--allow-features=proc_macro_span",
54-
],
55-
)
18+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def get_rust_features():
2+
features_config = read_config("rust", "features", "")
3+
4+
if features_config == "":
5+
# Default feature is "std" as per Cargo.toml
6+
return ["std"]
7+
return [f.strip() for f in features_config.split(",") if f.strip()]
8+
9+
def get_rustc_flags():
10+
"""
11+
Generate rustc flags based on rustc version.
12+
This mimics the functionality of the build.rs script.
13+
"""
14+
flags = []
15+
16+
# Get rustc minor version from config
17+
rustc_minor = int(read_config("serde", "rustc_minor", "0"))
18+
19+
# 128-bit integers stabilized in Rust 1.26
20+
if rustc_minor >= 26:
21+
flags.extend(["--cfg", "integer128"])
22+
23+
# Non-zero integers stabilized in Rust 1.28
24+
if rustc_minor >= 28:
25+
flags.extend(["--cfg", "num_nonzero"])
26+
27+
return flags
28+
29+
def get_conditional_deps():
30+
"""
31+
Get conditional dependencies based on enabled features.
32+
"""
33+
deps = []
34+
features = get_rust_features()
35+
36+
# Add serde_derive dependency if derive feature is enabled
37+
if "derive" in features:
38+
deps.append("//third-party/rust/crates/serde_derive/1.0.218:serde_derive")
39+
40+
return deps
Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,20 @@
1-
load("@prelude//rust:cargo_package.bzl", "cargo")
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/serde_derive/1.0.218:build.bzl", "get_rust_features")
23

3-
# This BUCK file is for the serde_derive crate
4-
# It provides proc macro implementations of #[derive(Serialize, Deserialize)]
5-
cargo.rust_library(
4+
# serde_derive implementation: provides procedural macros for #[derive(Serialize, Deserialize)]
5+
rust_library(
66
name = "serde_derive",
7-
edition = "2015", # Using original edition to avoid syntax compatibility issues
8-
srcs = glob(["src/**/*.rs", "crates-io.md"]),
7+
edition = "2015", # Using edition from Cargo.toml
8+
srcs = glob(["src/**/*.rs"]),
99
crate_root = "src/lib.rs",
10-
visibility = ["PUBLIC"],
11-
features = ["default"],
10+
features = get_rust_features(),
11+
rustc_flags = [],
12+
env = {},
13+
proc_macro = True, # This is a procedural macro crate
1214
deps = [
13-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
14-
"//third-party/rust/crates/quote/1.0.35:quote",
15+
"//third-party/rust/crates/proc-macro2/1.0.83:proc-macro2-proc-macro",
16+
"//third-party/rust/crates/quote/1.0.35:quote-proc-macro",
1517
"//third-party/rust/crates/syn/2.0.81:syn",
1618
],
17-
proc_macro = True,
18-
rustc_flags = [
19-
# Allow bare trait objects (no 'dyn' keyword)
20-
"-A", "bare_trait_objects",
21-
# Allow other deprecated syntax
22-
"-A", "deprecated",
23-
# Allow absolute paths in macro
24-
"-A", "absolute_paths_not_starting_with_crate",
25-
],
26-
)
27-
28-
# Version with deserialize_in_place feature
29-
cargo.rust_library(
30-
name = "serde_derive-deserialize_in_place",
31-
edition = "2015", # Using original edition to avoid syntax compatibility issues
32-
srcs = glob(["src/**/*.rs", "crates-io.md"]),
33-
crate_root = "src/lib.rs",
3419
visibility = ["PUBLIC"],
35-
features = ["deserialize_in_place"],
36-
deps = [
37-
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
38-
"//third-party/rust/crates/quote/1.0.35:quote",
39-
"//third-party/rust/crates/syn/2.0.81:syn",
40-
],
41-
proc_macro = True,
42-
rustc_flags = [
43-
"-A", "bare_trait_objects",
44-
"-A", "deprecated",
45-
"-A", "absolute_paths_not_starting_with_crate",
46-
],
47-
)
20+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def get_rust_features():
2+
features_config = read_config("rust", "features", "")
3+
4+
if features_config == "":
5+
return [] # No default features in Cargo.toml
6+
return [f.strip() for f in features_config.split(",") if f.strip()]
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
load("@prelude//rust:cargo_package.bzl", "cargo")
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/syn/2.0.81:build.bzl", "get_rust_features", "get_conditional_deps")
23

3-
# This BUCK file is generated based on Cargo.toml
4-
# Parser for Rust source code
54

6-
cargo.rust_library(
5+
# syn library implementation
6+
rust_library(
77
name = "syn",
8-
edition = "2021",
8+
edition = "2021", # Using edition from Cargo.toml
99
srcs = glob(["src/**/*.rs"]),
1010
crate_root = "src/lib.rs",
11+
features = get_rust_features(),
12+
rustc_flags = [],
13+
env = {},
14+
deps = get_conditional_deps(),
1115
visibility = ["PUBLIC"],
12-
features = ["default"],
13-
deps = [
14-
"//third-party/rust/crates/proc-macro2/1.0.83:proc-macro2",
15-
"//third-party/rust/crates/quote/1.0.35:quote",
16-
"//third-party/rust/crates/unicode-ident/1.0.17:unicode-ident",
17-
]
18-
)
16+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def get_rust_features():
2+
features_config = read_config("rust", "features", "")
3+
4+
if features_config == "":
5+
# Default features from Cargo.toml
6+
return ["derive", "parsing", "printing", "clone-impls", "proc-macro"]
7+
return [f.strip() for f in features_config.split(",") if f.strip()]
8+
9+
def get_conditional_deps():
10+
"""
11+
Get conditional dependencies based on enabled features.
12+
"""
13+
deps = [
14+
"//third-party/rust/crates/proc-macro2/1.0.83:proc-macro2",
15+
"//third-party/rust/crates/unicode-ident/1.0:unicode-ident",
16+
]
17+
18+
features = get_rust_features()
19+
20+
# Add quote dependency if printing feature is enabled
21+
if "printing" in features:
22+
deps.append("//third-party/rust/crates/quote/1.0.35:quote")
23+
24+
return deps

0 commit comments

Comments
 (0)