1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use std::{env, path::Path};
fn get_main_rs_path() -> &'static str {
if env::var("CARGO_PUBLISH").is_err() {
concat!(
env!("CARGO_MANIFEST_DIR"),
"/../single-binary-producer/src/main.rs"
)
} else {
concat!(
env!("CARGO_MANIFEST_DIR"),
"../../../../single-binary-producer/src/main.rs"
)
}
}
fn get_cargo_toml_path() -> &'static str {
if env::var("CARGO_PUBLISH").is_err() {
concat!(
env!("CARGO_MANIFEST_DIR"),
"/../single-binary-producer/Cargo.toml"
)
} else {
concat!(
env!("CARGO_MANIFEST_DIR"),
"../../../../single-binary-producer/Cargo.toml"
)
}
}
fn quote(dir: impl AsRef<Path> + ToTokens) -> TokenStream {
quote! {
std::include_str!(#dir)
}
.into()
}
#[proc_macro]
pub fn get_sbp_main_rs(_input: TokenStream) -> TokenStream {
let dir = get_main_rs_path();
quote(dir)
}
#[proc_macro]
pub fn get_sbp_cargo_toml(_input: TokenStream) -> TokenStream {
let dir = get_cargo_toml_path();
quote(dir)
}