manganis_core/
linker.rs

1//! Utilities for working with Manganis assets in the linker. This module defines [`LinkSection`] which has information about what section manganis assets are stored in on each platform.
2
3/// Information about the manganis link section for a given platform
4#[derive(Debug, Clone, Copy)]
5pub struct LinkSection {
6    /// The link section we pass to the static
7    pub link_section: &'static str,
8    /// The name of the section we find in the binary
9    pub name: &'static str,
10}
11
12impl LinkSection {
13    /// The list of link sections for all supported platforms
14    pub const ALL: &'static [&'static LinkSection] =
15        &[Self::WASM, Self::MACOS, Self::WINDOWS, Self::ILLUMOS];
16
17    /// Returns the link section used in linux, android, fuchsia, psp, freebsd, and wasm32
18    pub const WASM: &'static LinkSection = &LinkSection {
19        link_section: "manganis",
20        name: "manganis",
21    };
22
23    /// Returns the link section used in macOS, iOS, tvOS
24    pub const MACOS: &'static LinkSection = &LinkSection {
25        link_section: "__DATA,manganis,regular,no_dead_strip",
26        name: "manganis",
27    };
28
29    /// Returns the link section used in windows
30    pub const WINDOWS: &'static LinkSection = &LinkSection {
31        link_section: "mg",
32        name: "mg",
33    };
34
35    /// Returns the link section used in illumos
36    pub const ILLUMOS: &'static LinkSection = &LinkSection {
37        link_section: "set_manganis",
38        name: "set_manganis",
39    };
40
41    /// The link section used on the current platform
42    pub const CURRENT: &'static LinkSection = {
43        #[cfg(any(
44            target_os = "none",
45            target_os = "linux",
46            target_os = "android",
47            target_os = "fuchsia",
48            target_os = "psp",
49            target_os = "freebsd",
50            target_arch = "wasm32"
51        ))]
52        {
53            Self::WASM
54        }
55
56        #[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos"))]
57        {
58            Self::MACOS
59        }
60
61        #[cfg(target_os = "windows")]
62        {
63            Self::WINDOWS
64        }
65
66        #[cfg(target_os = "illumos")]
67        {
68            Self::ILLUMOS
69        }
70    };
71}