1+ def get_rust_features ():
2+ """
3+ Get comma-separated features from config and convert to a list.
4+ Default to proc-macro if none specified, matching Cargo.toml behavior.
5+ """
6+ features_config = read_config ("rust" , "features" , "" )
7+
8+ if features_config == "" :
9+ return ["proc-macro" ] # Default from Cargo.toml
10+ return [f .strip () for f in features_config .split ("," ) if f .strip ()]
11+
12+ def get_rustc_flags ():
13+ """
14+ Generate rustc flags based on configuration parameters.
15+ This mimics the functionality of the build.rs script.
16+ """
17+ flags = []
18+ features = get_rust_features ()
19+ rustc_minor = int (read_config ("proc_macro2" , "rustc_minor" , "9999" ))
20+ semver_exempt = read_config ("proc_macro2" , "semver_exempt" , "" ) != ""
21+ docs_rs = read_config ("proc_macro2" , "docs_rs" , "" ) != ""
22+ rustc_bootstrap = read_config ("proc_macro2" , "rustc_bootstrap" , "" ) != ""
23+
24+ # Handle semver_exempt (set by either procmacro2_semver_exempt or DOCS_RS)
25+ if semver_exempt or docs_rs :
26+ flags .extend (["--cfg" , "procmacro2_semver_exempt" ])
27+
28+ # Handle span_locations
29+ if semver_exempt or docs_rs or "span-locations" in features :
30+ flags .extend (["--cfg" , "span_locations" ])
31+
32+ # Handle no_is_available
33+ if rustc_minor < 57 :
34+ flags .extend (["--cfg" , "no_is_available" ])
35+
36+ # Handle no_source_text
37+ if rustc_minor < 66 :
38+ flags .extend (["--cfg" , "no_source_text" ])
39+
40+ # Handle no_literal_byte_character and no_literal_c_string
41+ if rustc_minor < 79 :
42+ flags .extend (["--cfg" , "no_literal_byte_character" ])
43+ flags .extend (["--cfg" , "no_literal_c_string" ])
44+
45+ # Handle proc_macro feature condition
46+ if "proc-macro" not in features :
47+ return flags
48+
49+ # Handle wrap_proc_macro
50+ proc_macro_span = rustc_bootstrap
51+
52+ if proc_macro_span or not semver_exempt :
53+ flags .extend (["--cfg" , "wrap_proc_macro" ])
54+
55+ # Handle proc_macro_span
56+ if proc_macro_span :
57+ flags .extend (["--cfg" , "proc_macro_span" ])
58+
59+ # Handle super_unstable
60+ if semver_exempt and proc_macro_span :
61+ flags .extend (["--cfg" , "super_unstable" ])
62+
63+ return flags
64+
65+ def get_env ():
66+ """
67+ Set environment variables for the build.
68+ """
69+ env = {}
70+
71+ # Set environment variables from config
72+ docs_rs = read_config ("proc_macro2" , "docs_rs" , "" )
73+ if docs_rs :
74+ env ["DOCS_RS" ] = docs_rs
75+
76+ rustc_bootstrap = read_config ("proc_macro2" , "rustc_bootstrap" , "" )
77+ if rustc_bootstrap :
78+ env ["RUSTC_BOOTSTRAP" ] = rustc_bootstrap
79+
80+ return env
0 commit comments