Skip to content

Commit 0d5370a

Browse files
committed
Auto merge of #12268 - epage:direct, r=weihanglo
fix(embedded): Don't create an intermediate manifest ### What does this PR try to resolve? More immediately, this is to unblock rust-lang/rust#112601 More generally, this gets us away from hackily writing out an out-of-line manifest from an embedded manifest. To parse the manifest, we have to write it out so our regular manifest loading code could handle it. This updates the manifest parsing code to handle it. This doesn't mean this will work everywhere in all cases though. For example, ephemeral workspaces parses a manifest from the SourceId and these won't have valid SourceIds. As a consequence, `Cargo.lock` and `CARGO_TARGET_DIR` are changing from being next to the temp manifest to being next to the script. This still isn't the desired behavior but stepping stones. ### How should we test and review this PR? A Commit at a time ### Additional information In production code, this does not conflict with #12255 (due to #12262) but in test code, it does.
2 parents a581ca2 + 224d2e6 commit 0d5370a

File tree

10 files changed

+169
-279
lines changed

10 files changed

+169
-279
lines changed

Cargo.lock

+1-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ exclude = [
1313
[workspace.dependencies]
1414
anyhow = "1.0.47"
1515
base64 = "0.21.0"
16-
blake3 = "1.3.3"
1716
bytesize = "1.0"
1817
cargo = { path = "" }
1918
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
@@ -114,7 +113,6 @@ path = "src/cargo/lib.rs"
114113
[dependencies]
115114
anyhow.workspace = true
116115
base64.workspace = true
117-
blake3.workspace = true
118116
bytesize.workspace = true
119117
cargo-platform.workspace = true
120118
cargo-util.workspace = true

deny.toml

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ allow = [
106106
"MIT-0",
107107
"Apache-2.0",
108108
"BSD-3-Clause",
109-
"BSD-2-Clause",
110109
"MPL-2.0",
111110
"Unicode-DFS-2016",
112111
"CC0-1.0",

src/bin/cargo/commands/run.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::Path;
55
use crate::command_prelude::*;
66
use crate::util::restricted_names::is_glob_pattern;
77
use cargo::core::Verbosity;
8+
use cargo::core::Workspace;
89
use cargo::ops::{self, CompileFilter, Packages};
910
use cargo_util::ProcessError;
1011

@@ -95,14 +96,19 @@ pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> C
9596
}
9697

9798
let manifest_path = Path::new(cmd);
99+
let manifest_path = config.cwd().join(manifest_path);
100+
let manifest_path = cargo_util::paths::normalize_path(&manifest_path);
98101
if !manifest_path.exists() {
99-
return Err(
100-
anyhow::anyhow!("manifest `{}` does not exist", manifest_path.display()).into(),
101-
);
102+
return Err(anyhow::format_err!(
103+
"manifest path `{}` does not exist",
104+
manifest_path.display()
105+
)
106+
.into());
107+
}
108+
let mut ws = Workspace::new(&manifest_path, config)?;
109+
if config.cli_unstable().avoid_dev_deps {
110+
ws.set_require_optional_deps(false);
102111
}
103-
let manifest_path = crate::util::try_canonicalize(manifest_path)?;
104-
let script = cargo::util::toml::embedded::parse_from(&manifest_path)?;
105-
let ws = cargo::util::toml::embedded::to_workspace(&script, config)?;
106112

107113
let mut compile_opts =
108114
cargo::ops::CompileOptions::new(config, cargo::core::compiler::CompileMode::Build)?;

src/cargo/core/manifest.rs

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct Manifest {
6464
metabuild: Option<Vec<String>>,
6565
resolve_behavior: Option<ResolveBehavior>,
6666
lint_rustflags: Vec<String>,
67+
embedded: bool,
6768
}
6869

6970
/// When parsing `Cargo.toml`, some warnings should silenced
@@ -407,6 +408,7 @@ impl Manifest {
407408
metabuild: Option<Vec<String>>,
408409
resolve_behavior: Option<ResolveBehavior>,
409410
lint_rustflags: Vec<String>,
411+
embedded: bool,
410412
) -> Manifest {
411413
Manifest {
412414
summary,
@@ -433,6 +435,7 @@ impl Manifest {
433435
metabuild,
434436
resolve_behavior,
435437
lint_rustflags,
438+
embedded,
436439
}
437440
}
438441

@@ -500,6 +503,9 @@ impl Manifest {
500503
pub fn links(&self) -> Option<&str> {
501504
self.links.as_deref()
502505
}
506+
pub fn is_embedded(&self) -> bool {
507+
self.embedded
508+
}
503509

504510
pub fn workspace_config(&self) -> &WorkspaceConfig {
505511
&self.workspace

src/cargo/core/workspace.rs

+11
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ impl<'cfg> Workspace<'cfg> {
726726
if self.members.contains(&manifest_path) {
727727
return Ok(());
728728
}
729+
if is_path_dep && self.root_maybe().is_embedded() {
730+
// Embedded manifests cannot have workspace members
731+
return Ok(());
732+
}
729733
if is_path_dep
730734
&& !manifest_path.parent().unwrap().starts_with(self.root())
731735
&& self.find_root(&manifest_path)? != self.root_manifest
@@ -1580,6 +1584,13 @@ impl MaybePackage {
15801584
MaybePackage::Virtual(ref vm) => vm.workspace_config(),
15811585
}
15821586
}
1587+
1588+
fn is_embedded(&self) -> bool {
1589+
match self {
1590+
MaybePackage::Package(p) => p.manifest().is_embedded(),
1591+
MaybePackage::Virtual(_) => false,
1592+
}
1593+
}
15831594
}
15841595

15851596
impl WorkspaceRootConfig {

src/cargo/ops/cargo_package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
393393
let package_root = orig_pkg.root();
394394
let source_id = orig_pkg.package_id().source_id();
395395
let (manifest, _nested_paths) =
396-
TomlManifest::to_real_manifest(&toml_manifest, source_id, package_root, config)?;
396+
TomlManifest::to_real_manifest(&toml_manifest, false, source_id, package_root, config)?;
397397
let new_pkg = Package::new(manifest, orig_pkg.manifest_path());
398398

399399
// Regenerate Cargo.lock using the old one as a guide.

0 commit comments

Comments
 (0)