Skip to content

Commit a6b3d27

Browse files
committed
fix(embedded): Don't create an intermediate 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. This also exposes the fact that we didn't disable `autobins` like the documentation says we should.
1 parent 94234b3 commit a6b3d27

File tree

10 files changed

+109
-273
lines changed

10 files changed

+109
-273
lines changed

Cargo.lock

Lines changed: 1 addition & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
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" }
@@ -115,7 +114,6 @@ path = "src/cargo/lib.rs"
115114
[dependencies]
116115
anyhow.workspace = true
117116
base64.workspace = true
118-
blake3.workspace = true
119117
bytesize.workspace = true
120118
cargo-platform.workspace = true
121119
cargo-util.workspace = true

deny.toml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 2 deletions
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

@@ -101,8 +102,10 @@ pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> C
101102
);
102103
}
103104
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)?;
105+
let mut ws = Workspace::new(&manifest_path, config)?;
106+
if config.cli_unstable().avoid_dev_deps {
107+
ws.set_require_optional_deps(false);
108+
}
106109

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

src/cargo/core/manifest.rs

Lines changed: 6 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)