1 // Copyright (c) 2022 The Vulkano developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9 
10 use super::{write_file, VkRegistryData};
11 use proc_macro2::{Literal, TokenStream};
12 use quote::quote;
13 
write(vk_data: &VkRegistryData)14 pub fn write(vk_data: &VkRegistryData) {
15     let version_output = version_output(vk_data.header_version);
16     write_file(
17         "version.rs",
18         format!(
19             "vk.xml header version {}.{}.{}",
20             vk_data.header_version.0, vk_data.header_version.1, vk_data.header_version.2
21         ),
22         quote! {
23             #version_output
24         },
25     );
26 }
27 
version_output((major, minor, patch): (u16, u16, u16)) -> TokenStream28 fn version_output((major, minor, patch): (u16, u16, u16)) -> TokenStream {
29     let major = Literal::u16_unsuffixed(major);
30     let minor = Literal::u16_unsuffixed(minor);
31     let patch = Literal::u16_unsuffixed(patch);
32 
33     quote! {
34         impl Version {
35             /// The highest Vulkan API version currently supported by Vulkano.
36             ///
37             /// It is allowed for applications that use Vulkano to make use of features from higher
38             /// versions than this. However, Vulkano itself will not make use of those features and
39             /// will not expose their APIs, so they must be accessed by other means.
40             ///
41             /// The `max_api_version` of an [`Instance`](crate::instance::Instance) equals
42             /// `HEADER_VERSION` by default, which locks out features from newer versions. In order
43             /// to enable the use of higher versions, the `max_api_version` must be overridden when
44             /// creating an instance.
45             pub const HEADER_VERSION: Version = Version {
46                 major: #major,
47                 minor: #minor,
48                 patch: #patch,
49             };
50         }
51     }
52 }
53