-
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.
- Loading branch information
Showing
13 changed files
with
507 additions
and
28 deletions.
There are no files selected for viewing
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,58 @@ | ||
# A [WIP] Library & Client implementation of [`luarocks`](https://github.com/luarocks/luarocks) | ||
|
||
> [!WARNING] | ||
> | ||
> **rocks is a work in progress | ||
> and does not have a stable release yet.** | ||
|
||
Rocks serves as an application for: | ||
- Installing and managing rocks | ||
- Creating Lua projects with dependencies, build scripts and desired Lua versions | ||
- Creating and publishing your own rocks | ||
- Embedding rock manipulation logic into your own application | ||
|
||
> [!NOTE] | ||
> This aims to be a full rewrite of `luarocks`, with many flags altered to be more | ||
> ergonomic. This is not a drop-in replacement for `luarocks` commands you may have in scripts. | ||
|
||
## :books: Usage | ||
|
||
```sh | ||
rocks <command> <options> | ||
``` | ||
|
||
To view available options and their descriptions, run `rocks --help`. | ||
|
||
## Comparison with [`luarocks v3.11.1`](https://github.com/luarocks/luarocks) | ||
|
||
As this project is still a work in progress, some luarocks features | ||
have not been (fully) implemented yet. | ||
On the other hand, rocks has some features that are not present in luarocks. | ||
|
||
The following table provides a brief (incomplete) comparison: | ||
|
||
| | `rocks` | `luarocks v3.11.1` | | ||
| --- | --- | --- | | ||
| `builtin` build spec | :white_check_mark: | :white_check_mark: | | ||
| `make` build spec | :white_check_mark: | :white_check_mark: | | ||
| `rust-mlua` build spec | :white_check_mark: (builtin) | :white_check_mark: (external build backend) | | ||
| `cmake` build spec | :x: (planned) | :white_check_mark: | | ||
| `command` build spec | :x: (planned) | :white_check_mark: | | ||
| custom build backends | :white_check_mark:[^1] | :white_check_mark: | | ||
| install pre-built binary rocks | :x: (planned) | :white_check_mark: | | ||
| parallel builds/installs | :white_check_mark: | :x: | | ||
| install multiple packages with a single command | :white_check_mark: | :x: | | ||
| install packages using version constraints | :white_check_mark: | :x: | | ||
| lockfiles | :white_check_mark: | :white_check_mark: (basic, dependency versions only) | | ||
| formatting with stylua | :white_check_mark: | :x: | | ||
|
||
[^1]: Supported via a compatibility layer that uses luarocks as a backend. | ||
|
||
## :book: License | ||
|
||
`rocks` is licensed under [MIT](./LICENSE). | ||
|
||
## :green_heart: Contributing | ||
|
||
Contributions are more than welcome! | ||
See [CONTRIBUTING.md](./CONTRIBUTING.md) for a guide. |
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
2 changes: 1 addition & 1 deletion
2
rocks-lib/resources/test/sample-project-busted/project.rockspec
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
6 changes: 6 additions & 0 deletions
6
rocks-lib/resources/test/sample-project-no-build-spec/foo-1.0.0-1.rockspec
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,6 @@ | ||
rockspec_format = "3.0" | ||
package = "foo" | ||
version = "1.0.0-1" | ||
source = { | ||
url = 'https://github.com/nvim-neorocks/luarocks-stub', | ||
} |
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,86 @@ | ||
use std::{io, path::Path}; | ||
|
||
use crate::{ | ||
config::Config, | ||
lua_installation::LuaInstallation, | ||
luarocks_installation::{ExecLuaRocksError, LuaRocksError, LuaRocksInstallation}, | ||
progress::{Progress, ProgressBar}, | ||
rockspec::Rockspec, | ||
tree::RockLayout, | ||
}; | ||
|
||
use tempdir::TempDir; | ||
use thiserror::Error; | ||
|
||
use super::utils::recursive_copy_dir; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum LuarocksBuildError { | ||
#[error(transparent)] | ||
Io(#[from] io::Error), | ||
#[error("error instantiating luarocks compatibility layer: {0}")] | ||
LuaRocksError(#[from] LuaRocksError), | ||
#[error("error running 'luarocks make': {0}")] | ||
ExecLuaRocksError(#[from] ExecLuaRocksError), | ||
} | ||
|
||
pub(crate) async fn build( | ||
rockspec: &Rockspec, | ||
output_paths: &RockLayout, | ||
lua: &LuaInstallation, | ||
config: &Config, | ||
build_dir: &Path, | ||
progress: &Progress<ProgressBar>, | ||
) -> Result<(), LuarocksBuildError> { | ||
progress.map(|p| { | ||
p.set_message(format!( | ||
"Building {} {} with luarocks...", | ||
rockspec.package, rockspec.version | ||
)) | ||
}); | ||
let rockspec_temp_dir = TempDir::new("temp-rockspec")?.into_path(); | ||
let rockspec_file = rockspec_temp_dir.join(format!( | ||
"{}-{}.rockspec", | ||
rockspec.package, rockspec.version | ||
)); | ||
std::fs::write(&rockspec_file, &rockspec.raw_content)?; | ||
let luarocks = LuaRocksInstallation::new(config)?; | ||
let luarocks_tree = TempDir::new("luarocks-compat-tree")?; | ||
luarocks.make(&rockspec_file, build_dir, luarocks_tree.path(), lua)?; | ||
install(rockspec, &luarocks_tree.into_path(), output_paths, config) | ||
} | ||
|
||
fn install( | ||
rockspec: &Rockspec, | ||
luarocks_tree: &Path, | ||
output_paths: &RockLayout, | ||
config: &Config, | ||
) -> Result<(), LuarocksBuildError> { | ||
let lua_version = rockspec | ||
.lua_version_from_config(config) | ||
.expect("could not get lua version!"); | ||
std::fs::create_dir_all(&output_paths.bin)?; | ||
let package_dir = luarocks_tree | ||
.join("lib") | ||
.join("lib") | ||
.join("luarocks") | ||
.join(format!( | ||
"rocks-{}", | ||
&lua_version.version_compatibility_str() | ||
)) | ||
.join(format!("{}", rockspec.package)) | ||
.join(format!("{}", rockspec.version)); | ||
recursive_copy_dir(&package_dir.join("doc"), &output_paths.doc)?; | ||
recursive_copy_dir(&luarocks_tree.join("bin"), &output_paths.bin)?; | ||
let src_dir = luarocks_tree | ||
.join("share") | ||
.join("lua") | ||
.join(lua_version.version_compatibility_str()); | ||
recursive_copy_dir(&src_dir, &output_paths.src)?; | ||
let lib_dir = luarocks_tree | ||
.join("lib") | ||
.join("lua") | ||
.join(lua_version.version_compatibility_str()); | ||
recursive_copy_dir(&lib_dir, &output_paths.lib)?; | ||
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
Oops, something went wrong.