Skip to content

Commit a15e67d

Browse files
authored
Deleted "extra workspace member" functionality from crate_universe (#1406)
* Deleted "extra workspace member" functionality from crate_universe * Regenerate documentation
1 parent 5910a75 commit a15e67d

15 files changed

Lines changed: 72 additions & 3912 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,13 @@ tasks:
333333
# failing. This is likely an issue with the windows workers in CI.
334334
- "-//vendor_local_pkgs/..."
335335
- "-//vendor_remote_pkgs/..."
336-
- "-//extra_workspace_members/..."
337336
- "-//no_cargo_manifests/..."
338337
test_targets:
339338
- "//..."
340339
# TODO: Temporarily disable this windows build as it recently started
341340
# failing. This is likely an issue with the windows workers in CI.
342341
- "-//vendor_local_pkgs/..."
343342
- "-//vendor_remote_pkgs/..."
344-
- "-//extra_workspace_members/..."
345343
- "-//no_cargo_manifests/..."
346344
buildifier:
347345
version: latest

crate_universe/private/crates_repository.bzl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,6 @@ CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index
175175
"cargo_config": attr.label(
176176
doc = "A [Cargo configuration](https://doc.rust-lang.org/cargo/reference/config.html) file",
177177
),
178-
"extra_workspace_member_url_template": attr.string(
179-
doc = "The registry url to use when fetching extra workspace members",
180-
default = "https://crates.io/api/v1/crates/{name}/{version}/download",
181-
),
182-
"extra_workspace_members": attr.string_dict(
183-
doc = (
184-
"Additional crates to download and include as a workspace member. This is unfortunately required in " +
185-
"order to add information about \"binary-only\" crates so that a `rust_binary` may be generated for " +
186-
"it. [rust-lang/cargo#9096](https://github.com/rust-lang/cargo/issues/9096) tracks an RFC which may " +
187-
"solve for this."
188-
),
189-
),
190178
"generate_build_scripts": attr.bool(
191179
doc = (
192180
"Whether or not to generate " +

crate_universe/private/crates_vendor.bzl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,6 @@ def _write_splicing_manifest(ctx):
120120
runfiles = [manifest] + ctx.files.manifests + ([ctx.file.cargo_config] if ctx.attr.cargo_config else [])
121121
return args, runfiles
122122

123-
def _write_extra_manifests_manifest(ctx):
124-
manifest = _write_data_file(
125-
ctx = ctx,
126-
name = "cargo-bazel-extra-manifests-manifest.json",
127-
data = json.encode(struct(
128-
# TODO: This is for extra workspace members
129-
manifests = [],
130-
)),
131-
)
132-
is_windows = _is_windows(ctx)
133-
args = ["--extra-manifests-manifest", _runfiles_path(manifest.short_path, is_windows)]
134-
runfiles = [manifest]
135-
return args, runfiles
136-
137123
def _write_config_file(ctx):
138124
rendering_config = dict(json.decode(render_config()))
139125

@@ -219,11 +205,6 @@ def _crates_vendor_impl(ctx):
219205
args.extend(splicing_manifest_args)
220206
cargo_bazel_runfiles.extend(splicing_manifest_runfiles)
221207

222-
# Generate extra-manifests manifest
223-
extra_manifests_manifest_args, extra_manifests_manifest_runfiles = _write_extra_manifests_manifest(ctx)
224-
args.extend(extra_manifests_manifest_args)
225-
cargo_bazel_runfiles.extend(extra_manifests_manifest_runfiles)
226-
227208
# Optionally include buildifier
228209
if ctx.attr.buildifier:
229210
args.extend(["--buildifier", _runfiles_path(ctx.executable.buildifier.short_path, is_windows)])

crate_universe/private/splicing_utils.bzl

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,6 @@ def splicing_config(resolver_version = "1"):
2121
resolver_version = resolver_version,
2222
))
2323

24-
def download_extra_workspace_members(repository_ctx, cache_dir, render_template_registry_url):
25-
"""Download additional workspace members for use in splicing.
26-
27-
Args:
28-
repository_ctx (repository_ctx): The rule's context object.
29-
cache_dir (path): A directory in which to download and extract extra workspace members
30-
render_template_registry_url (str): The base template to use for determining the crate's registry URL.
31-
32-
Returns:
33-
list: A list of information related to the downloaded crates
34-
- manifest: The path of the manifest.
35-
- url: The url the manifest came from.
36-
- sha256: The sha256 checksum of the new manifest.
37-
"""
38-
manifests = []
39-
extra_workspace_members = repository_ctx.attr.extra_workspace_members
40-
if extra_workspace_members:
41-
repository_ctx.report_progress("Downloading extra workspace members.")
42-
43-
for name, spec in repository_ctx.attr.extra_workspace_members.items():
44-
spec = struct(**json.decode(spec))
45-
46-
url = render_template_registry_url
47-
url = url.replace("{name}", name)
48-
url = url.replace("{version}", spec.version)
49-
50-
if spec.sha256:
51-
result = repository_ctx.download_and_extract(
52-
output = cache_dir,
53-
url = url,
54-
sha256 = spec.sha256,
55-
type = "tar.gz",
56-
)
57-
else:
58-
result = repository_ctx.download_and_extract(
59-
output = cache_dir,
60-
url = url,
61-
type = "tar.gz",
62-
)
63-
64-
manifest = repository_ctx.path("{}/{}-{}/Cargo.toml".format(
65-
cache_dir,
66-
name,
67-
spec.version,
68-
))
69-
70-
if not manifest.exists:
71-
fail("Extra workspace member '{}' has no root Cargo.toml file".format(name))
72-
73-
manifests.append(struct(
74-
manifest = str(manifest),
75-
url = url,
76-
sha256 = result.sha256,
77-
))
78-
79-
return manifests
80-
8124
def kebab_case_keys(data):
8225
"""Ensure the key value of the data given are kebab-case
8326
@@ -183,22 +126,6 @@ def splice_workspace_manifest(repository_ctx, generator, lockfile, splicing_mani
183126
repository_ctx.report_progress("Splicing Cargo workspace.")
184127
repo_dir = repository_ctx.path(".")
185128

186-
# Download extra workspace members
187-
crates_cache_dir = repository_ctx.path("{}/.crates_cache".format(repo_dir))
188-
extra_manifest_info = download_extra_workspace_members(
189-
repository_ctx = repository_ctx,
190-
cache_dir = crates_cache_dir,
191-
render_template_registry_url = repository_ctx.attr.extra_workspace_member_url_template,
192-
)
193-
194-
extra_manifests_manifest = repository_ctx.path("{}/extra_manifests_manifest.json".format(repo_dir))
195-
repository_ctx.file(
196-
extra_manifests_manifest,
197-
json.encode_indent(struct(
198-
manifests = extra_manifest_info,
199-
), indent = " " * 4),
200-
)
201-
202129
splicing_output_dir = repository_ctx.path("splicing-output")
203130

204131
# Generate a workspace root which contains all workspace members
@@ -209,8 +136,6 @@ def splice_workspace_manifest(repository_ctx, generator, lockfile, splicing_mani
209136
splicing_output_dir,
210137
"--splicing-manifest",
211138
splicing_manifest,
212-
"--extra-manifests-manifest",
213-
extra_manifests_manifest,
214139
"--cargo",
215140
cargo,
216141
"--rustc",

crate_universe/src/cli/splice.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use clap::Parser;
77

88
use crate::cli::Result;
99
use crate::metadata::{write_metadata, Generator, MetadataGenerator};
10-
use crate::splicing::{
11-
generate_lockfile, ExtraManifestsManifest, Splicer, SplicingManifest, WorkspaceMetadata,
12-
};
10+
use crate::splicing::{generate_lockfile, Splicer, SplicingManifest, WorkspaceMetadata};
1311

1412
/// Command line options for the `splice` subcommand
1513
#[derive(Parser, Debug)]
@@ -19,10 +17,6 @@ pub struct SpliceOptions {
1917
#[clap(long)]
2018
pub splicing_manifest: PathBuf,
2119

22-
/// A generated manifest of "extra workspace members"
23-
#[clap(long)]
24-
pub extra_manifests_manifest: PathBuf,
25-
2620
/// A Cargo lockfile (Cargo.lock).
2721
#[clap(long)]
2822
pub cargo_lockfile: Option<PathBuf>,
@@ -57,8 +51,6 @@ pub struct SpliceOptions {
5751
pub fn splice(opt: SpliceOptions) -> Result<()> {
5852
// Load the all config files required for splicing a workspace
5953
let splicing_manifest = SplicingManifest::try_from_path(&opt.splicing_manifest)?;
60-
let extra_manifests_manifest =
61-
ExtraManifestsManifest::try_from_path(opt.extra_manifests_manifest)?;
6254

6355
// Determine the splicing workspace
6456
let temp_dir;
@@ -71,7 +63,7 @@ pub fn splice(opt: SpliceOptions) -> Result<()> {
7163
};
7264

7365
// Generate a splicer for creating a Cargo workspace manifest
74-
let splicer = Splicer::new(splicing_dir, splicing_manifest, extra_manifests_manifest)?;
66+
let splicer = Splicer::new(splicing_dir, splicing_manifest)?;
7567

7668
// Splice together the manifest
7769
let manifest_path = splicer.splice_workspace()?;

crate_universe/src/cli/vendor.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use crate::context::Context;
1414
use crate::metadata::{Annotations, VendorGenerator};
1515
use crate::metadata::{Generator, MetadataGenerator};
1616
use crate::rendering::{render_module_label, write_outputs, Renderer};
17-
use crate::splicing::{
18-
generate_lockfile, ExtraManifestsManifest, Splicer, SplicingManifest, WorkspaceMetadata,
19-
};
17+
use crate::splicing::{generate_lockfile, Splicer, SplicingManifest, WorkspaceMetadata};
2018

2119
/// Command line options for the `vendor` subcommand
2220
#[derive(Parser, Debug)]
@@ -55,10 +53,6 @@ pub struct VendorOptions {
5553
#[clap(long)]
5654
pub metadata: Option<PathBuf>,
5755

58-
/// A generated manifest of "extra workspace members"
59-
#[clap(long)]
60-
pub extra_manifests_manifest: PathBuf,
61-
6256
/// The path to a bazel binary
6357
#[clap(long, env = "BAZEL_REAL", default_value = "bazel")]
6458
pub bazel: PathBuf,
@@ -117,18 +111,12 @@ pub fn vendor(opt: VendorOptions) -> Result<()> {
117111
// Load the all config files required for splicing a workspace
118112
let splicing_manifest = SplicingManifest::try_from_path(&opt.splicing_manifest)?
119113
.resolve(&opt.workspace_dir, &output_base);
120-
let extra_manifests_manifest =
121-
ExtraManifestsManifest::try_from_path(opt.extra_manifests_manifest)?.absolutize();
122114

123115
let temp_dir = tempfile::tempdir().context("Failed to create temporary directory")?;
124116

125117
// Generate a splicer for creating a Cargo workspace manifest
126-
let splicer = Splicer::new(
127-
PathBuf::from(temp_dir.as_ref()),
128-
splicing_manifest,
129-
extra_manifests_manifest,
130-
)
131-
.context("Failed to create splicer")?;
118+
let splicer = Splicer::new(PathBuf::from(temp_dir.as_ref()), splicing_manifest)
119+
.context("Failed to create splicer")?;
132120

133121
// Splice together the manifest
134122
let manifest_path = splicer

crate_universe/src/splicing.rs

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,9 @@ use crate::utils::starlark::Label;
2121
use self::cargo_config::CargoConfig;
2222
pub use self::splicer::*;
2323

24-
#[derive(Debug, Default, Serialize, Deserialize)]
25-
pub struct ExtraManifestInfo {
26-
// The path to a Cargo Manifest
27-
pub manifest: PathBuf,
28-
29-
// The URL where the manifest's package can be downloaded
30-
pub url: String,
31-
32-
// The Sha256 checksum of the downloaded package located at `url`.
33-
pub sha256: String,
34-
}
35-
3624
type DirectPackageManifest = BTreeMap<String, cargo_toml::DependencyDetail>;
3725

26+
/// A collection of information used for splicing together a new Cargo manifest.
3827
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
3928
#[serde(deny_unknown_fields)]
4029
pub struct SplicingManifest {
@@ -104,6 +93,7 @@ impl SplicingManifest {
10493
}
10594
}
10695

96+
/// The result of fully resolving a [SplicingManifest] in preparation for splicing.
10797
#[derive(Debug, Serialize, Default)]
10898
pub struct SplicingMetadata {
10999
/// A set of all packages directly written to the rule
@@ -149,32 +139,6 @@ impl TryFrom<SplicingManifest> for SplicingMetadata {
149139
}
150140
}
151141

152-
/// A collection of information required for reproducible "extra worksspace members".
153-
#[derive(Debug, Default, Serialize, Deserialize)]
154-
#[serde(deny_unknown_fields)]
155-
pub struct ExtraManifestsManifest {
156-
pub manifests: Vec<ExtraManifestInfo>,
157-
}
158-
159-
impl FromStr for ExtraManifestsManifest {
160-
type Err = serde_json::Error;
161-
162-
fn from_str(s: &str) -> Result<Self, Self::Err> {
163-
serde_json::from_str(s)
164-
}
165-
}
166-
167-
impl ExtraManifestsManifest {
168-
pub fn try_from_path<T: AsRef<Path>>(path: T) -> Result<Self> {
169-
let content = fs::read_to_string(path.as_ref())?;
170-
Self::from_str(&content).context("Failed to load ExtraManifestsManifest")
171-
}
172-
173-
pub fn absolutize(self) -> Self {
174-
self
175-
}
176-
}
177-
178142
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
179143
pub struct SourceInfo {
180144
/// A url where to a `.crate` file.
@@ -229,30 +193,9 @@ impl TryFrom<serde_json::Value> for WorkspaceMetadata {
229193
impl WorkspaceMetadata {
230194
fn new(
231195
splicing_manifest: &SplicingManifest,
232-
extra_manifests_manifest: &ExtraManifestsManifest,
233-
injected_manifests: HashMap<&PathBuf, String>,
196+
member_manifests: HashMap<&PathBuf, String>,
234197
) -> Result<Self> {
235-
let mut sources = BTreeMap::new();
236-
237-
for config in extra_manifests_manifest.manifests.iter() {
238-
let package = match read_manifest(&config.manifest) {
239-
Ok(manifest) => match manifest.package {
240-
Some(pkg) => pkg,
241-
None => continue,
242-
},
243-
Err(e) => return Err(e),
244-
};
245-
246-
let id = CrateId::new(package.name, package.version);
247-
let info = SourceInfo {
248-
url: config.url.clone(),
249-
sha256: config.sha256.clone(),
250-
};
251-
252-
sources.insert(id, info);
253-
}
254-
255-
let mut package_prefixes: BTreeMap<String, String> = injected_manifests
198+
let mut package_prefixes: BTreeMap<String, String> = member_manifests
256199
.iter()
257200
.filter_map(|(original_manifest, cargo_pkg_name)| {
258201
let label = match splicing_manifest.manifests.get(*original_manifest) {
@@ -287,7 +230,7 @@ impl WorkspaceMetadata {
287230
.collect();
288231

289232
Ok(Self {
290-
sources,
233+
sources: BTreeMap::new(),
291234
workspace_prefix,
292235
package_prefixes,
293236
})

0 commit comments

Comments
 (0)