Skip to content

Commit

Permalink
fix(embedded): Don't append hash to bin names
Browse files Browse the repository at this point in the history
This reduces the chance of hitting file length issues on Windows.

The hash existed for sharing a target directory.  That code isn't
implemented yet and a per-user build cache might remove the need for it,
so let's remove it for now and more carefully weigh adding it back in.
  • Loading branch information
epage committed Jun 14, 2023
1 parent d2d1811 commit b1968b8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 68 deletions.
35 changes: 1 addition & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exclude = [
[workspace.dependencies]
anyhow = "1.0.47"
base64 = "0.21.0"
blake3 = "1.3.3"
bytesize = "1.0"
cargo = { path = "" }
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
Expand Down Expand Up @@ -115,7 +114,6 @@ path = "src/cargo/lib.rs"
[dependencies]
anyhow.workspace = true
base64.workspace = true
blake3.workspace = true
bytesize.workspace = true
cargo-platform.workspace = true
cargo-util.workspace = true
Expand Down
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ allow = [
"MIT-0",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"MPL-2.0",
"Unicode-DFS-2016",
"CC0-1.0",
Expand Down
14 changes: 4 additions & 10 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ pub fn expand_manifest(
}
}
.unwrap_or_default();
let manifest = expand_manifest_(content, &manifest, path, config)
let manifest = expand_manifest_(&manifest, path, config)
.with_context(|| format!("failed to parse manifest at {}", path.display()))?;
let manifest = toml::to_string_pretty(&manifest)?;
Ok(manifest)
}

fn expand_manifest_(
content: &str,
manifest: &str,
path: &std::path::Path,
config: &Config,
Expand Down Expand Up @@ -68,8 +67,7 @@ fn expand_manifest_(
.to_string_lossy();
let separator = '_';
let name = sanitize_package_name(file_name.as_ref(), separator);
let hash = hash(content);
let bin_name = format!("{name}{separator}{hash}");
let bin_name = name.clone();
package
.entry("name".to_owned())
.or_insert(toml::Value::String(name));
Expand Down Expand Up @@ -141,10 +139,6 @@ fn sanitize_package_name(name: &str, placeholder: char) -> String {
slug
}

fn hash(content: &str) -> blake3::Hash {
blake3::hash(content.as_bytes())
}

/// Locates a "code block manifest" in Rust source.
fn extract_comment(input: &str) -> CargoResult<String> {
let re_crate_comment = regex::Regex::new(
Expand Down Expand Up @@ -357,7 +351,7 @@ mod test_expand {
fn test_default() {
snapbox::assert_eq(
r#"[[bin]]
name = "test_a472c7a31645d310613df407eab80844346938a3b8fe4f392cae059cb181aa85"
name = "test"
path = "/home/me/test.rs"
[package]
Expand All @@ -379,7 +373,7 @@ strip = true
fn test_dependencies() {
snapbox::assert_eq(
r#"[[bin]]
name = "test_3a1fa07700654ea2e893f70bb422efa7884eb1021ccacabc5466efe545da8a0b"
name = "test"
path = "/home/me/test.rs"
[dependencies]
Expand Down
36 changes: 15 additions & 21 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ args: []
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/echo_[..]`
[RUNNING] `target/debug/echo`
",
)
.run();
Expand All @@ -59,7 +59,7 @@ args: []
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/echo_[..]`
[RUNNING] `target/debug/echo`
",
)
.run();
Expand Down Expand Up @@ -113,7 +113,7 @@ args: []
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/echo_[..]`
[RUNNING] `target/debug/echo`
",
)
.run();
Expand Down Expand Up @@ -205,7 +205,7 @@ fn main() {
"\
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand Down Expand Up @@ -237,7 +237,7 @@ fn main() {
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand Down Expand Up @@ -266,7 +266,7 @@ fn main() {
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand All @@ -282,7 +282,7 @@ fn main() {
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand All @@ -300,7 +300,7 @@ fn main() {
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand Down Expand Up @@ -329,7 +329,7 @@ fn main() {
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..]`
[RUNNING] `target/debug/script`
",
)
.run();
Expand All @@ -354,7 +354,7 @@ args: ["-NotAnArg"]
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..] -NotAnArg`
[RUNNING] `target/debug/script -NotAnArg`
",
)
.run();
Expand All @@ -379,7 +379,7 @@ args: ["-NotAnArg"]
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..] -NotAnArg`
[RUNNING] `target/debug/script -NotAnArg`
",
)
.run();
Expand All @@ -404,7 +404,7 @@ args: ["--help"]
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..] --help`
[RUNNING] `target/debug/script --help`
",
)
.run();
Expand All @@ -427,14 +427,8 @@ args: []
.with_stderr(
r#"[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] s-h_w_c_ v0.0.0 ([ROOT]/foo)
[WARNING] crate `s_h_w_c__[..]` should have a snake case name
|
= help: convert the identifier to snake case: `s_h_w_c_[..]`
= note: `#[warn(non_snake_case)]` on by default
[WARNING] `s-h_w_c_` (bin "s-h_w_c__[..]") generated 1 warning
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/s-h_w_c__[..]`
[RUNNING] `target/debug/s-h_w_c_`
"#,
)
.run();
Expand Down Expand Up @@ -472,7 +466,7 @@ fn main() {
[COMPILING] script v1.0.0
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..] --help`
[RUNNING] `target/debug/script --help`
",
)
.run();
Expand Down Expand Up @@ -509,7 +503,7 @@ fn main() {
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
[COMPILING] script v0.0.0 ([ROOT]/foo)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `target/debug/script_[..] --help`
[RUNNING] `target/debug/script --help`
",
)
.run();
Expand Down

0 comments on commit b1968b8

Please sign in to comment.