@@ -34,22 +34,29 @@ fn copy_spec_files(src: &Path, dst: &Path) -> anyhow::Result<()> {
34
34
Ok ( ( ) )
35
35
}
36
36
37
- /// Add the target spec files to the crate .
38
- pub fn update_spec_files (
37
+ /// Computes the ` target-specs` directory to use and updates the target spec files, if enabled .
38
+ pub fn update_target_specs_files (
39
39
source : & SpirvSource ,
40
- install_dir : & Path ,
41
40
dummy_metadata : & Metadata ,
42
- skip_rebuild : bool ,
41
+ update_files : bool ,
43
42
) -> anyhow:: Result < PathBuf > {
44
- let mut target_specs_dst = install_dir. join ( "target-specs" ) ;
45
- if !skip_rebuild {
46
- if let Ok ( target_specs) = dummy_metadata. find_package ( "rustc_codegen_spirv-target-specs" ) {
47
- log:: info!(
48
- "target-specs: found crate `rustc_codegen_spirv-target-specs` with manifest at `{}`" ,
49
- target_specs. manifest_path
50
- ) ;
43
+ log:: info!(
44
+ "target-specs: Resolving target specs `{}`" ,
45
+ if update_files {
46
+ "and update them"
47
+ } else {
48
+ "without updating"
49
+ }
50
+ ) ;
51
+
52
+ let mut target_specs_dst = source. install_dir ( ) ?. join ( "target-specs" ) ;
53
+ if let Ok ( target_specs) = dummy_metadata. find_package ( "rustc_codegen_spirv-target-specs" ) {
54
+ log:: info!(
55
+ "target-specs: found crate `rustc_codegen_spirv-target-specs` with manifest at `{}`" ,
56
+ target_specs. manifest_path
57
+ ) ;
51
58
52
- let target_specs_src = target_specs
59
+ let target_specs_src = target_specs
53
60
. manifest_path
54
61
. as_std_path ( )
55
62
. parent ( )
@@ -58,34 +65,47 @@ pub fn update_spec_files(
58
65
src. is_dir ( ) . then_some ( src)
59
66
} )
60
67
. context ( "Could not find `target-specs` directory within `rustc_codegen_spirv-target-specs` dependency" ) ?;
61
- if source. is_path ( ) {
62
- // skip copy
63
- log:: info!(
64
- "target-specs: source is local path, use target-specs from `{}`" ,
65
- target_specs_src. display( )
66
- ) ;
67
- target_specs_dst = target_specs_src;
68
- } else {
69
- // copy over the target-specs
70
- log:: info!(
71
- "target-specs: Copy target specs from `{}`" ,
72
- target_specs_src. display( )
73
- ) ;
68
+ log:: info!(
69
+ "target-specs: found `rustc_codegen_spirv-target-specs` with `target-specs` directory `{}`" ,
70
+ target_specs_dst. display( )
71
+ ) ;
72
+
73
+ if source. is_path ( ) {
74
+ // skip copy
75
+ log:: info!(
76
+ "target-specs resolution: source is local path, use target-specs directly from `{}`" ,
77
+ target_specs_dst. display( )
78
+ ) ;
79
+ target_specs_dst = target_specs_src;
80
+ } else {
81
+ // copy over the target-specs
82
+ log:: info!(
83
+ "target-specs resolution: coping target-specs from `{}`{}" ,
84
+ target_specs_dst. display( ) ,
85
+ if update_files { "" } else { " was skipped" }
86
+ ) ;
87
+ if update_files {
74
88
copy_spec_files ( & target_specs_src, & target_specs_dst)
75
89
. context ( "copying target-specs json files" ) ?;
76
90
}
77
- } else {
78
- // use legacy target specs bundled with cargo gpu
79
- if source. is_path ( ) {
80
- // This is a stupid situation:
81
- // * We can't be certain that there are `target-specs` in the local checkout (there may be some in `spirv-builder`)
82
- // * We can't dump our legacy ones into the `install_dir`, as that would modify the local rust-gpu checkout
83
- // -> do what the old cargo gpu did, one global dir for all target specs
84
- // and hope parallel runs don't shred each other
85
- target_specs_dst = cache_dir ( ) ?. join ( "legacy-target-specs-for-local-checkout" ) ;
86
- }
91
+ }
92
+ } else {
93
+ // use legacy target specs bundled with cargo gpu
94
+ if source. is_path ( ) {
95
+ // This is a stupid situation:
96
+ // * We can't be certain that there are `target-specs` in the local checkout (there may be some in `spirv-builder`)
97
+ // * We can't dump our legacy ones into the `install_dir`, as that would modify the local rust-gpu checkout
98
+ // -> do what the old cargo gpu did, one global dir for all target specs
99
+ // and hope parallel runs don't shred each other
100
+ target_specs_dst = cache_dir ( ) ?. join ( "legacy-target-specs-for-local-checkout" ) ;
101
+ }
102
+ log:: info!(
103
+ "target-specs resolution: legacy target specs in directory `{}`" ,
104
+ target_specs_dst. display( )
105
+ ) ;
106
+ if update_files {
87
107
log:: info!(
88
- "target-specs: Writing legacy target specs to `{}`" ,
108
+ "target-specs: Writing legacy target specs into `{}`" ,
89
109
target_specs_dst. display( )
90
110
) ;
91
111
write_legacy_target_specs ( & target_specs_dst) ?;
0 commit comments