7
7
//!
8
8
//! # How it works
9
9
//!
10
- //! This library primarily manages installations of `rustc_codegen_spirv`, the
11
- //! codegen backend of rust-gpu to generate SPIR-V shader binaries. The codegen
12
- //! backend builds on internal, ever-changing interfaces of rustc, which requires
13
- //! fixing a version of rust-gpu to a specific version of the rustc compiler.
14
- //! Usually, this would require you to fix your entire project to that specific
15
- //! toolchain, but this project loosens that requirement by managing installations
16
- //! of `rustc_codegen_spirv` and their associated toolchains for you.
10
+ //! This library manages installations of `rustc_codegen_spirv`
11
+ //! using rust-gpu's [`rustc_codegen_spirv-cache`](rustc_codegen_spirv_cache) crate.
17
12
//!
18
- //! We continue to use rust-gpu's `spirv_builder` crate to pass the many additional
19
- //! parameters required to configure rustc and our codegen backend, but provide you
20
- //! with a toolchain agnostic version that you may use from stable rustc.
13
+ //! Then we continue to use rust-gpu's [`spirv-builder`](spirv_builder) crate
14
+ //! to pass the many additional parameters required to configure rustc and our codegen backend,
15
+ //! but provide you with a toolchain agnostic version that you may use from stable rustc.
21
16
//! And a `cargo gpu` command line utility to simplify shader building even more.
22
17
//!
23
- //! ## Where the binaries are
24
- //!
25
- //! We store our prebuilt `rustc_spirv_builder` binaries in the default cache
26
- //! directory of your OS:
27
- //! * Windows: `C:/users/<user>/AppData/Local/rust-gpu`
28
- //! * Mac: `~/Library/Caches/rust-gpu`
29
- //! * Linux: `~/.cache/rust-gpu`
30
- //!
31
18
//! ## How we build the backend
32
19
//!
33
20
//! * retrieve the version of rust-gpu you want to use based on the version of the
50
37
//! conduct other post-processing, like converting the `spv` files into `wgsl` files,
51
38
//! for example.
52
39
53
- use anyhow:: Context as _;
54
-
55
40
use build:: Build ;
56
41
use show:: Show ;
57
42
@@ -74,28 +59,30 @@ mod test;
74
59
pub use install:: * ;
75
60
pub use spirv_builder;
76
61
77
- /// Central function to write to the user .
62
+ /// Writes formatted user output into a [writer](std::io::Write) .
78
63
#[ macro_export]
79
- macro_rules! user_output {
80
- ( $( $args: tt) * ) => {
64
+ macro_rules! write_user_output {
65
+ ( $dst : expr , $ ( $args: tt) * ) => { {
81
66
#[ allow(
82
67
clippy:: allow_attributes,
83
68
clippy:: useless_attribute,
84
69
unused_imports,
85
70
reason = "`std::io::Write` is only sometimes called??"
86
71
) ]
87
- use std:: io:: Write as _;
72
+ use :: std:: io:: Write as _;
73
+
74
+ let mut writer = $dst;
75
+ #[ expect( clippy:: non_ascii_literal, reason = "CRAB GOOD. CRAB IMPORTANT." ) ]
76
+ :: std:: write!( writer, "🦀 " )
77
+ . and_then( |( ) | :: std:: write!( writer, $( $args) * ) )
78
+ . and_then( |( ) | :: std:: io:: Write :: flush( & mut writer) )
79
+ } } ;
80
+ }
88
81
89
- #[ expect(
90
- clippy:: non_ascii_literal,
91
- reason = "CRAB GOOD. CRAB IMPORTANT."
92
- ) ]
93
- {
94
- print!( "🦀 " ) ;
95
- }
96
- print!( $( $args) * ) ;
97
- std:: io:: stdout( ) . flush( ) . unwrap( ) ;
98
- }
82
+ /// Central function to write to the user.
83
+ #[ macro_export]
84
+ macro_rules! user_output {
85
+ ( $( $args: tt) * ) => { $crate:: write_user_output!( :: std:: io:: stdout( ) , $( $args) * ) } ;
99
86
}
100
87
101
88
/// All of the available subcommands for `cargo gpu`
@@ -176,26 +163,6 @@ pub struct Cli {
176
163
pub command : Command ,
177
164
}
178
165
179
- /// The central cache directory of cargo gpu
180
- ///
181
- /// # Errors
182
- /// may fail if we can't find the user home directory
183
- #[ inline]
184
- pub fn cache_dir ( ) -> anyhow:: Result < std:: path:: PathBuf > {
185
- let dir = directories:: BaseDirs :: new ( )
186
- . with_context ( || "could not find the user home directory" ) ?
187
- . cache_dir ( )
188
- . join ( "rust-gpu" ) ;
189
-
190
- Ok ( if cfg ! ( test) {
191
- let thread_id = std:: thread:: current ( ) . id ( ) ;
192
- let id = format ! ( "{thread_id:?}" ) . replace ( '(' , "-" ) . replace ( ')' , "" ) ;
193
- dir. join ( "tests" ) . join ( id)
194
- } else {
195
- dir
196
- } )
197
- }
198
-
199
166
/// Returns a string suitable to use as a directory.
200
167
///
201
168
/// Created from the spirv-builder source dep and the rustc channel.
0 commit comments