marine_rs_sdk_main/
sdk_version_embedder.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#![allow(dead_code)]
18
19const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
20const VERSION_SIZE: usize = PKG_VERSION.len();
21
22const fn sdk_version() -> [u8; VERSION_SIZE] {
23    let version_as_slice = PKG_VERSION.as_bytes();
24
25    let mut version_as_array: [u8; VERSION_SIZE] = [0; VERSION_SIZE];
26    let mut byte_id = 0;
27    while byte_id < VERSION_SIZE {
28        version_as_array[byte_id] = version_as_slice[byte_id];
29        byte_id += 1;
30    }
31
32    version_as_array
33}
34
35// TODO: avoid duplication with the link_section when key-value attributes become stable
36pub const VERSION_SECTION_NAME: &str = "__fluence_sdk_version";
37
38#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
39#[link_section = "__fluence_sdk_version"]
40#[doc(hidden)]
41pub static __M_SDK_VERSION: [u8; VERSION_SIZE] = sdk_version();