Skip to content

Commit febdddf

Browse files
committed
tool: move spirv_attr_version into a crate to allow publishing
1 parent 381f804 commit febdddf

File tree

11 files changed

+33
-31
lines changed

11 files changed

+33
-31
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ either = "1.8.0"
5050
indexmap = "2.6.0"
5151
rspirv = "0.12"
5252
rustc_codegen_spirv-types.workspace = true
53+
spirv-std-types = { workspace = true, features = ["std"] }
5354
rustc-demangle = "0.1.21"
5455
sanitize-filename = "0.6.0"
5556
smallvec = { version = "1.6.1", features = ["const_generics", "const_new", "union"] }

crates/rustc_codegen_spirv/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ mod custom_decorations;
133133
mod custom_insts;
134134
mod link;
135135
mod linker;
136-
#[path = "../../spirv_attr_version.rs"]
137-
mod spirv_attr_version;
138136
mod spirv_type;
139137
mod spirv_type_constraints;
140138
mod symbols;

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::attr::{IntrinsicType, SpirvAttribute};
22
use crate::builder::libm_intrinsics;
3-
use crate::spirv_attr_version::spirv_attr_with_version;
43
use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass};
54
use rustc_data_structures::fx::FxHashMap;
65
use rustc_span::symbol::Symbol;
6+
use spirv_std_types::spirv_attr_version::spirv_attr_with_version;
77
use std::rc::Rc;
88

99
/// Various places in the codebase (mostly attribute parsing) need to compare rustc Symbols to particular keywords.

crates/spirv-std/macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ workspace = true
1414
proc-macro = true
1515

1616
[dependencies]
17-
spirv-std-types.workspace = true
17+
spirv-std-types = { workspace = true, features = ["std"] }
1818
proc-macro2 = "1.0.24"
1919
quote = "1.0.8"
2020
syn = { version = "2.0.90", features = ["full", "visit-mut"] }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,14 @@
7272
#![doc = include_str!("../README.md")]
7373

7474
mod image;
75-
#[path = "../../../spirv_attr_version.rs"]
76-
mod spirv_attr_version;
7775

7876
use proc_macro::TokenStream;
7977
use proc_macro2::{Delimiter, Group, Span, TokenTree};
8078

8179
use syn::{ImplItemFn, visit_mut::VisitMut};
8280

83-
use crate::spirv_attr_version::spirv_attr_with_version;
8481
use quote::{ToTokens, TokenStreamExt, format_ident, quote};
82+
use spirv_std_types::spirv_attr_version::spirv_attr_with_version;
8583
use std::fmt::Write;
8684

8785
/// A macro for creating SPIR-V `OpTypeImage` types. Always produces a

crates/spirv-std/shared/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spirv-std-types"
3-
description = "SPIR-V types shared between spirv-std and spirv-std-macros"
3+
description = "SPIR-V types shared between spirv-std, spirv-std-macros and rustc_codegen_spirv"
44
version.workspace = true
55
authors.workspace = true
66
edition.workspace = true
@@ -9,3 +9,6 @@ repository.workspace = true
99

1010
[lints]
1111
workspace = true
12+
13+
[features]
14+
std = []

crates/spirv-std/shared/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# `spirv-std-types`
22

3-
Small shared crate, to share definitions between [`spirv-std`](https://docs.rs/spirv-std/) and [`spirv-std-macros`](https://docs.rs/spirv-std-macros/). Please refer to [`spirv-std`](https://docs.rs/spirv-std/) for more information.
3+
Small shared crate, to share definitions between [`spirv-std`](https://docs.rs/spirv-std/), [`spirv-std-macros`](https://docs.rs/spirv-std-macros/) and [`rustc_codegen_spirv`](https://docs.rs/rustc_codegen_spirv/). Should only contain symbols that compile in a `no_std` context.
4+
5+
Please refer to [`spirv-std`](https://docs.rs/spirv-std/) for more information.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![doc = include_str!("../README.md")]
2-
#![no_std]
2+
#![cfg_attr(not(feature = "std"), no_std)]
33

44
pub mod image_params;
5+
#[cfg(feature = "std")]
6+
pub mod spirv_attr_version;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// Returns the `spirv` attribute name with version tag.
2+
///
3+
/// The `#[spirv()]` attribute in `spirv_std` expands to this spirv attribute name,
4+
/// including the version of `spirv_std`. `rustc_codegen_spirv` verifies that the
5+
/// version matches with the codegen backend, to prevent accidental mismatches.
6+
///
7+
/// ```no_run
8+
/// # use spirv_std_types::spirv_attr_version::spirv_attr_with_version;
9+
/// let spirv = spirv_attr_with_version();
10+
/// let attr = format!("#[rust_gpu::{spirv}(vertex)]");
11+
/// // version here may be out-of-date
12+
/// assert_eq!("#[rust_gpu::spirv_v0_9(vertex)]", attr);
13+
/// ```
14+
pub fn spirv_attr_with_version() -> String {
15+
let major: u32 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();
16+
let minor: u32 = env!("CARGO_PKG_VERSION_MINOR").parse().unwrap();
17+
format!("spirv_v{major}_{minor}")
18+
}

0 commit comments

Comments
 (0)