|
1 | 1 | macro_rules! embed_in_section { |
2 | 2 | ($name:ident, $path:expr, $section:expr, Bytes) => { |
3 | | - #[cfg(target_os = "macos")] |
4 | | - #[unsafe(link_section = concat!("__DATA,", $section))] |
5 | | - #[used] |
6 | | - #[unsafe(no_mangle)] |
7 | | - pub static $name: [u8; include_bytes!(env!($path)).len()] = *include_bytes!(env!($path)); |
8 | | - |
9 | | - #[cfg(target_os = "linux")] |
10 | | - #[unsafe(link_section = concat!(".", $section))] |
11 | | - #[used] |
12 | | - #[unsafe(no_mangle)] |
13 | | - pub static $name: [u8; include_bytes!(env!($path)).len()] = *include_bytes!(env!($path)); |
14 | | - |
15 | | - #[cfg(target_os = "windows")] |
16 | | - #[unsafe(link_section = concat!(".rdata$", $section))] |
17 | | - #[used] |
18 | | - #[unsafe(no_mangle)] |
19 | | - pub static $name: [u8; include_bytes!(env!($path)).len()] = *include_bytes!(env!($path)); |
| 3 | + embed_in_section!( |
| 4 | + $name, |
| 5 | + [u8; include_bytes!(env!($path)).len()], |
| 6 | + $section, |
| 7 | + *include_bytes!(env!($path)) |
| 8 | + ); |
20 | 9 | }; |
21 | 10 |
|
22 | 11 | ($name:ident, $path:expr, $section:expr, String) => { |
23 | | - #[cfg(target_os = "macos")] |
24 | | - #[unsafe(link_section = concat!("__DATA,", $section))] |
25 | | - #[used] |
26 | | - #[unsafe(no_mangle)] |
27 | | - pub static $name: &str = include_str!(env!($path)); |
28 | | - |
29 | | - #[cfg(target_os = "linux")] |
30 | | - #[unsafe(link_section = concat!(".", $section))] |
31 | | - #[used] |
32 | | - #[unsafe(no_mangle)] |
33 | | - pub static $name: &str = include_str!(env!($path)); |
34 | | - |
35 | | - #[cfg(target_os = "windows")] |
36 | | - #[unsafe(link_section = concat!(".rdata$", $section))] |
37 | | - #[used] |
38 | | - #[unsafe(no_mangle)] |
39 | | - pub static $name: &str = include_str!(env!($path)); |
| 12 | + embed_in_section!($name, &str, $section, include_str!(env!($path))); |
40 | 13 | }; |
41 | 14 |
|
42 | 15 | ($name:ident, $path:expr, $section:expr, Env) => { |
43 | | - #[cfg(target_os = "macos")] |
44 | | - #[unsafe(link_section = concat!("__DATA,", $section))] |
45 | | - #[used] |
46 | | - #[unsafe(no_mangle)] |
47 | | - pub static $name: &str = env!($path); |
| 16 | + embed_in_section!($name, &str, $section, env!($path)); |
| 17 | + }; |
48 | 18 |
|
49 | | - #[cfg(target_os = "linux")] |
50 | | - #[unsafe(link_section = concat!(".", $section))] |
51 | | - #[used] |
52 | | - #[unsafe(no_mangle)] |
53 | | - pub static $name: &str = env!($path); |
| 19 | + ($name:ident, $dtype:ty, $section:expr, $res:expr) => { |
| 20 | + embed_in_section!($name, $dtype, concat!("__DATA,", $section), $res, "macos"); |
| 21 | + embed_in_section!($name, $dtype, concat!(".", $section), $res, "linux"); |
| 22 | + embed_in_section!($name, $dtype, concat!(".rdata$", $section), $res, "windows"); |
| 23 | + }; |
54 | 24 |
|
55 | | - #[cfg(target_os = "windows")] |
56 | | - #[unsafe(link_section = concat!(".rdata$", $section))] |
| 25 | + ($name:ident, $dtype:ty, $section:expr, $res:expr, $target_os:expr) => { |
| 26 | + #[cfg(target_os = $target_os)] |
| 27 | + #[unsafe(link_section = $section)] |
57 | 28 | #[used] |
58 | 29 | #[unsafe(no_mangle)] |
59 | | - pub static $name: &str = env!($path); |
| 30 | + pub static $name: $dtype = $res; |
60 | 31 | }; |
61 | 32 | } |
62 | 33 |
|
|
0 commit comments