lux_lib/lua_rockspec/build/
make.rs

1use std::{collections::HashMap, path::PathBuf};
2
3use mlua::UserData;
4
5#[cfg(not(target_env = "msvc"))]
6const MAKEFILE: &str = "Makefile";
7#[cfg(target_env = "msvc")]
8const MAKEFILE: &str = "Makefile.win";
9
10#[derive(Debug, PartialEq, Clone)]
11pub struct MakeBuildSpec {
12    /// Makefile to be used.
13    /// Default is "Makefile" on Unix variants and "Makefile.win" under Win32.
14    pub makefile: PathBuf,
15    pub build_target: Option<String>,
16    /// Whether to perform a make pass on the target indicated by `build_target`.
17    /// Default is true (i.e., to run make).
18    pub build_pass: bool,
19    /// Default is "install"
20    pub install_target: String,
21    /// Whether to perform a make pass on the target indicated by `install_target`.
22    /// Default is true (i.e., to run make).
23    pub install_pass: bool,
24    /// Assignments to be passed to make during the build pass
25    pub build_variables: HashMap<String, String>,
26    /// Assignments to be passed to make during the install pass
27    pub install_variables: HashMap<String, String>,
28    /// Assignments to be passed to make during both passes
29    pub variables: HashMap<String, String>,
30}
31
32impl UserData for MakeBuildSpec {
33    fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
34        methods.add_method("makefile", |_, this, _: ()| Ok(this.makefile.clone()));
35        methods.add_method("build_target", |_, this, _: ()| {
36            Ok(this.build_target.clone())
37        });
38        methods.add_method("build_pass", |_, this, _: ()| Ok(this.build_pass));
39        methods.add_method("install_target", |_, this, _: ()| {
40            Ok(this.install_target.clone())
41        });
42        methods.add_method("install_pass", |_, this, _: ()| Ok(this.install_pass));
43        methods.add_method("build_variables", |_, this, _: ()| {
44            Ok(this.build_variables.clone())
45        });
46        methods.add_method("install_variables", |_, this, _: ()| {
47            Ok(this.install_variables.clone())
48        });
49        methods.add_method("variables", |_, this, _: ()| Ok(this.variables.clone()));
50    }
51}
52
53impl Default for MakeBuildSpec {
54    fn default() -> Self {
55        Self {
56            makefile: default_makefile_name(),
57            build_target: Option::default(),
58            build_pass: default_pass(),
59            install_target: default_install_target(),
60            install_pass: default_pass(),
61            build_variables: HashMap::default(),
62            install_variables: HashMap::default(),
63            variables: HashMap::default(),
64        }
65    }
66}
67
68fn default_makefile_name() -> PathBuf {
69    PathBuf::from(MAKEFILE)
70}
71
72fn default_pass() -> bool {
73    true
74}
75
76fn default_install_target() -> String {
77    "install".into()
78}