diff --git a/Cargo.lock b/Cargo.lock index c5c4082..4bf2427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,7 +111,6 @@ dependencies = [ "env_logger", "log", "relative-path", - "rustc_codegen_spirv-target-specs", "semver", "serde", "serde_json", @@ -1027,21 +1026,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_codegen_spirv-target-specs" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c89eaf493b3dfc730cda42a77014aad65e03213992c7afe0dff60a9f7d3dd94" - [[package]] name = "rustc_codegen_spirv-types" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=e97524f6b4816056b3edaa70c3e0e0c656392c05#e97524f6b4816056b3edaa70c3e0e0c656392c05" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=823b0c275e3eb8ab44ada5a6d989bdb57e8f9409#823b0c275e3eb8ab44ada5a6d989bdb57e8f9409" dependencies = [ "rspirv", + "semver", "serde", "serde_json", "spirv", + "thiserror", ] [[package]] @@ -1216,7 +1211,7 @@ dependencies = [ [[package]] name = "spirv-builder" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=e97524f6b4816056b3edaa70c3e0e0c656392c05#e97524f6b4816056b3edaa70c3e0e0c656392c05" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=823b0c275e3eb8ab44ada5a6d989bdb57e8f9409#823b0c275e3eb8ab44ada5a6d989bdb57e8f9409" dependencies = [ "cargo_metadata", "clap", diff --git a/Cargo.toml b/Cargo.toml index de7d918..7c66d0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ exclude = [ resolver = "2" [workspace.dependencies] -spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "e97524f6b4816056b3edaa70c3e0e0c656392c05", default-features = false } +spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "823b0c275e3eb8ab44ada5a6d989bdb57e8f9409", default-features = false } anyhow = "1.0.98" clap = { version = "4.5.41", features = ["derive"] } crossterm = "0.29.0" @@ -33,9 +33,6 @@ cargo-util-schemas = "0.8.2" semver = "1.0.26" dunce = "1.0.5" -# This crate MUST NEVER be upgraded, we need this particular "first" version to support old rust-gpu builds -legacy_target_specs = { package = "rustc_codegen_spirv-target-specs", version = "0.9.0", features = ["include_str"] } - [workspace.lints.rust] missing_docs = "warn" diff --git a/crates/cargo-gpu/Cargo.toml b/crates/cargo-gpu/Cargo.toml index ba88383..81c8a87 100644 --- a/crates/cargo-gpu/Cargo.toml +++ b/crates/cargo-gpu/Cargo.toml @@ -14,7 +14,6 @@ default-run = "cargo-gpu" cargo_metadata.workspace = true anyhow.workspace = true spirv-builder = { workspace = true, features = ["clap", "watch"] } -legacy_target_specs.workspace = true clap.workspace = true directories.workspace = true env_logger.workspace = true diff --git a/crates/cargo-gpu/src/install.rs b/crates/cargo-gpu/src/install.rs index c66c6b6..c9ea0ec 100644 --- a/crates/cargo-gpu/src/install.rs +++ b/crates/cargo-gpu/src/install.rs @@ -3,7 +3,6 @@ use crate::spirv_source::{ get_channel_from_rustc_codegen_spirv_build_script, query_metadata, FindPackage as _, }; -use crate::target_specs::update_target_specs_files; use crate::{cache_dir, spirv_source::SpirvSource}; use anyhow::Context as _; use spirv_builder::SpirvBuilder; @@ -17,8 +16,6 @@ pub struct InstalledBackend { pub rustc_codegen_spirv_location: PathBuf, /// toolchain channel name pub toolchain_channel: String, - /// directory with target-specs json files - pub target_spec_dir: PathBuf, } impl InstalledBackend { @@ -48,10 +45,6 @@ impl InstalledBackend { pub fn configure_spirv_builder(&self, builder: &mut SpirvBuilder) -> anyhow::Result<()> { builder.rustc_codegen_spirv_location = Some(self.rustc_codegen_spirv_location.clone()); builder.toolchain_overwrite = Some(self.toolchain_channel.clone()); - builder.path_to_target_spec = Some(self.target_spec_dir.join(format!( - "{}.json", - builder.target.as_ref().context("expect target to be set")? - ))); Ok(()) } } @@ -270,10 +263,6 @@ package = "rustc_codegen_spirv" )?; log::info!("selected toolchain channel `{toolchain_channel:?}`"); - log::debug!("update_spec_files"); - let target_spec_dir = update_target_specs_files(&source, &dummy_metadata, !skip_rebuild) - .context("writing target spec files")?; - log::debug!("ensure_toolchain_and_components_exist"); crate::install_toolchain::ensure_toolchain_and_components_exist( &toolchain_channel, @@ -336,7 +325,6 @@ package = "rustc_codegen_spirv" Ok(InstalledBackend { rustc_codegen_spirv_location: dest_dylib_path, toolchain_channel, - target_spec_dir, }) } } diff --git a/crates/cargo-gpu/src/lib.rs b/crates/cargo-gpu/src/lib.rs index cd16561..d482278 100644 --- a/crates/cargo-gpu/src/lib.rs +++ b/crates/cargo-gpu/src/lib.rs @@ -64,7 +64,6 @@ mod lockfile; mod metadata; mod show; mod spirv_source; -mod target_specs; mod test; pub use install::*; diff --git a/crates/cargo-gpu/src/show.rs b/crates/cargo-gpu/src/show.rs index b7eb19b..1e318c4 100644 --- a/crates/cargo-gpu/src/show.rs +++ b/crates/cargo-gpu/src/show.rs @@ -1,11 +1,7 @@ //! Display various information about `cargo gpu`, eg its cache directory. use crate::cache_dir; -use crate::spirv_source::{query_metadata, SpirvSource}; -use crate::target_specs::update_target_specs_files; -use anyhow::bail; -use std::fs; -use std::path::Path; +use crate::spirv_source::SpirvSource; /// Show the computed source of the spirv-std dependency. #[derive(Clone, Debug, clap::Parser)] @@ -26,9 +22,6 @@ pub enum Info { Commitsh, /// All the available SPIR-V capabilities that can be set with `--capabilities` Capabilities, - - /// All available SPIR-V targets - Targets(SpirvSourceDep), } /// `cargo gpu show` @@ -70,13 +63,6 @@ impl Show { println!(" {capability:?}"); } } - Info::Targets(SpirvSourceDep { shader_crate }) => { - let (source, targets) = Self::available_spirv_targets_iter(shader_crate)?; - println!("All available targets for rust-gpu version '{source}':"); - for target in targets { - println!("{target}"); - } - } } Ok(()) @@ -90,32 +76,4 @@ impl Show { let last_capability = spirv_builder::Capability::CacheControlsINTEL as u32; (0..=last_capability).filter_map(spirv_builder::Capability::from_u32) } - - /// List all available spirv targets, note: the targets from compile time of cargo-gpu and those - /// in the cache-directory will be picked up. - fn available_spirv_targets_iter( - shader_crate: &Path, - ) -> anyhow::Result<(SpirvSource, impl Iterator)> { - let source = SpirvSource::new(shader_crate, None, None)?; - let install_dir = source.install_dir()?; - if !install_dir.is_dir() { - bail!("rust-gpu version {} is not installed", source); - } - let dummy_metadata = query_metadata(&install_dir)?; - let target_specs_dir = update_target_specs_files(&source, &dummy_metadata, false)?; - - let mut targets = fs::read_dir(target_specs_dir)? - .filter_map(|entry| { - let file = entry.ok()?; - if file.path().is_file() { - if let Some(target) = file.file_name().to_string_lossy().strip_suffix(".json") { - return Some(target.to_owned()); - } - } - None - }) - .collect::>(); - targets.sort(); - Ok((source, targets.into_iter())) - } } diff --git a/crates/cargo-gpu/src/target_specs.rs b/crates/cargo-gpu/src/target_specs.rs deleted file mode 100644 index eef8dca..0000000 --- a/crates/cargo-gpu/src/target_specs.rs +++ /dev/null @@ -1,135 +0,0 @@ -//! This module deals with target specs, which are json metadata files that need to be passed to -//! rustc to add foreign targets such as `spirv_unknown_vulkan1.2`. -//! -//! There are 4 version ranges of `rustc_codegen_spirv` and they all need different handling of -//! their target specs: -//! * "ancient" versions such as 0.9.0 or earlier do not need target specs, just passing the target -//! string (`spirv-unknown-vulkan1.2`) directly is sufficient. We still prep target-specs for them -//! like the "legacy" variant below, spirv-builder -//! [will just ignore it](https://github.com/Rust-GPU/rust-gpu/blob/369122e1703c0c32d3d46f46fa11ccf12667af03/crates/spirv-builder/src/lib.rs#L987) -//! * "legacy" versions require target specs to compile, which is a requirement introduced by some -//! rustc version. Back then it was decided that cargo gpu would ship them, as they'd probably -//! never change, right? So now we're stuck with having to ship these "legacy" target specs with -//! cargo gpu *forever*. These are the symbol `legacy_target_specs::TARGET_SPECS`, with -//! `legacy_target_specs` being a **fixed** version of `rustc_codegen_spirv-target-specs`, -//! which must **never** update. -//! * As of [PR 256](https://github.com/Rust-GPU/rust-gpu/pull/256), `rustc_codegen_spirv` now has -//! a direct dependency on `rustc_codegen_spirv-target-specs`, allowing cargo gpu to pull the -//! required target specs directly from that dependency. At this point, the target specs are -//! still the same as the legacy target specs. -//! * The [edition 2024 PR](https://github.com/Rust-GPU/rust-gpu/pull/249) must update the -//! target specs to comply with newly added validation within rustc. This is why the new system -//! was implemented, so we can support both old and new target specs without having to worry -//! which version of cargo gpu you are using. It'll "just work". - -use crate::cache_dir; -use crate::spirv_source::{FindPackage as _, SpirvSource}; -use anyhow::Context as _; -use cargo_metadata::Metadata; -use std::path::{Path, PathBuf}; - -/// Extract legacy target specs from our executable into some directory -pub fn write_legacy_target_specs(target_spec_dir: &Path) -> anyhow::Result<()> { - std::fs::create_dir_all(target_spec_dir)?; - for (filename, contents) in legacy_target_specs::TARGET_SPECS { - let path = target_spec_dir.join(filename); - std::fs::write(&path, contents.as_bytes()) - .with_context(|| format!("writing legacy target spec file at [{}]", path.display()))?; - } - Ok(()) -} - -/// Copy spec files from one dir to another, assuming no subdirectories -fn copy_spec_files(src: &Path, dst: &Path) -> anyhow::Result<()> { - std::fs::create_dir_all(dst)?; - let dir = std::fs::read_dir(src)?; - for dir_entry in dir { - let file = dir_entry?; - let file_path = file.path(); - if file_path.is_file() { - std::fs::copy(file_path, dst.join(file.file_name()))?; - } - } - Ok(()) -} - -/// Computes the `target-specs` directory to use and updates the target spec files, if enabled. -pub fn update_target_specs_files( - source: &SpirvSource, - dummy_metadata: &Metadata, - update_files: bool, -) -> anyhow::Result { - log::info!( - "target-specs: Resolving target specs `{}`", - if update_files { - "and update them" - } else { - "without updating" - } - ); - - let mut target_specs_dst = source.install_dir()?.join("target-specs"); - if let Ok(target_specs) = dummy_metadata.find_package("rustc_codegen_spirv-target-specs") { - log::info!( - "target-specs: found crate `rustc_codegen_spirv-target-specs` with manifest at `{}`", - target_specs.manifest_path - ); - - let target_specs_src = target_specs - .manifest_path - .as_std_path() - .parent() - .and_then(|root| { - let src = root.join("target-specs"); - src.is_dir().then_some(src) - }) - .context("Could not find `target-specs` directory within `rustc_codegen_spirv-target-specs` dependency")?; - log::info!( - "target-specs: found `rustc_codegen_spirv-target-specs` with `target-specs` directory `{}`", - target_specs_dst.display() - ); - - if source.is_path() { - // skip copy - log::info!( - "target-specs resolution: source is local path, use target-specs directly from `{}`", - target_specs_dst.display() - ); - target_specs_dst = target_specs_src; - } else { - // copy over the target-specs - log::info!( - "target-specs resolution: copying target-specs from `{}`{}", - target_specs_dst.display(), - if update_files { "" } else { " was skipped" } - ); - if update_files { - copy_spec_files(&target_specs_src, &target_specs_dst) - .context("copying target-specs json files")?; - } - } - } else { - // use legacy target specs bundled with cargo gpu - if source.is_path() { - // This is a stupid situation: - // * We can't be certain that there are `target-specs` in the local checkout (there may be some in `spirv-builder`) - // * We can't dump our legacy ones into the `install_dir`, as that would modify the local rust-gpu checkout - // -> do what the old cargo gpu did, one global dir for all target specs - // and hope parallel runs don't shred each other - target_specs_dst = cache_dir()?.join("legacy-target-specs-for-local-checkout"); - } - log::info!( - "target-specs resolution: legacy target specs in directory `{}`", - target_specs_dst.display() - ); - if update_files { - log::info!( - "target-specs: writing legacy target specs into `{}`", - target_specs_dst.display() - ); - write_legacy_target_specs(&target_specs_dst)?; - } - } - - Ok(target_specs_dst) -}