Skip to main content

lux_lib/lua_rockspec/build/
make.rs

1use std::{collections::HashMap, path::PathBuf};
2
3use serde::Serialize;
4
5#[cfg(not(target_env = "msvc"))]
6const MAKEFILE: &str = "Makefile";
7#[cfg(target_env = "msvc")]
8const MAKEFILE: &str = "Makefile.win";
9
10/// Specification for building a rock with the `make` build backend
11#[derive(Debug, PartialEq, Clone, Serialize)]
12pub struct MakeBuildSpec {
13    /// Makefile to be used.
14    /// Default is "Makefile" on Unix variants and "Makefile.win" under Win32.
15    pub makefile: PathBuf,
16    pub build_target: Option<String>,
17    /// Whether to perform a make pass on the target indicated by `build_target`.
18    /// Default is true (i.e., to run make).
19    pub build_pass: bool,
20    /// Default is "install"
21    pub install_target: String,
22    /// Whether to perform a make pass on the target indicated by `install_target`.
23    /// Default is true (i.e., to run make).
24    pub install_pass: bool,
25    /// Assignments to be passed to make during the build pass
26    pub build_variables: HashMap<String, String>,
27    /// Assignments to be passed to make during the install pass
28    pub install_variables: HashMap<String, String>,
29    /// Assignments to be passed to make during both passes
30    pub variables: HashMap<String, String>,
31}
32
33impl Default for MakeBuildSpec {
34    fn default() -> Self {
35        Self {
36            makefile: default_makefile_name(),
37            build_target: Option::default(),
38            build_pass: default_pass(),
39            install_target: default_install_target(),
40            install_pass: default_pass(),
41            build_variables: HashMap::default(),
42            install_variables: HashMap::default(),
43            variables: HashMap::default(),
44        }
45    }
46}
47
48fn default_makefile_name() -> PathBuf {
49    PathBuf::from(MAKEFILE)
50}
51
52fn default_pass() -> bool {
53    true
54}
55
56fn default_install_target() -> String {
57    "install".into()
58}