Skip to content

Commit 2607cfd

Browse files
committed
feat(cli): Pull in cargo-script-mvs core logic
This is no where near the implementation we want but I think we should develop incrementally on top of what we already have. See https://github.com/epage/cargo-script-mvs/tree/main
1 parent 3ca2dca commit 2607cfd

File tree

7 files changed

+1367
-34
lines changed

7 files changed

+1367
-34
lines changed

Cargo.lock

Lines changed: 58 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exclude = [
1313
[workspace.dependencies]
1414
anyhow = "1.0.47"
1515
base64 = "0.21.0"
16+
blake3 = "1.3.3"
1617
bytesize = "1.0"
1718
cargo = { path = "" }
1819
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
@@ -66,6 +67,7 @@ pretty_env_logger = "0.4"
6667
proptest = "1.1.0"
6768
pulldown-cmark = { version = "0.9.2", default-features = false }
6869
rand = "0.8.5"
70+
regex = "1.8.3"
6971
rustfix = "0.6.0"
7072
same-file = "1.0.6"
7173
security-framework = "2.0.0"
@@ -79,6 +81,7 @@ sha2 = "0.10.6"
7981
shell-escape = "0.1.4"
8082
snapbox = { version = "0.4.0", features = ["diff", "path"] }
8183
strip-ansi-escapes = "0.1.0"
84+
syn = { version = "2.0.14", features = ["extra-traits", "full"] }
8285
tar = { version = "0.4.38", default-features = false }
8386
tempfile = "3.1.0"
8487
termcolor = "1.1.2"
@@ -112,6 +115,7 @@ path = "src/cargo/lib.rs"
112115
[dependencies]
113116
anyhow.workspace = true
114117
base64.workspace = true
118+
blake3.workspace = true
115119
bytesize.workspace = true
116120
cargo-platform.workspace = true
117121
cargo-util.workspace = true
@@ -147,7 +151,9 @@ os_info.workspace = true
147151
pasetors.workspace = true
148152
pathdiff.workspace = true
149153
pretty_env_logger = { workspace = true, optional = true }
154+
pulldown-cmark.workspace = true
150155
rand.workspace = true
156+
regex.workspace = true
151157
rustfix.workspace = true
152158
semver.workspace = true
153159
serde = { workspace = true, features = ["derive"] }
@@ -157,6 +163,7 @@ serde_json = { workspace = true, features = ["raw_value"] }
157163
sha1.workspace = true
158164
shell-escape.workspace = true
159165
strip-ansi-escapes.workspace = true
166+
syn.workspace = true
160167
tar.workspace = true
161168
tempfile.workspace = true
162169
termcolor.workspace = true

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ allow = [
106106
"MIT-0",
107107
"Apache-2.0",
108108
"BSD-3-Clause",
109+
"BSD-2-Clause",
109110
"MPL-2.0",
110111
"Unicode-DFS-2016",
111112
"CC0-1.0",

src/bin/cargo/commands/run.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::command_prelude::*;
66
use crate::util::restricted_names::is_glob_pattern;
77
use cargo::core::Verbosity;
88
use cargo::ops::{self, CompileFilter, Packages};
9+
use cargo::CargoResult;
910
use cargo_util::ProcessError;
1011

1112
pub fn cli() -> Command {
@@ -89,12 +90,54 @@ pub fn is_manifest_command(arg: &str) -> bool {
8990
1 < path.components().count() || path.extension() == Some(OsStr::new("rs"))
9091
}
9192

92-
pub fn exec_manifest_command(config: &Config, cmd: &str, _args: &[OsString]) -> CliResult {
93+
pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> CliResult {
9394
if !config.cli_unstable().script {
9495
return Err(anyhow::anyhow!("running `{cmd}` requires `-Zscript`").into());
9596
}
9697

97-
todo!("support for running manifest-commands is not yet implemented")
98+
let manifest_path = Path::new(cmd);
99+
if !manifest_path.exists() {
100+
return Err(
101+
anyhow::anyhow!("manifest `{}` does not exist", manifest_path.display()).into(),
102+
);
103+
}
104+
let manifest_path = crate::util::try_canonicalize(manifest_path)?;
105+
let script = cargo::util::toml::embedded::RawScript::parse_from(&manifest_path)?;
106+
let ws = script.to_workspace(config)?;
107+
108+
let compile_opts = default_compile_opts(config)?;
109+
110+
cargo::ops::run(&ws, &compile_opts, args).map_err(|err| to_run_error(config, err))
111+
}
112+
113+
fn default_compile_opts(config: &Config) -> CargoResult<cargo::ops::CompileOptions> {
114+
let mut build_config = cargo::core::compiler::BuildConfig::new(
115+
config,
116+
None,
117+
false,
118+
&[],
119+
cargo::core::compiler::CompileMode::Build,
120+
)?;
121+
build_config.requested_profile = cargo::util::interning::InternedString::new("dev");
122+
let compile_opts = cargo::ops::CompileOptions {
123+
build_config,
124+
cli_features: cargo::core::resolver::features::CliFeatures::from_command_line(
125+
&[],
126+
false,
127+
true,
128+
)?,
129+
spec: cargo::ops::Packages::Default,
130+
filter: cargo::ops::CompileFilter::Default {
131+
required_features_filterable: false,
132+
},
133+
target_rustdoc_args: None,
134+
target_rustc_args: None,
135+
target_rustc_crate_types: None,
136+
rustdoc_document_private_items: false,
137+
honor_rust_version: true,
138+
};
139+
140+
Ok(compile_opts)
98141
}
99142

100143
fn to_run_error(config: &cargo::util::Config, err: anyhow::Error) -> CliError {

0 commit comments

Comments
 (0)