Skip to content

Commit 9557a7e

Browse files
committed
add logging on target-specs writing
1 parent babb489 commit 9557a7e

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

crates/cargo-gpu/src/install.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::spirv_source::{
77
use crate::{cache_dir, spirv_source::SpirvSource};
88
use anyhow::Context as _;
99
use cargo_metadata::Metadata;
10-
use log::{info, trace};
1110
use spirv_builder::SpirvBuilder;
1211
use std::path::{Path, PathBuf};
1312

@@ -162,14 +161,14 @@ impl Install {
162161
);
163162

164163
{
165-
trace!("writing dummy lib.rs");
164+
log::trace!("writing dummy lib.rs");
166165
let src = checkout.join("src");
167166
std::fs::create_dir_all(&src).context("creating 'src' directory")?;
168167
std::fs::File::create(src.join("lib.rs")).context("creating 'src/lib.rs'")?;
169168
};
170169

171170
{
172-
trace!("writing dummy Cargo.toml");
171+
log::trace!("writing dummy Cargo.toml");
173172
let version_spec = match &source {
174173
SpirvSource::CratesIO(version) => {
175174
format!("version = \"{version}\"")
@@ -206,11 +205,6 @@ package = "rustc_codegen_spirv"
206205

207206
/// Copy spec files from one dir to another, assuming no subdirectories
208207
fn copy_spec_files(src: &Path, dst: &Path) -> anyhow::Result<()> {
209-
info!(
210-
"Copy target specs from {:?} to {:?}",
211-
src.display(),
212-
dst.display()
213-
);
214208
std::fs::create_dir_all(dst)?;
215209
let dir = std::fs::read_dir(src)?;
216210
for dir_entry in dir {
@@ -225,7 +219,6 @@ package = "rustc_codegen_spirv"
225219

226220
/// Add the target spec files to the crate.
227221
fn update_spec_files(
228-
&self,
229222
source: &SpirvSource,
230223
install_dir: &Path,
231224
dummy_metadata: &Metadata,
@@ -236,6 +229,11 @@ package = "rustc_codegen_spirv"
236229
if let Ok(target_specs) =
237230
dummy_metadata.find_package("rustc_codegen_spirv-target-specs")
238231
{
232+
log::info!(
233+
"target-specs: found crate `rustc_codegen_spirv-target-specs` with manifest at `{}`",
234+
target_specs.manifest_path
235+
);
236+
239237
let target_specs_src = target_specs
240238
.manifest_path
241239
.as_std_path()
@@ -247,9 +245,17 @@ package = "rustc_codegen_spirv"
247245
.context("Could not find `target-specs` directory within `rustc_codegen_spirv-target-specs` dependency")?;
248246
if source.is_path() {
249247
// skip copy
248+
log::info!(
249+
"target-specs: source is local path, use target-specs from {}",
250+
target_specs_src.display()
251+
);
250252
target_specs_dst = target_specs_src;
251253
} else {
252254
// copy over the target-specs
255+
log::info!(
256+
"target-specs: Copy target specs from {}",
257+
target_specs_src.display()
258+
);
253259
Self::copy_spec_files(&target_specs_src, &target_specs_dst)
254260
.context("copying target-specs json files")?;
255261
}
@@ -263,7 +269,11 @@ package = "rustc_codegen_spirv"
263269
// and hope parallel runs don't shred each other
264270
target_specs_dst = cache_dir()?.join("legacy-target-specs-for-local-checkout");
265271
}
266-
write_legacy_target_specs(&target_specs_dst, self.rebuild_codegen)?;
272+
log::info!(
273+
"target-specs: Writing legacy target specs to {}",
274+
target_specs_dst.display()
275+
);
276+
write_legacy_target_specs(&target_specs_dst)?;
267277
}
268278
}
269279

@@ -335,9 +345,9 @@ package = "rustc_codegen_spirv"
335345
log::info!("selected toolchain channel `{toolchain_channel:?}`");
336346

337347
log::debug!("update_spec_files");
338-
let target_spec_dir = self
339-
.update_spec_files(&source, &install_dir, &dummy_metadata, skip_rebuild)
340-
.context("writing target spec files")?;
348+
let target_spec_dir =
349+
Self::update_spec_files(&source, &install_dir, &dummy_metadata, skip_rebuild)
350+
.context("writing target spec files")?;
341351

342352
if !skip_rebuild {
343353
log::debug!("ensure_toolchain_and_components_exist");

crates/cargo-gpu/src/legacy_target_specs.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@
44
//! introduced before the first target spec update.
55
66
use anyhow::Context as _;
7-
use log::info;
87
use std::path::Path;
98

109
/// Extract legacy target specs from our executable into some directory
11-
pub fn write_legacy_target_specs(target_spec_dir: &Path, rebuild: bool) -> anyhow::Result<()> {
12-
info!(
13-
"Writing legacy target specs to {}",
14-
target_spec_dir.display()
15-
);
10+
pub fn write_legacy_target_specs(target_spec_dir: &Path) -> anyhow::Result<()> {
1611
std::fs::create_dir_all(target_spec_dir)?;
1712
for (filename, contents) in legacy_target_specs::TARGET_SPECS {
1813
let path = target_spec_dir.join(filename);
19-
if !path.is_file() || rebuild {
20-
std::fs::write(&path, contents.as_bytes()).with_context(|| {
21-
format!("writing legacy target spec file at [{}]", path.display())
22-
})?;
23-
}
14+
std::fs::write(&path, contents.as_bytes())
15+
.with_context(|| format!("writing legacy target spec file at [{}]", path.display()))?;
2416
}
2517
Ok(())
2618
}

0 commit comments

Comments
 (0)