@@ -40,6 +40,32 @@ def render_select_build_script_env(platform_items, use_legacy_rules_rust_platfor
4040def _exclude_deps_from_features (features ):
4141 return [f for f in features if not f .startswith ("dep:" )]
4242
43+ _INHERITABLE_PACKAGE_FIELDS = [
44+ "version" ,
45+ "edition" ,
46+ "description" ,
47+ "homepage" ,
48+ "repository" ,
49+ "license" ,
50+ # TODO(zbarsky): Do we need to fixup the path for readme and license_file?
51+ "license_file" ,
52+ "rust_version" ,
53+ "readme" ,
54+ ]
55+
56+ def inherit_workspace_package_fields (cargo_toml , workspace_cargo_toml ):
57+ workspace_package = workspace_cargo_toml .get ("workspace" , {}).get ("package" )
58+ if not workspace_package :
59+ return cargo_toml
60+
61+ crate_package = cargo_toml ["package" ]
62+ for field in _INHERITABLE_PACKAGE_FIELDS :
63+ value = crate_package .get (field )
64+ if type (value ) == "dict" and value .get ("workspace" ) == True :
65+ crate_package [field ] = workspace_package .get (field )
66+
67+ return cargo_toml
68+
4369def cargo_build_file_values (rctx , cargo_toml , gen_binaries , package_path = "" , gen_build_script = None ):
4470 package_dir = rctx .path (package_path or "." )
4571 package = cargo_toml ["package" ]
@@ -141,11 +167,15 @@ _RUST_CRATE_MACRO_CALL = """{indent}rust_crate(
141167{indent} data = [
142168{indent} {data}
143169{indent} ],
170+ {indent} extra_compile_data = [
171+ {indent} {extra_compile_data}
172+ {indent} ],
144173{indent} crate_features = {crate_features},
145174{indent} triples = {triples},
146175{indent} conditional_crate_features = {conditional_crate_features},
147176{indent} crate_root = {crate_root},
148177{indent} edition = {edition},
178+ {indent} rustc_env = {rustc_env},
149179{indent} rustc_flags = {rustc_flags}{conditional_rustc_flags},
150180{indent} tags = {tags},
151181{indent} target_compatible_with = RESOLVED_PLATFORMS,
@@ -162,10 +192,12 @@ _RUST_CRATE_MACRO_CALL = """{indent}rust_crate(
162192{indent} is_proc_macro = {is_proc_macro},
163193{indent} binaries = {binaries},
164194{indent} use_legacy_rules_rust_platforms = {use_legacy_rules_rust_platforms},
195+ {indent} cargo_toml_env = {cargo_toml_env},
196+ {indent} skip_deps_verification = {skip_deps_verification},
165197{indent})
166198"""
167199
168- def render_rust_crate_call (attr , values , bazel_metadata = {}, extra_deps = "" , indent = "" ):
200+ def render_rust_crate_call (attr , values , bazel_metadata = {}, extra_deps = "" , indent = "" , skip_deps_verification = False ):
169201 # We keep conditional_crate_features unrendered here because it must be treated specially for build scripts.
170202 # See `rust_crate.bzl` for details.
171203 crate_features , conditional_crate_features = compute_select (
@@ -195,11 +227,13 @@ def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", i
195227 extra_deps = extra_deps ,
196228 conditional_deps = " + " + conditional_deps if conditional_deps else "" ,
197229 data = list_indent .join (['"%s"' % d for d in attr .data ]),
230+ extra_compile_data = list_indent .join (['"%s"' % d for d in attr .extra_compile_data ]),
198231 crate_features = repr (sorted (crate_features )),
199232 triples = repr (attr .crate_features_select .keys ()),
200233 conditional_crate_features = repr (conditional_crate_features ),
201234 crate_root = values ["crate_root" ],
202235 edition = values ["edition" ],
236+ rustc_env = repr (attr .rustc_env ),
203237 rustc_flags = repr (rustc_flags ),
204238 conditional_rustc_flags = " + " + conditional_rustc_flags if conditional_rustc_flags else "" ,
205239 tags = repr (attr .crate_tags ),
@@ -218,6 +252,8 @@ def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", i
218252 is_proc_macro = values ["is_proc_macro" ],
219253 binaries = values ["binaries" ],
220254 use_legacy_rules_rust_platforms = use_legacy_rules_rust_platforms ,
255+ cargo_toml_env = attr .cargo_toml_env ,
256+ skip_deps_verification = repr (skip_deps_verification ),
221257 )
222258
223259def render_build_file_content (rctx , attr , values , bazel_metadata = {}):
@@ -250,16 +286,19 @@ rust_crate_attrs = {
250286 "build_script_tools" : attr .label_list (default = []),
251287 "build_script_tools_select" : attr .string_list_dict (),
252288 "build_script_tags" : attr .string_list (),
289+ "rustc_env" : attr .string_dict (),
253290 "rustc_flags" : attr .string_list (),
254291 "rustc_flags_select" : attr .string_list_dict (),
255292 "crate_tags" : attr .string_list (),
256293 "data" : attr .label_list (default = []),
294+ "extra_compile_data" : attr .label_list (default = []),
257295 "deps" : attr .string_list (default = []),
258296 "deps_select" : attr .string_list_dict (),
259297 "aliases" : attr .string_dict (),
260298 "crate_features" : attr .string_list (),
261299 "crate_features_select" : attr .string_list_dict (),
262300 "use_legacy_rules_rust_platforms" : attr .bool (),
301+ "cargo_toml_env" : attr .bool (default = True ),
263302}
264303
265304common_attrs = rust_crate_attrs | {
0 commit comments