playdate_build_utils/
compile.rs

1//! Utils for compilation binaries.
2
3
4/// Do not forget
5/// - first positional - artifact path
6/// - _this args_
7/// - output path `-o`
8pub const GCC_ARGS_LIB: &[&str] = &["-nostartfiles",
9                                    "-mthumb",
10                                    "-mcpu=cortex-m7",
11                                    "-mfloat-abi=hard",
12                                    "-mfpu=fpv5-sp-d16",
13                                    "-D__FPU_USED=1",
14                                    "-Wl,--cref,--gc-sections,--no-warn-mismatch,--emit-relocs",
15                                    "-fno-exceptions",
16                                    "-mword-relocations",
17                                    "-fno-common",
18                                    "--entry",
19                                    "eventHandlerShim"];
20
21
22pub const RUSTFLAGS_LIB_HOST: &[&str] = &["-Ctarget-cpu=native"];
23pub const RUSTFLAGS_LIB_PLAYDATE: &[&str] = &["-Ctarget-cpu=cortex-m7",
24                                              "-Ctarget-feature=-fp64",
25                                              "-Clink-args=--emit-relocs",
26                                              "-Crelocation-model=pic",
27                                              "-Csoft-float=no",
28                                              "-Clink-arg=--cref",
29                                              "-Clink-arg=--gc-sections"];
30/// For bin.
31///
32/// Do not forget
33/// - `-Clink-arg=-T...link_map.ld`
34/// - `-L{libs-search-paths}`
35pub const RUSTFLAGS_BIN_PLAYDATE: &[&str] = &["-Ctarget-cpu=cortex-m7",
36                                              "-Ctarget-feature=-fp64",
37                                              "-Clink-args=--emit-relocs",
38                                              "-Crelocation-model=pic",
39                                              "-Csoft-float=no",
40                                              "-Clink-arg=--cref",
41                                              "-Clink-arg=--gc-sections",
42                                              "-Clink-arg=--entry=eventHandlerShim"];
43
44/// Bin that we giving to PDC.
45pub const PDX_BIN_NAME_ELF: &str = "pdex.elf";
46/// Bin that is product of PDC.
47pub const PDX_BIN_NAME_BIN: &str = "pdex.bin";
48/// File-stem for bin, elf, and dylib files.
49pub const PDX_BIN_NAME_STEM: &str = "pdex";
50/// Extension of Playdate package (dir).
51pub const PDX_PKG_EXT: &str = "pdx";
52/// Playdate package manifest filename.
53pub const PDX_PKG_MANIFEST_FILENAME: &str = "pdxinfo";
54
55
56pub const fn dylib_suffix_for_host() -> &'static str {
57	if cfg!(target_os = "macos") {
58		"dylib"
59	} else if cfg!(unix) {
60		"so"
61	} else if cfg!(windows) {
62		"dll"
63	} else {
64		panic!("platform not supported");
65		#[cfg(all(not(unix), not(windows)))]
66		{
67			compile_error!("platform not supported")
68		}
69	}
70}
71
72pub const fn dylib_suffix_for_host_opt() -> Option<&'static str> {
73	if cfg!(target_os = "macos") {
74		Some("dylib")
75	} else if cfg!(unix) {
76		Some("so")
77	} else if cfg!(windows) {
78		Some("dll")
79	} else {
80		None
81	}
82}
83
84pub fn dylib_suffix_for_opt(target_family: &str, target_os: &str) -> Option<&'static str> {
85	match target_family {
86		"unix" if target_os == "macos" => Some("dylib"),
87		"unix" => Some("so"),
88		"windows" => Some("dll"),
89		_ => None,
90	}
91}
92
93pub const fn static_lib_suffix() -> &'static str { "a" }
94
95
96/// Compile-time path to the linker-script [LINK_MAP_BIN_SRC].
97/// __Do note resolve, it contains file as dir.__
98/// Path is relative to crate root by default, it depends on your rustc configuration.
99pub const LINK_MAP_BIN_PATH: &str = concat!(file!(), "/../", "layout.x");
100
101/// Linker-script for elf that built with rustc,
102/// without arm-gcc and its std lib.
103pub const LINK_MAP_BIN_SRC: &str = include_str!("layout.x");