-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
rocks install-lua
command + Lua compilation
- Loading branch information
Showing
12 changed files
with
171 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use clap::Args; | ||
use eyre::Result; | ||
use rocks_lib::{ | ||
config::{Config, LuaVersion}, | ||
lua::Lua, | ||
}; | ||
|
||
#[derive(Args)] | ||
pub struct InstallLua { | ||
version: LuaVersion, | ||
} | ||
|
||
// TODO: Make `config` useful: allow custom paths to install lua into, perhaps `--lua-dir`? | ||
pub fn install_lua(install_data: InstallLua, _config: &Config) -> Result<()> { | ||
let version_stringified = install_data.version.to_string(); | ||
|
||
// TODO: Detect when path already exists by checking `Lua::path()` and prompt the user | ||
// whether they'd like to forcefully reinstall. | ||
Lua::new(&install_data.version)?; | ||
|
||
print!("Succesfully installed Lua {version_stringified}."); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod build; | ||
pub mod config; | ||
pub mod lua; | ||
pub mod lua_package; | ||
pub mod manifest; | ||
pub mod operations; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use eyre::Result; | ||
use std::path::PathBuf; | ||
use target_lexicon::Triple; | ||
|
||
use crate::config::{Config, LuaVersion}; | ||
|
||
pub struct Lua { | ||
pub include_dir: PathBuf, | ||
pub lib_dir: PathBuf, | ||
} | ||
|
||
impl Lua { | ||
pub fn new(version: &LuaVersion) -> Result<Self> { | ||
let output = Self::path(version)?; | ||
|
||
if output.exists() { | ||
Ok(Lua { | ||
include_dir: output.join("include"), | ||
lib_dir: output.join("lib"), | ||
}) | ||
} else { | ||
let host = Triple::host(); | ||
let target = &host.to_string(); | ||
let host_operating_system = &host.operating_system.to_string(); | ||
|
||
let (include_dir, lib_dir) = match version { | ||
LuaVersion::LuaJIT => { | ||
let build = lua_src::Build::new() | ||
.target(target) | ||
.host(host_operating_system) | ||
.out_dir(output) | ||
.build(match version { | ||
LuaVersion::Lua51 => lua_src::Version::Lua51, | ||
LuaVersion::Lua52 => lua_src::Version::Lua52, | ||
LuaVersion::Lua53 => lua_src::Version::Lua53, | ||
LuaVersion::Lua54 => lua_src::Version::Lua54, | ||
LuaVersion::LuaJIT => unreachable!(), | ||
}); | ||
|
||
( | ||
build.include_dir().to_path_buf(), | ||
build.lib_dir().to_path_buf(), | ||
) | ||
} | ||
_ => { | ||
let build = luajit_src::Build::new() | ||
.target(target) | ||
.host(host_operating_system) | ||
.out_dir(output) | ||
.build(); | ||
|
||
( | ||
build.include_dir().to_path_buf(), | ||
build.lib_dir().to_path_buf(), | ||
) | ||
} | ||
}; | ||
|
||
Ok(Lua { | ||
include_dir, | ||
lib_dir, | ||
}) | ||
} | ||
} | ||
|
||
pub fn path(version: &LuaVersion) -> Result<PathBuf> { | ||
Ok(Config::get_default_cache_path()? | ||
.join("lua") | ||
.join(version.to_string())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters