membrane_macro 0.7.1
“A companion crate for `membrane`”
Reads a file into a Rust string
SHA-2566d7ed24caece5123a09bc87f310485630c1d45af6a954b8db85403de7863ac36
MaleculeH₂(FOs)
Evidence
1use crate::quote::quote;
2use once_cell::sync::OnceCell;
3use proc_macro::TokenStream;
4use std::env;
5use std::path::PathBuf;
6use toml::Value;
7
8static BOOTSTRAPPED: OnceCell<bool> = OnceCell::new();
9
10//
11// Fetch the crate type from the Cargo.toml of the currently-compiling crate
12//
13pub(crate) fn is_cdylib() -> bool {
14 let toml = std::fs::read_to_string(
15 PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("Cargo.toml"),
16 )
17 .unwrap();
18
19 match toml::from_str::<Value>(&toml) {
20 Ok(Value::Table(table)) => match table.get("lib") {
21 Some(Value::Table(lib)) => match lib.get("crate-type") {
22 Some(Value::Array(crate_type)) => crate_type.iter().any(|x| match x {
23 Value::String(val) => val == "cdylib",
24 _ => false,
25 …
36:22… true).unwrap();
37
38 // we only add the metadata once and only then when we're a crate that produces a dylib, otherwise
39 // we run the risk of generating duplicate functions within shared workspace crates that all use this macro
40 if is_cdylib() {
41 token_stream.extend::<TokenStream>(
42 quote! {
43 …
55:30… veloper to override the embedded version string with one of their own choosing
56 const LIB_VERSION: Option<&str> = option_env!("MEMBRANE …
No evidence locations were recorded for this file. Raw result