|
1 | 1 | //! Install a dedicated per-shader crate that has the `rust-gpu` compiler in it.
|
2 | 2 |
|
3 |
| -use crate::legacy_target_specs::write_legacy_target_specs; |
4 | 3 | use crate::spirv_source::{
|
5 | 4 | get_channel_from_rustc_codegen_spirv_build_script, query_metadata, FindPackage as _,
|
6 | 5 | };
|
| 6 | +use crate::target_specs::update_spec_files; |
7 | 7 | use crate::{cache_dir, spirv_source::SpirvSource};
|
8 | 8 | use anyhow::Context as _;
|
9 |
| -use cargo_metadata::Metadata; |
10 | 9 | use spirv_builder::SpirvBuilder;
|
11 | 10 | use std::path::{Path, PathBuf};
|
12 | 11 |
|
@@ -196,83 +195,6 @@ package = "rustc_codegen_spirv"
|
196 | 195 | Ok(())
|
197 | 196 | }
|
198 | 197 |
|
199 |
| - /// Copy spec files from one dir to another, assuming no subdirectories |
200 |
| - fn copy_spec_files(src: &Path, dst: &Path) -> anyhow::Result<()> { |
201 |
| - std::fs::create_dir_all(dst)?; |
202 |
| - let dir = std::fs::read_dir(src)?; |
203 |
| - for dir_entry in dir { |
204 |
| - let file = dir_entry?; |
205 |
| - let file_path = file.path(); |
206 |
| - if file_path.is_file() { |
207 |
| - std::fs::copy(file_path, dst.join(file.file_name()))?; |
208 |
| - } |
209 |
| - } |
210 |
| - Ok(()) |
211 |
| - } |
212 |
| - |
213 |
| - /// Add the target spec files to the crate. |
214 |
| - fn update_spec_files( |
215 |
| - source: &SpirvSource, |
216 |
| - install_dir: &Path, |
217 |
| - dummy_metadata: &Metadata, |
218 |
| - skip_rebuild: bool, |
219 |
| - ) -> anyhow::Result<PathBuf> { |
220 |
| - let mut target_specs_dst = install_dir.join("target-specs"); |
221 |
| - if !skip_rebuild { |
222 |
| - if let Ok(target_specs) = |
223 |
| - dummy_metadata.find_package("rustc_codegen_spirv-target-specs") |
224 |
| - { |
225 |
| - log::info!( |
226 |
| - "target-specs: found crate `rustc_codegen_spirv-target-specs` with manifest at `{}`", |
227 |
| - target_specs.manifest_path |
228 |
| - ); |
229 |
| - |
230 |
| - let target_specs_src = target_specs |
231 |
| - .manifest_path |
232 |
| - .as_std_path() |
233 |
| - .parent() |
234 |
| - .and_then(|root| { |
235 |
| - let src = root.join("target-specs"); |
236 |
| - src.is_dir().then_some(src) |
237 |
| - }) |
238 |
| - .context("Could not find `target-specs` directory within `rustc_codegen_spirv-target-specs` dependency")?; |
239 |
| - if source.is_path() { |
240 |
| - // skip copy |
241 |
| - log::info!( |
242 |
| - "target-specs: source is local path, use target-specs from `{}`", |
243 |
| - target_specs_src.display() |
244 |
| - ); |
245 |
| - target_specs_dst = target_specs_src; |
246 |
| - } else { |
247 |
| - // copy over the target-specs |
248 |
| - log::info!( |
249 |
| - "target-specs: Copy target specs from `{}`", |
250 |
| - target_specs_src.display() |
251 |
| - ); |
252 |
| - Self::copy_spec_files(&target_specs_src, &target_specs_dst) |
253 |
| - .context("copying target-specs json files")?; |
254 |
| - } |
255 |
| - } else { |
256 |
| - // use legacy target specs bundled with cargo gpu |
257 |
| - if source.is_path() { |
258 |
| - // This is a stupid situation: |
259 |
| - // * We can't be certain that there are `target-specs` in the local checkout (there may be some in `spirv-builder`) |
260 |
| - // * We can't dump our legacy ones into the `install_dir`, as that would modify the local rust-gpu checkout |
261 |
| - // -> do what the old cargo gpu did, one global dir for all target specs |
262 |
| - // and hope parallel runs don't shred each other |
263 |
| - target_specs_dst = cache_dir()?.join("legacy-target-specs-for-local-checkout"); |
264 |
| - } |
265 |
| - log::info!( |
266 |
| - "target-specs: Writing legacy target specs to `{}`", |
267 |
| - target_specs_dst.display() |
268 |
| - ); |
269 |
| - write_legacy_target_specs(&target_specs_dst)?; |
270 |
| - } |
271 |
| - } |
272 |
| - |
273 |
| - Ok(target_specs_dst) |
274 |
| - } |
275 |
| - |
276 | 198 | /// Install the binary pair and return the [`InstalledBackend`], from which you can create [`SpirvBuilder`] instances.
|
277 | 199 | ///
|
278 | 200 | /// # Errors
|
@@ -339,7 +261,7 @@ package = "rustc_codegen_spirv"
|
339 | 261 |
|
340 | 262 | log::debug!("update_spec_files");
|
341 | 263 | let target_spec_dir =
|
342 |
| - Self::update_spec_files(&source, &install_dir, &dummy_metadata, skip_rebuild) |
| 264 | + update_spec_files(&source, &install_dir, &dummy_metadata, skip_rebuild) |
343 | 265 | .context("writing target spec files")?;
|
344 | 266 |
|
345 | 267 | if !skip_rebuild {
|
|
0 commit comments