Skip to content

Commit c8a15f3

Browse files
committed
fix(publish): Don't generate final artifacts
1 parent 474598e commit c8a15f3

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn create_package(
160160
}
161161

162162
let filename = pkg.package_id().tarball_name();
163-
let dir = ws.target_dir().join("package");
163+
let dir = ws.build_dir().join("package");
164164
let mut dst = {
165165
let tmp = format!(".{}", filename);
166166
dir.open_rw_exclusive_create(&tmp, gctx, "package scratch space")?
@@ -220,7 +220,22 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
220220
let packaged = do_package(ws, opts, pkgs)?;
221221

222222
let mut result = Vec::new();
223-
result.extend(packaged.into_iter().map(|(_, _, src)| src));
223+
let target_dir = ws.target_dir();
224+
let build_dir = ws.build_dir();
225+
if target_dir == build_dir {
226+
result.extend(packaged.into_iter().map(|(_, _, src)| src));
227+
} else {
228+
// Uplifting artifacts
229+
let artifact_dir = target_dir.join("package");
230+
for (pkg, _, src) in packaged {
231+
let filename = pkg.package_id().tarball_name();
232+
let dst =
233+
artifact_dir.open_rw_exclusive_create(filename, ws.gctx(), "uplifted package")?;
234+
src.file().seek(SeekFrom::Start(0))?;
235+
std::io::copy(&mut src.file(), &mut dst.file())?;
236+
result.push(dst);
237+
}
238+
}
224239

225240
Ok(result)
226241
}

src/doc/src/reference/build-cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ the `target` directory:
6262
Directory | Description
6363
----------|------------
6464
<code style="white-space: nowrap">target/doc/</code> | Contains rustdoc documentation ([`cargo doc`]).
65-
<code style="white-space: nowrap">target/package/</code> | Contains the output of the [`cargo package`] and [`cargo publish`] commands.
65+
<code style="white-space: nowrap">target/package/</code> | Contains the output of the [`cargo package`].
6666

6767
Cargo also creates several other directories and files in the build-dir needed for the build
6868
process. The build-dir layout is considered internal to Cargo, and is subject to

tests/testsuite/build_dir.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ fn cargo_publish_should_only_touch_build_dir() {
384384
assert_build_dir_layout(p.root().join("build-dir"), "debug");
385385

386386
let package_artifact_dir = p.root().join("target-dir/package");
387-
assert_exists(&package_artifact_dir);
388-
assert_exists(&package_artifact_dir.join("foo-0.0.1.crate"));
389-
assert!(package_artifact_dir.join("foo-0.0.1.crate").is_file());
387+
assert!(!package_artifact_dir.exists());
390388

391389
let package_build_dir = p.root().join("build-dir/package");
392390
assert_exists(&package_build_dir);

0 commit comments

Comments
 (0)