77//!
88//! # How it works
99//!
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.
1712//!
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.
2116//! And a `cargo gpu` command line utility to simplify shader building even more.
2217//!
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- //!
3118//! ## How we build the backend
3219//!
3320//! * retrieve the version of rust-gpu you want to use based on the version of the
5037//! conduct other post-processing, like converting the `spv` files into `wgsl` files,
5138//! for example.
5239
53- use anyhow:: Context as _;
54-
5540use build:: Build ;
5641use show:: Show ;
5742
@@ -74,28 +59,30 @@ mod test;
7459pub use install:: * ;
7560pub use spirv_builder;
7661
77- /// Central function to write to the user .
62+ /// Writes formatted user output into a [writer](std::io::Write) .
7863#[ macro_export]
79- macro_rules! user_output {
80- ( $( $args: tt) * ) => {
64+ macro_rules! write_user_output {
65+ ( $dst : expr , $ ( $args: tt) * ) => { {
8166 #[ allow(
8267 clippy:: allow_attributes,
8368 clippy:: useless_attribute,
8469 unused_imports,
8570 reason = "`std::io::Write` is only sometimes called??"
8671 ) ]
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+ }
8881
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) * ) } ;
9986}
10087
10188/// All of the available subcommands for `cargo gpu`
@@ -176,26 +163,6 @@ pub struct Cli {
176163 pub command : Command ,
177164}
178165
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-
199166/// Returns a string suitable to use as a directory.
200167///
201168/// Created from the spirv-builder source dep and the rustc channel.
0 commit comments