Skip to main content

lux_lib/rockspec/build/backend/
mod.rs

1//! Build backends, serialized from the build table.
2
3pub(crate) mod builtin;
4mod cmake;
5mod make;
6mod rust_binary;
7mod rust_mlua;
8mod treesitter;
9
10pub use builtin::{Builtin, Module, ModulePaths, ModuleSpec, ParseLuaModuleError};
11pub use cmake::CMake;
12pub use make::Make;
13pub use rust_binary::RustBinary;
14pub use rust_mlua::RustMlua;
15pub use treesitter::Treesitter;
16
17impl Default for Spec {
18    fn default() -> Self {
19        Self::Builtin(Builtin::default())
20    }
21}
22
23/// Encodes extra information about each backend.
24/// When selecting a backend, one may provide extra parameters
25/// to `build = { ... }` in order to further customize the behaviour of the build step.
26///
27/// Luarocks provides several default build types, these are also reflected in `lux`
28/// for compatibility.
29#[derive(Debug, PartialEq, Clone)]
30pub enum Spec {
31    Builtin(Builtin),
32    Make(Make),
33    CMake(CMake),
34    Command(Command),
35    LuaRock(String),
36    RustMlua(RustMlua),
37    RustBinary(RustBinary),
38    TreesitterParser(Treesitter),
39    /// Build from the source rockspec, if present.
40    /// Otherwise, fall back to the builtin build and copy all directories.
41    /// This is currently unimplemented by luarocks, but we don't ever publish rockspecs
42    /// that implement this.
43    /// It could be implemented as a custom build backend.
44    Source,
45}
46
47impl Spec {
48    pub(crate) fn can_use_build_dependencies(&self) -> bool {
49        match self {
50            Self::Make(_) | Self::CMake(_) | Self::Command(_) | Self::LuaRock(_) => true,
51            Self::Builtin(_)
52            | Self::RustMlua(_)
53            | Self::RustBinary(_)
54            | Self::TreesitterParser(_)
55            | Self::Source => false,
56        }
57    }
58}
59
60/// Specification for building a rock with the `command` build backend
61#[derive(Debug, PartialEq, Clone)]
62pub struct Command {
63    pub build_command: Option<String>,
64    pub install_command: Option<String>,
65}