core_crypto_ffi/
metadata.rs

1#[cfg(target_family = "wasm")]
2use wasm_bindgen::prelude::*;
3
4const VERSION: &str = env!("CARGO_PKG_VERSION");
5
6#[cfg_attr(not(target_family = "wasm"), uniffi::export)]
7#[cfg_attr(target_family = "wasm", wasm_bindgen)]
8#[inline]
9pub fn version() -> String {
10    VERSION.to_string()
11}
12
13// Unfortunately, we need to define the `BuildMetadata` struct twice:
14// not only does it require a different fundamental member type, but
15// the `wasm_bindgen` attribute on the struct members is not compatible
16// with the `#[cfg_attr]` attribute.
17
18#[cfg(not(target_family = "wasm"))]
19#[derive(uniffi::Record)]
20/// Metadata describing the conditions of the build of this software.
21pub struct BuildMetadata {
22    /// Build Timestamp
23    pub timestamp: String,
24    /// Whether this build was in Debug mode (true) or Release mode (false)
25    pub cargo_debug: String,
26    /// Features enabled for this build
27    pub cargo_features: String,
28    /// Optimization level
29    pub opt_level: String,
30    /// Build target triple
31    pub target_triple: String,
32    /// Git branch
33    pub git_branch: String,
34    /// Output of `git describe`
35    pub git_describe: String,
36    /// Hash of current git commit
37    pub git_sha: String,
38    /// `true` when the source code differed from the commit at the most recent git hash
39    pub git_dirty: String,
40}
41
42/// Metadata describing the conditions of the build of this software.
43#[cfg(target_family = "wasm")]
44#[wasm_bindgen(inspectable)]
45pub struct BuildMetadata {
46    /// Build Timestamp
47    #[wasm_bindgen(readonly)]
48    pub timestamp: &'static str,
49    /// Whether this build was in Debug mode (true) or Release mode (false)
50    #[wasm_bindgen(readonly, js_name = "cargoDebug")]
51    pub cargo_debug: &'static str,
52    /// Features enabled for this build
53    #[wasm_bindgen(readonly, js_name = "cargoFeatures")]
54    pub cargo_features: &'static str,
55    /// Optimization level
56    #[wasm_bindgen(readonly, js_name = "optLevel")]
57    pub opt_level: &'static str,
58    /// Build target triple
59    #[wasm_bindgen(readonly, js_name = "targetTriple")]
60    pub target_triple: &'static str,
61    /// Git branch
62    #[wasm_bindgen(readonly, js_name = "gitBranch")]
63    pub git_branch: &'static str,
64    /// Output of `git describe`
65    #[wasm_bindgen(readonly, js_name = "gitDescribe")]
66    pub git_describe: &'static str,
67    /// Hash of current git commit
68    #[wasm_bindgen(readonly, js_name = "gitSha")]
69    pub git_sha: &'static str,
70    /// `true` when the source code differed from the commit at the most recent git hash
71    #[wasm_bindgen(readonly, js_name = "gitDirty")]
72    pub git_dirty: &'static str,
73}
74
75/// Returns build data for CoreCrypto
76#[cfg_attr(not(target_family = "wasm"), uniffi::export)]
77#[cfg_attr(target_family = "wasm", wasm_bindgen)]
78#[inline]
79pub fn build_metadata() -> BuildMetadata {
80    BuildMetadata {
81        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
82        timestamp: core_crypto::BUILD_METADATA.timestamp.into(),
83        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
84        cargo_debug: core_crypto::BUILD_METADATA.cargo_debug.into(),
85        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
86        cargo_features: core_crypto::BUILD_METADATA.cargo_features.into(),
87        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
88        opt_level: core_crypto::BUILD_METADATA.opt_level.into(),
89        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
90        target_triple: core_crypto::BUILD_METADATA.target_triple.into(),
91        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
92        git_branch: core_crypto::BUILD_METADATA.git_branch.into(),
93        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
94        git_describe: core_crypto::BUILD_METADATA.git_describe.into(),
95        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
96        git_sha: core_crypto::BUILD_METADATA.git_sha.into(),
97        #[cfg_attr(target_family = "wasm", expect(clippy::useless_conversion))]
98        git_dirty: core_crypto::BUILD_METADATA.git_dirty.into(),
99    }
100}
101
102#[cfg(target_family = "wasm")]
103impl crate::CoreCrypto {
104    /// Returns the current version of CoreCrypto
105    pub fn version() -> String {
106        version()
107    }
108
109    /// Returns build data for CoreCrypto
110    pub fn build_metadata() -> BuildMetadata {
111        build_metadata()
112    }
113}