Skip to content

Commit d063b16

Browse files
committed
rename tool from rust_gpu to rustc_codegen_spirv
1 parent 19d23e5 commit d063b16

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::rc::Rc;
1515
/// is to allocate all our keywords up front and intern them all, so we can do comparisons really easily and fast.
1616
pub struct Symbols {
1717
pub discriminant: Symbol,
18-
pub rust_gpu: Symbol,
18+
pub rustc_codegen_spirv: Symbol,
1919
pub spirv: Symbol,
2020
pub libm: Symbol,
2121
pub entry_point_name: Symbol,
@@ -406,7 +406,7 @@ impl Symbols {
406406
}
407407
Self {
408408
discriminant: Symbol::intern("discriminant"),
409-
rust_gpu: Symbol::intern("rust_gpu"),
409+
rustc_codegen_spirv: Symbol::intern("rustc_codegen_spirv"),
410410
spirv: Symbol::intern("spirv"),
411411
libm: Symbol::intern("libm"),
412412
entry_point_name: Symbol::intern("entry_point_name"),
@@ -450,34 +450,34 @@ pub(crate) fn parse_attrs_for_checking<'a>(
450450
Attribute::Unparsed(item) => {
451451
// #[...]
452452
let s = &item.path.segments;
453-
if s.len() > 1 && s[0].name == sym.rust_gpu {
454-
// #[rust_gpu ...]
453+
if s.len() > 1 && s[0].name == sym.rustc_codegen_spirv {
454+
// #[rustc_codegen_spirv ...]
455455
if s.len() != 2 || s[1].name != sym.spirv {
456-
// #[rust_gpu::...] but not #[rust_gpu::spirv]
456+
// #[rustc_codegen_spirv::...] but not #[rustc_codegen_spirv::spirv]
457457
(
458458
Some(Err((
459459
attr.span(),
460-
"unknown `rust_gpu` attribute, expected `rust_gpu::spirv`"
460+
"unknown `rustc_codegen_spirv` attribute, expected `rustc_codegen_spirv::spirv`"
461461
.to_string(),
462462
))),
463463
Default::default(),
464464
)
465465
} else if let Some(args) = attr.meta_item_list() {
466-
// #[rust_gpu::spirv(...)]
466+
// #[rustc_codegen_spirv::spirv(...)]
467467
(None, args)
468468
} else {
469-
// #[rust_gpu::spirv]
469+
// #[rustc_codegen_spirv::spirv]
470470
(
471471
Some(Err((
472472
attr.span(),
473-
"#[rust_gpu::spirv(..)] attribute must have at least one argument"
473+
"#[rustc_codegen_spirv::spirv(..)] attribute must have at least one argument"
474474
.to_string(),
475475
))),
476476
Default::default(),
477477
)
478478
}
479479
} else {
480-
// #[...] but not #[rust_gpu ...]
480+
// #[...] but not #[rustc_codegen_spirv ...]
481481
(None, Default::default())
482482
}
483483
}

crates/spirv-builder/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
862862
"-Zbinary-dep-depinfo".to_string(),
863863
"-Csymbol-mangling-version=v0".to_string(),
864864
"-Zcrate-attr=feature(register_tool)".to_string(),
865-
"-Zcrate-attr=register_tool(rust_gpu)".to_string(),
865+
"-Zcrate-attr=register_tool(rustc_codegen_spirv)".to_string(),
866866
// HACK(eddyb) this is the same configuration that we test with, and
867867
// ensures no unwanted surprises from e.g. `core` debug assertions.
868868
"-Coverflow-checks=off".to_string(),

crates/spirv-std/macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ pub fn Image(item: TokenStream) -> TokenStream {
140140
}
141141

142142
/// Replaces all (nested) occurrences of the `#[spirv(..)]` attribute with
143-
/// `#[cfg_attr(target_arch="spirv", rust_gpu::spirv(..))]`.
143+
/// `#[cfg_attr(target_arch="spirv", rustc_codegen_spirv::spirv(..))]`.
144144
#[proc_macro_attribute]
145145
pub fn spirv(attr: TokenStream, item: TokenStream) -> TokenStream {
146146
let mut tokens: Vec<TokenTree> = Vec::new();
147147

148-
// prepend with #[rust_gpu::spirv(..)]
148+
// prepend with #[rustc_codegen_spirv::spirv(..)]
149149
let attr: proc_macro2::TokenStream = attr.into();
150-
tokens.extend(quote! { #[cfg_attr(target_arch="spirv", rust_gpu::spirv(#attr))] });
150+
tokens.extend(quote! { #[cfg_attr(target_arch="spirv", rustc_codegen_spirv::spirv(#attr))] });
151151

152152
let item: proc_macro2::TokenStream = item.into();
153153
for tt in item {
@@ -164,7 +164,7 @@ pub fn spirv(attr: TokenStream, item: TokenStream) -> TokenStream {
164164
// group matches [spirv ...]
165165
let inner = group.stream(); // group stream doesn't include the brackets
166166
sub_tokens.extend(
167-
quote! { [cfg_attr(target_arch="spirv", rust_gpu::#inner)] },
167+
quote! { [cfg_attr(target_arch="spirv", rustc_codegen_spirv::#inner)] },
168168
);
169169
}
170170
_ => sub_tokens.push(tt),

docs/src/migration-to-register-tool.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ You'll also need to remove the `feature(register_attr)` and `register_attr(spirv
2929

3030
```rust
3131
#![feature(register_tool)]
32-
#![register_tool(rust_gpu)]
32+
#![register_tool(rustc_codegen_spirv)]
3333
```
3434

3535
That's it. Your shaders should now compile like before.
3636

3737
## Technical Background
3838

39-
Unfortunately, since the new Rust nightly toolchain in September 2022, `register_attr(spirv)` can no longer be used to register a global `spirv` attribute. Without this registration, the compiler would simply complain about `spirv` being an unknown attribute. However, the alternative, `register_tool`, requires us to scope the attribute in a namespace. For instance, as we've chosen the `rust_gpu` namespace, this would mean that you'd need to start writing `#[rust_gpu::spirv(..)]` instead, which would be quite tedious and would break a lot of code. And it's not possible to `use` a name from a tool namespace to bring it into scope.
39+
Unfortunately, since the new Rust nightly toolchain in September 2022, `register_attr(spirv)` can no longer be used to register a global `spirv` attribute. Without this registration, the compiler would simply complain about `spirv` being an unknown attribute. However, the alternative, `register_tool`, requires us to scope the attribute in a namespace. For instance, as we've chosen the `rustc_codegen_spirv` namespace, this would mean that you'd need to start writing `#[rustc_codegen_spirv::spirv(..)]` instead, which would be quite tedious and would break a lot of code. And it's not possible to `use` a name from a tool namespace to bring it into scope.
4040

41-
Instead, we opted to implement a proc macro attribute called `spirv` instead[^1]. This macro attribute scans the item it is applied to, and translates any `#[spirv(..)]` it finds into `#[rust_gpu::spirv(..)]` which will be subsequently handled by the codegen backend. Because it is now a proc macro attribute exported from `spirv_std`, you need to do `use spirv_std::spirv` to make it globally visible in your crate. ***Note that we recommend using the `spirv` proc macro attribute itself rather than the `rust_gpu::spirv` attribute it translates to, as the latter is subject to change.***
41+
Instead, we opted to implement a proc macro attribute called `spirv` instead[^1]. This macro attribute scans the item it is applied to, and translates any `#[spirv(..)]` it finds into `#[rustc_codegen_spirv::spirv(..)]` which will be subsequently handled by the codegen backend. Because it is now a proc macro attribute exported from `spirv_std`, you need to do `use spirv_std::spirv` to make it globally visible in your crate. ***Note that we recommend using the `spirv` proc macro attribute itself rather than the `rustc_codegen_spirv::spirv` attribute it translates to, as the latter is subject to change.***
4242

43-
We've also added the `feature(register_tool)` and `register_tool(rust_gpu)` crate attributes by default when compiling through `SpirvBuilder`. This will silence any error that you would otherwise get for applying a `rust_gpu` scoped attribute.
43+
We've also added the `feature(register_tool)` and `register_tool(rustc_codegen_spirv)` crate attributes by default when compiling through `SpirvBuilder`. This will silence any error that you would otherwise get for applying a `rustc_codegen_spirv` scoped attribute.
4444

45-
[^1]: This is not entirely true. In reality, the `spirv` proc macro attribute already existed, but only for non-spirv builds. It was used to turn the `#[spirv(..)]` attribute into a no-op. The proc macro is now used on all platforms, and it emits `#[cfg_attr(target_arch="spirv", rust_gpu::spirv(..))]` for each usage of `#[spirv(..)]`.
45+
[^1]: This is not entirely true. In reality, the `spirv` proc macro attribute already existed, but only for non-spirv builds. It was used to turn the `#[spirv(..)]` attribute into a no-op. The proc macro is now used on all platforms, and it emits `#[cfg_attr(target_arch="spirv", rustc_codegen_spirv::spirv(..))]` for each usage of `#[spirv(..)]`.

docs/src/writing-shader-crates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ rustflags = [
132132
"-Zbinary-dep-depinfo",
133133
"-Csymbol-mangling-version=v0",
134134
"-Zcrate-attr=feature(register_tool)",
135-
"-Zcrate-attr=register_tool(rust_gpu)"
135+
"-Zcrate-attr=register_tool(rustc_codegen_spirv)"
136136
]
137137

138138
[unstable]

tests/compiletests/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn rust_flags(codegen_backend_path: &Path) -> String {
363363
"-Zbinary-dep-depinfo",
364364
"-Csymbol-mangling-version=v0",
365365
"-Zcrate-attr=feature(register_tool)",
366-
"-Zcrate-attr=register_tool(rust_gpu)",
366+
"-Zcrate-attr=register_tool(rustc_codegen_spirv)",
367367
// HACK(eddyb) this is the same configuration that we test with, and
368368
// ensures no unwanted surprises from e.g. `core` debug assertions.
369369
"-Coverflow-checks=off",

0 commit comments

Comments
 (0)