gdext_gen/features/
target.rs

1//! Module for the representation of the [`Target`], either `Godot`'s or `Rust`'s.
2
3use super::{arch::Architecture, mode::Mode, sys::System};
4
5/// Target to compile the `Godot` game and the `Rust GDExtension` to.
6#[derive(Debug, PartialEq, Eq, Hash)]
7pub struct Target(pub System, pub Mode, pub Architecture);
8
9impl Target {
10    /// Gets the name of the `Rust` target triple this [`Target`] would use if the [`Architecture`] isn't [`Generic`](Architecture::Generic).
11    ///
12    /// # Returns
13    ///
14    /// The name of the `Rust` target triple of this [`Target`].
15    pub fn get_rust_target_triple(&self) -> String {
16        if self.2 == Architecture::Generic {
17            return "".into();
18        }
19        match self.0 {
20            System::Android => format!(
21                "{}-linux-{}{}",
22                self.2.get_rust_name(),
23                self.0.get_name(),
24                if self.2 == Architecture::Armv7 {
25                    "eabi"
26                } else {
27                    ""
28                }
29            ),
30            System::IOS => format!("{}-apple-{}", self.2.get_rust_name(), self.0.get_name()),
31            System::Linux => format!(
32                "{}-unknown-{}-gnu",
33                self.2.get_rust_name(),
34                self.0.get_name()
35            ),
36            System::MacOS => format!("{}-apple-darwin", self.2.get_rust_name()),
37            System::Web => format!("{}-unknown-emscripten", self.2.get_rust_name()),
38            System::Windows(windows_abi) => format!(
39                "{}-pc-{}-{}",
40                self.2.get_rust_name(),
41                self.0.get_name(),
42                windows_abi.get_rust_name(),
43            ),
44        }
45    }
46
47    /// Gets the name of the `Godot` target this [`Target`] would use. If the [`Target`] uses the [`Generic`](Architecture::Generic) [`Architecture`], it translates to "`system`.`mode`", otherwise, to "`system`.`mode`.`architecture`".
48    ///
49    /// # Returns
50    ///
51    /// The name of the `Godot` target of this [`Target`].
52    pub fn get_godot_target(&self) -> String {
53        if self.2 == Architecture::Generic {
54            format!("{}.{}", self.0.get_name(), self.1.get_godot_name())
55        } else {
56            format!(
57                "{}.{}.{}",
58                self.0.get_name(),
59                self.1.get_godot_name(),
60                self.2.get_godot_name()
61            )
62        }
63    }
64}