Skip to content

Commit

Permalink
feat: luarocks build backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 13, 2024
1 parent 9b7741d commit 1569194
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
55 changes: 55 additions & 0 deletions rocks-lib/src/build/luarocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::{lua_installation::LuaInstallation, rockspec::Rockspec, tree::RockLayout};

use mlua::Lua;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum LuarocksBuildError {
#[error(transparent)]
MluaError(#[from] mlua::Error),
}

pub(crate) async fn build(
rockspec: &Rockspec,
output_paths: &RockLayout,
lua: &LuaInstallation,
) -> Result<(), LuarocksBuildError> {
// TODO: store rockspec content in a temp dir

// TODO: install build_dependencies?
// - What about rockspec_format 1 that has build dependencies in the dependencies list?
// `--deps-mode none` won't work with those!
// - Check the rockspec_format and decide what to do? We could install dependencies into
// a separate temp tree if rockspec_format != 3

// TODO: set lua headers in luarocks config

// Build using Lua, not the CLI wrapper, because the Windows one doesn't seem to work.
let lua = Lua::new();
let package_path = "";
let package_cpath = "";
let install_tree = ""; // TODO: Temp directory for install tree
lua.load(format!(
"
package.path = '{0}'
package.cpath = '{1}'
local commands = {{
make = 'luarocks.cmd.make',
}}
local args = {{
'make',
'--deps-mode',
'none',
'--tree',
'{2}',
}}
local unpack = unpack or table.unpack
cmd.run_command(description, commands, 'luarocks.cmd.external', unpack(args))
",
package_path, package_cpath, install_tree
))
.exec()?;

// TODO: Copy files from temp install tree to output_paths
todo!()
}
7 changes: 7 additions & 0 deletions rocks-lib/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ use crate::{
};
pub(crate) mod utils; // Make build utilities available as a submodule
use indicatif::style::TemplateError;
use luarocks::LuarocksBuildError;
use make::MakeError;
use rust_mlua::RustError;
use thiserror::Error;
mod builtin;
mod luarocks;
mod make;
mod rust_mlua;
pub mod variables;
Expand All @@ -43,6 +45,8 @@ pub enum BuildError {
stdout: String,
stderr: String,
},
#[error(transparent)]
LuarocksBuildError(#[from] LuarocksBuildError),
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -87,6 +91,9 @@ async fn run_build(
.run(output_paths, false, lua, config, build_dir, progress)
.await?
}
Some(BuildBackendSpec::LuaRock(_)) => {
luarocks::build(rockspec, output_paths, lua).await?;
}
None => (),
_ => unimplemented!(),
}
Expand Down
3 changes: 3 additions & 0 deletions rocks-lib/src/rockspec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Rockspec {
pub source: PerPlatform<RockSource>,
pub build: PerPlatform<BuildSpec>,
pub test: PerPlatform<TestSpec>,
/// The original content of this rockspec, needed by luarocks
pub raw_content: String,
/// The sha256 of this rockspec
hash: Integrity,
}
Expand All @@ -77,6 +79,7 @@ impl Rockspec {
build: globals.get("build")?,
test: globals.get("test")?,
hash: Integrity::from(rockspec_content),
raw_content: rockspec_content.clone(),
};

let rockspec_file_name = format!("{}-{}.rockspec", rockspec.package, rockspec.version);
Expand Down

0 comments on commit 1569194

Please sign in to comment.