Skip to content

Commit c2152f0

Browse files
committed
Delete rmeta files for rlibs during cargo clean
1 parent 8f032b3 commit c2152f0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
use std::fs;
33
use std::path::Path;
44

5-
use crate::core::compiler::UnitInterner;
5+
use crate::core::compiler::{UnitInterner, FileFlavor};
66
use crate::core::compiler::{BuildConfig, BuildContext, CompileMode, Context, Kind};
77
use crate::core::profiles::UnitFor;
88
use crate::core::Workspace;
@@ -119,6 +119,9 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
119119
if let Some(ref dst) = output.hardlink {
120120
rm_rf(dst, config)?;
121121
}
122+
if let FileFlavor::Linkable { rmeta } = &output.flavor {
123+
rm_rf(rmeta, config)?;
124+
}
122125
}
123126
}
124127

tests/testsuite/clean.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,26 @@ fn clean_verbose() {
294294
.run();
295295
p.cargo("build").run();
296296
}
297+
298+
#[test]
299+
fn clean_remove_rlib_rmeta() {
300+
let p = project()
301+
.file(
302+
"Cargo.toml",
303+
r#"
304+
[package]
305+
name = "foo"
306+
version = "0.0.1"
307+
"#,
308+
)
309+
.file("src/lib.rs", "")
310+
.build();
311+
312+
p.cargo("build").run();
313+
assert!(p.target_debug_dir().join("libfoo.rlib").exists());
314+
let rmeta = p.glob("target/debug/deps/*.rmeta").next().unwrap().unwrap();
315+
assert!(rmeta.exists());
316+
p.cargo("clean -p foo").run();
317+
assert!(!p.target_debug_dir().join("libfoo.rlib").exists());
318+
assert!(!rmeta.exists());
319+
}

0 commit comments

Comments
 (0)