From 0f582d5254e66dfbeb105acf2f8952134c3420a4 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 12 Oct 2023 17:01:25 +0100 Subject: [PATCH] Improvements to better support cxx (#2192) * Support adding to `deps` from annotations in Cargo.toml files * Default `extra_aliased_targets` and `gen_binaries` to `None` rather than empty collections, because the rust code has explicit handling for `None` vs empty when merging. --- crate_universe/private/crate.bzl | 4 ++-- crate_universe/src/config.rs | 3 +++ crate_universe/src/metadata/metadata_annotation.rs | 2 +- docs/crate_universe.md | 4 ++-- examples/crate_universe/WORKSPACE.bazel | 8 ++++++++ .../crate_universe/cargo_aliases/cargo-bazel-lock.json | 2 +- .../crate_universe/multi_package/cargo-bazel-lock.json | 2 +- .../no_cargo_manifests/cargo-bazel-lock.json | 2 +- examples/crate_universe/using_cxx/cargo-bazel-lock.json | 8 +++++++- 9 files changed, 26 insertions(+), 9 deletions(-) diff --git a/crate_universe/private/crate.bzl b/crate_universe/private/crate.bzl index 868cc8d62c..15596c7b9e 100644 --- a/crate_universe/private/crate.bzl +++ b/crate_universe/private/crate.bzl @@ -85,8 +85,8 @@ def _annotation( data = None, data_glob = None, deps = None, - extra_aliased_targets = {}, - gen_binaries = [], + extra_aliased_targets = None, + gen_binaries = None, disable_pipelining = False, gen_build_script = None, patch_args = None, diff --git a/crate_universe/src/config.rs b/crate_universe/src/config.rs index c4af4d03d1..98af006ec1 100644 --- a/crate_universe/src/config.rs +++ b/crate_universe/src/config.rs @@ -368,6 +368,7 @@ pub struct AnnotationsProvidedByPackage { pub gen_build_script: Option, pub data: Option>, pub data_glob: Option>, + pub deps: Option>, pub compile_data: Option>, pub compile_data_glob: Option>, pub rustc_env: Option>, @@ -387,6 +388,7 @@ impl CrateAnnotations { gen_build_script, data, data_glob, + deps, compile_data, compile_data_glob, rustc_env, @@ -417,6 +419,7 @@ impl CrateAnnotations { default(&mut self.gen_build_script, gen_build_script); default(&mut self.data, data); default(&mut self.data_glob, data_glob); + default(&mut self.deps, deps); default(&mut self.compile_data, compile_data); default(&mut self.compile_data_glob, compile_data_glob); default(&mut self.rustc_env, rustc_env); diff --git a/crate_universe/src/metadata/metadata_annotation.rs b/crate_universe/src/metadata/metadata_annotation.rs index 1402689109..4f22dbed24 100644 --- a/crate_universe/src/metadata/metadata_annotation.rs +++ b/crate_universe/src/metadata/metadata_annotation.rs @@ -391,7 +391,7 @@ impl Annotations { // Mark that an annotation has been consumed unused_extra_annotations.remove(id); - // Fitler out the annotation + // Filter out the annotation extra }) .cloned() diff --git a/docs/crate_universe.md b/docs/crate_universe.md index 1e52b467ea..8d4e093579 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -637,8 +637,8 @@ A collection of extra attributes and settings for a particular crate | data | A list of labels to add to a crate's rust_library::data attribute. | `None` | | data_glob | A list of glob patterns to add to a crate's rust_library::data attribute. | `None` | | deps | A list of labels to add to a crate's rust_library::deps attribute. | `None` | -| extra_aliased_targets | A list of targets to add to the generated aliases in the root crate_universe repository. | `{}` | -| gen_binaries | As a list, the subset of the crate's bins that should get rust_binary targets produced. Or True to generate all, False to generate none. | `[]` | +| extra_aliased_targets | A list of targets to add to the generated aliases in the root crate_universe repository. | `None` | +| gen_binaries | As a list, the subset of the crate's bins that should get rust_binary targets produced. Or True to generate all, False to generate none. | `None` | | disable_pipelining | If True, disables pipelining for library targets for this crate. | `False` | | gen_build_script | An authorative flag to determine whether or not to produce cargo_build_script targets for the current crate. | `None` | | patch_args | The patch_args attribute of a Bazel repository rule. See [http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args) | `None` | diff --git a/examples/crate_universe/WORKSPACE.bazel b/examples/crate_universe/WORKSPACE.bazel index 1635a96e1d..70f2f59325 100644 --- a/examples/crate_universe/WORKSPACE.bazel +++ b/examples/crate_universe/WORKSPACE.bazel @@ -277,6 +277,14 @@ no_cargo_crate_repositories() crates_repository( name = "using_cxx", + annotations = { + "cxx": [ + crate.annotation( + # Until https://github.com/dtolnay/cxx/pull/1257#issuecomment-1755816850 gets resolved. + deps = [":cxx_cc"], + ), + ], + }, cargo_lockfile = "//using_cxx:Cargo.Bazel.lock", # `generator` is not necessary in official releases. # See load satement for `cargo_bazel_bootstrap`. diff --git a/examples/crate_universe/cargo_aliases/cargo-bazel-lock.json b/examples/crate_universe/cargo_aliases/cargo-bazel-lock.json index c32a5787c1..8c247655c0 100644 --- a/examples/crate_universe/cargo_aliases/cargo-bazel-lock.json +++ b/examples/crate_universe/cargo_aliases/cargo-bazel-lock.json @@ -1,5 +1,5 @@ { - "checksum": "4355f1e12d6f719741ec5cb17cd7bfceef732cf34702e21301b29b1c15377102", + "checksum": "52f60c61e76b1cb7a9142f4c92751bcf190f7836c4ef50560439c0a322d44dc6", "crates": { "aho-corasick 0.7.20": { "name": "aho-corasick", diff --git a/examples/crate_universe/multi_package/cargo-bazel-lock.json b/examples/crate_universe/multi_package/cargo-bazel-lock.json index dc33bd206c..88789e2ef2 100644 --- a/examples/crate_universe/multi_package/cargo-bazel-lock.json +++ b/examples/crate_universe/multi_package/cargo-bazel-lock.json @@ -1,5 +1,5 @@ { - "checksum": "933f3b50ddd3e6651dd0772efa2a8b3a9209ea79c7cc66ed9d82d5dc48be7c59", + "checksum": "762f9faabb2c99e97ac5af7e3cbbe30afec964cd85c203589efe0275abca78f8", "crates": { "aho-corasick 0.7.20": { "name": "aho-corasick", diff --git a/examples/crate_universe/no_cargo_manifests/cargo-bazel-lock.json b/examples/crate_universe/no_cargo_manifests/cargo-bazel-lock.json index bcb96e5910..0e9f1adac6 100644 --- a/examples/crate_universe/no_cargo_manifests/cargo-bazel-lock.json +++ b/examples/crate_universe/no_cargo_manifests/cargo-bazel-lock.json @@ -1,5 +1,5 @@ { - "checksum": "56839f1477ad6fefa9c8ba4c8822691ea0925afbf9415eae2cba7371612329eb", + "checksum": "0c441bac079b4481f5810054a2282693511a0c5582636028298e4cb49cc63695", "crates": { "async-trait 0.1.64": { "name": "async-trait", diff --git a/examples/crate_universe/using_cxx/cargo-bazel-lock.json b/examples/crate_universe/using_cxx/cargo-bazel-lock.json index b331486507..5dc76c0f19 100644 --- a/examples/crate_universe/using_cxx/cargo-bazel-lock.json +++ b/examples/crate_universe/using_cxx/cargo-bazel-lock.json @@ -1,5 +1,5 @@ { - "checksum": "8be96719f615bbe2ddff9c4bb131b70589dec6e2098e7460eee7d75f1c8ce159", + "checksum": "1c8a8ade9ae2054f346e20ad66cb1d2c0e95f4ec87cdb3299dc584df78f9b6a4", "crates": { "cc 1.0.82": { "name": "cc", @@ -84,6 +84,12 @@ ], "selects": {} }, + "extra_deps": { + "common": [ + ":cxx_cc" + ], + "selects": {} + }, "edition": "2021", "proc_macro_deps": { "common": [