@@ -15,6 +15,18 @@ use smallvec::SmallVec;
15
15
/// See `CUSTOM_EXT_INST_SET`'s docs for further constraints on the full name.
16
16
pub const CUSTOM_EXT_INST_SET_PREFIX : & str = concat ! ( "Rust." , env!( "CARGO_PKG_NAME" ) , "." ) ;
17
17
18
+ macro_rules! join_cargo_pkg_version_major_minor_patch {
19
+ ( $sep: literal) => {
20
+ concat!(
21
+ env!( "CARGO_PKG_VERSION_MAJOR" ) ,
22
+ $sep,
23
+ env!( "CARGO_PKG_VERSION_MINOR" ) ,
24
+ $sep,
25
+ env!( "CARGO_PKG_VERSION_PATCH" ) ,
26
+ )
27
+ } ;
28
+ }
29
+
18
30
lazy_static ! {
19
31
/// `OpExtInstImport` "instruction set" name for all Rust-GPU instructions.
20
32
///
@@ -30,10 +42,6 @@ lazy_static! {
30
42
/// if the definitions of the custom instructions have changed - this is
31
43
/// achieved by hashing the `SCHEMA` constant from `def_custom_insts!` below
32
44
pub static ref CUSTOM_EXT_INST_SET : String = {
33
- const VER_MAJOR : & str = env!( "CARGO_PKG_VERSION_MAJOR" ) ;
34
- const VER_MINOR : & str = env!( "CARGO_PKG_VERSION_MINOR" ) ;
35
- const VER_PATCH : & str = env!( "CARGO_PKG_VERSION_PATCH" ) ;
36
-
37
45
let schema_hash = {
38
46
use rustc_data_structures:: stable_hasher:: StableHasher ;
39
47
use std:: hash:: Hash ;
@@ -43,11 +51,47 @@ lazy_static! {
43
51
let ( lo, hi) = hasher. finalize( ) ;
44
52
( lo as u128 ) | ( ( hi as u128 ) << 64 )
45
53
} ;
46
-
47
- format!( "{CUSTOM_EXT_INST_SET_PREFIX}{VER_MAJOR}_{VER_MINOR}_{VER_PATCH }.{schema_hash:x}" )
54
+ let version = join_cargo_pkg_version_major_minor_patch! ( "_" ) ;
55
+ format!( "{CUSTOM_EXT_INST_SET_PREFIX}{version }.{schema_hash:x}" )
48
56
} ;
49
57
}
50
58
59
+ pub fn register_to_spirt_context ( cx : & spirt:: Context ) {
60
+ use spirt:: spv:: spec:: { ExtInstSetDesc , ExtInstSetInstructionDesc } ;
61
+ cx. register_custom_ext_inst_set (
62
+ & CUSTOM_EXT_INST_SET ,
63
+ ExtInstSetDesc {
64
+ // HACK(eddyb) this is the most compact form I've found, that isn't
65
+ // outright lossy by omitting "Rust vs Rust-GPU" or the version.
66
+ short_alias : Some (
67
+ concat ! ( "Rust-GPU " , join_cargo_pkg_version_major_minor_patch!( "." ) ) . into ( ) ,
68
+ ) ,
69
+ instructions : SCHEMA
70
+ . iter ( )
71
+ . map ( |& ( i, name, operand_names) | {
72
+ (
73
+ i,
74
+ ExtInstSetInstructionDesc {
75
+ name : name. into ( ) ,
76
+ operand_names : operand_names
77
+ . iter ( )
78
+ . map ( |name| {
79
+ name. strip_prefix ( ".." )
80
+ . unwrap_or ( name)
81
+ . replace ( '_' , " " )
82
+ . into ( )
83
+ } )
84
+ . collect ( ) ,
85
+ is_debuginfo : name. contains ( "Debug" )
86
+ || name. contains ( "InlinedCallFrame" ) ,
87
+ } ,
88
+ )
89
+ } )
90
+ . collect ( ) ,
91
+ } ,
92
+ ) ;
93
+ }
94
+
51
95
macro_rules! def_custom_insts {
52
96
( $( $num: literal => $name: ident $( { $( $field: ident) ,+ $( , ..$variadic_field: ident) ? $( , ) ? } ) ?) ,+ $( , ) ?) => {
53
97
const SCHEMA : & [ ( u32 , & str , & [ & str ] ) ] = & [
0 commit comments