mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Migrate to using cargo workspaces
This commit is contained in:
parent
403d87f7f5
commit
aec7f820ca
66 changed files with 148 additions and 91 deletions
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
|
@ -23,13 +23,13 @@ jobs:
|
|||
run: cargo fmt -- --check
|
||||
|
||||
- name: Build
|
||||
run: cargo build --locked --verbose
|
||||
run: cargo build --locked
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy
|
||||
|
||||
- name: Test - Lune
|
||||
run: cargo test --lib
|
||||
run: cargo test --package lune
|
||||
|
||||
- name: Test - CLI
|
||||
run: cargo test --bin lune
|
||||
run: cargo test --package lune-cli
|
||||
|
|
1
.github/workflows/publish.yaml
vendored
1
.github/workflows/publish.yaml
vendored
|
@ -24,5 +24,6 @@ jobs:
|
|||
- name: Publish to crates.io
|
||||
uses: katyo/publish-crates@v1
|
||||
with:
|
||||
path: "packages/lib"
|
||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
ignore-unpublished-changes: true
|
||||
|
|
42
.github/workflows/release.yaml
vendored
42
.github/workflows/release.yaml
vendored
|
@ -7,23 +7,16 @@ permissions:
|
|||
contents: write
|
||||
|
||||
jobs:
|
||||
init:
|
||||
name: Init
|
||||
create-release:
|
||||
name: Create release
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
manifest_name: ${{ steps.get_name.outputs.value }}
|
||||
manifest_version: ${{ steps.get_version.outputs.value }}
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get name from manifest
|
||||
uses: SebRollen/toml-action@0ad94c4a52c402aaa76e14e8a43551163b6cedf9
|
||||
id: get_name
|
||||
with:
|
||||
file: Cargo.toml
|
||||
field: package.name
|
||||
|
||||
- name: Get version from manifest
|
||||
uses: SebRollen/toml-action@0ad94c4a52c402aaa76e14e8a43551163b6cedf9
|
||||
id: get_version
|
||||
|
@ -31,28 +24,18 @@ jobs:
|
|||
file: Cargo.toml
|
||||
field: package.version
|
||||
|
||||
create-release:
|
||||
needs: ["init"]
|
||||
name: Create release
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: v${{ needs.init.outputs.manifest_version }}
|
||||
release_name: ${{ needs.init.outputs.manifest_version }}
|
||||
tag_name: v${{ steps.get_version.outputs.value }}
|
||||
release_name: ${{ steps.get_version.outputs.value }}
|
||||
draft: true
|
||||
|
||||
upload-assets:
|
||||
needs: ["init", "create-release"]
|
||||
needs: ["create-release"]
|
||||
name: Upload assets
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -96,15 +79,15 @@ jobs:
|
|||
include:
|
||||
- name: Windows x86_64
|
||||
runner-os: windows-latest
|
||||
artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-windows-x86_64
|
||||
artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-windows-x86_64
|
||||
cargo-target: x86_64-pc-windows-msvc
|
||||
- name: Linux x86_64
|
||||
runner-os: ubuntu-latest
|
||||
artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-linux-x86_64
|
||||
artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-linux-x86_64
|
||||
cargo-target: x86_64-unknown-linux-gnu
|
||||
- name: macOS x86_64
|
||||
runner-os: macos-latest
|
||||
artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-macos-x86_64
|
||||
artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-macos-x86_64
|
||||
cargo-target: x86_64-apple-darwin
|
||||
|
||||
name: Build - ${{ matrix.name }}
|
||||
|
@ -122,21 +105,20 @@ jobs:
|
|||
profile: minimal
|
||||
|
||||
- name: Build binary
|
||||
run: cargo build --locked --release --all-features --target ${{ matrix.cargo-target }}
|
||||
run: cargo build --package lune-cli --locked --release --all-features --target ${{ matrix.cargo-target }}
|
||||
env:
|
||||
CARGO_TARGET_DIR: output
|
||||
OPENSSL_STATIC: 1
|
||||
|
||||
- name: Create binary archive
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p staging
|
||||
if [ "${{ matrix.runner-os }}" = "windows-latest" ]; then
|
||||
cp "output/${{ matrix.cargo-target }}/release/${{ needs.init.outputs.manifest_name }}.exe" staging/
|
||||
cp "output/${{ matrix.cargo-target }}/release/lune.exe" staging/
|
||||
cd staging
|
||||
7z a ../release.zip *
|
||||
else
|
||||
cp "output/${{ matrix.cargo-target }}/release/${{ needs.init.outputs.manifest_name }}" staging/
|
||||
cp "output/${{ matrix.cargo-target }}/release/lune" staging/
|
||||
cd staging
|
||||
zip ../release.zip *
|
||||
fi
|
||||
|
|
|
@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `net.serve` gets `NetRequest` and `NetResponse` for the handler function argument and return value
|
||||
- `process.spawn` gets `ProcessSpawnOptions` for its third and optional parameter
|
||||
|
||||
### Changed
|
||||
|
||||
- Reorganize repository structure to take advantage of cargo workspaces, improves compile times
|
||||
|
||||
## `0.2.1` - February 3rd, 2023
|
||||
|
||||
### Added
|
||||
|
|
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -13,9 +13,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.68"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
|
||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
|
@ -518,11 +518,23 @@ name = "lune"
|
|||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"full_moon",
|
||||
"hyper",
|
||||
"mlua",
|
||||
"os_str_bytes",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lune-cli"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"full_moon",
|
||||
"lune",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
@ -706,9 +718,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.50"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -902,9 +914,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.91"
|
||||
version = "1.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||
checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -949,9 +961,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
|||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.1.23"
|
||||
version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7475118a28b7e3a2e157ce0131ba8c5526ea96e90ee601d9f6bb2e286a35ab44"
|
||||
checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
28
Cargo.toml
28
Cargo.toml
|
@ -1,42 +1,32 @@
|
|||
[package]
|
||||
name = "lune"
|
||||
[workspace]
|
||||
|
||||
members = ["packages/cli", "packages/lib"]
|
||||
default-members = ["packages/cli"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
repository = "https://github.com/filiptibell/lune"
|
||||
description = "A Luau script runner"
|
||||
readme = "README.md"
|
||||
keywords = ["cli", "lua", "luau", "scripts"]
|
||||
categories = ["command-line-interface"]
|
||||
|
||||
[[bin]]
|
||||
name = "lune"
|
||||
path = "src/cli/main.rs"
|
||||
|
||||
[lib]
|
||||
name = "lune"
|
||||
path = "src/lib/lib.rs"
|
||||
|
||||
[profile.release]
|
||||
strip = true # Automatically strip symbols from the binary.
|
||||
opt-level = "z" # Optimize for size.
|
||||
lto = true # Enable link-time optimization
|
||||
panic = "abort" # Remove extra panic info
|
||||
|
||||
[dependencies]
|
||||
[workspace.dependencies]
|
||||
|
||||
anyhow = "1.0.68"
|
||||
os_str_bytes = "6.4.1"
|
||||
regex = "1.7.1"
|
||||
serde_json = "1.0.91"
|
||||
|
||||
clap = { version = "4.1.1", features = ["derive"] }
|
||||
full_moon = { version = "0.17.0", features = ["roblox"] }
|
||||
hyper = { version = "0.14.24", features = ["full"] }
|
||||
mlua = { version = "0.8.7", features = ["luau", "async", "serialize"] }
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
tokio = { version = "1.24.2", features = ["full"] }
|
||||
|
||||
[dependencies.reqwest]
|
||||
[workspace.dependencies.reqwest]
|
||||
version = "0.11.14"
|
||||
default-features = false
|
||||
features = ["rustls-tls"]
|
||||
|
|
29
packages/cli/Cargo.toml
Normal file
29
packages/cli/Cargo.toml
Normal file
|
@ -0,0 +1,29 @@
|
|||
[package]
|
||||
name = "lune-cli"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
description.workspace = true
|
||||
readme.workspace = true
|
||||
keywords.workspace = true
|
||||
categories.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "lune"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
lune = { path = "../lib" }
|
||||
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
reqwest.workspace = true
|
||||
|
||||
anyhow = "1.0.68"
|
||||
regex = "1.7.1"
|
||||
|
||||
clap = { version = "4.1.1", features = ["derive"] }
|
||||
full_moon = { version = "0.17.0", features = ["roblox"] }
|
|
@ -165,7 +165,7 @@ impl Cli {
|
|||
Ok(match result {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
ExitCode::from(1)
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
Ok(code) => code,
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
#![deny(clippy::all)]
|
||||
#![warn(clippy::cargo, clippy::pedantic)]
|
||||
#![allow(
|
||||
clippy::cargo_common_metadata,
|
||||
clippy::match_bool,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::multiple_crate_versions,
|
29
packages/lib/Cargo.toml
Normal file
29
packages/lib/Cargo.toml
Normal file
|
@ -0,0 +1,29 @@
|
|||
[package]
|
||||
name = "lune"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
description.workspace = true
|
||||
readme.workspace = true
|
||||
keywords.workspace = true
|
||||
categories.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "lune"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
reqwest.workspace = true
|
||||
|
||||
os_str_bytes = "6.4.1"
|
||||
|
||||
hyper = { version = "0.14.24", features = ["full"] }
|
||||
mlua = { version = "0.8.7", features = ["luau", "async", "serialize"] }
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "1.0.69"
|
|
@ -1,6 +1,5 @@
|
|||
use std::{collections::HashSet, process::ExitCode, sync::Arc};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use mlua::prelude::*;
|
||||
use tokio::{sync::mpsc, task};
|
||||
|
||||
|
@ -71,7 +70,7 @@ impl Lune {
|
|||
self
|
||||
}
|
||||
|
||||
pub async fn run(&self, name: &str, chunk: &str) -> Result<ExitCode> {
|
||||
pub async fn run(&self, name: &str, chunk: &str) -> Result<ExitCode, LuaError> {
|
||||
let task_set = task::LocalSet::new();
|
||||
let (sender, mut receiver) = mpsc::channel::<LuneMessage>(64);
|
||||
let lua = Arc::new(mlua::Lua::new());
|
||||
|
@ -94,7 +93,10 @@ impl Lune {
|
|||
let script_name = name.to_string();
|
||||
let script_chunk = chunk.to_string();
|
||||
let script_sender = snd.clone();
|
||||
script_sender.send(LuneMessage::Spawned).await?;
|
||||
script_sender
|
||||
.send(LuneMessage::Spawned)
|
||||
.await
|
||||
.map_err(LuaError::external)?;
|
||||
task_set.spawn_local(async move {
|
||||
let result = script_lua
|
||||
.load(&script_chunk)
|
||||
|
@ -123,10 +125,10 @@ impl Lune {
|
|||
LuneMessage::Spawned => {}
|
||||
message => {
|
||||
if task_count == 0 {
|
||||
bail!(
|
||||
return Err(format!(
|
||||
"Got message while task count was 0!\nMessage: {:#?}",
|
||||
message
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +155,8 @@ impl Lune {
|
|||
}
|
||||
Ok((got_code, got_error, exit_code))
|
||||
})
|
||||
.await?;
|
||||
.await
|
||||
.map_err(LuaError::external)?;
|
||||
// If we got an error, we will default to exiting
|
||||
// with code 1, unless a code was manually given
|
||||
if got_code {
|
||||
|
@ -168,7 +171,7 @@ impl Lune {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::process::ExitCode;
|
||||
use std::{env::set_current_dir, path::PathBuf, process::ExitCode};
|
||||
|
||||
use anyhow::Result;
|
||||
use tokio::fs::read_to_string;
|
||||
|
@ -182,10 +185,15 @@ mod tests {
|
|||
$(
|
||||
#[tokio::test]
|
||||
async fn $name() -> Result<ExitCode> {
|
||||
let full_name = format!("src/tests/{}.luau", $value);
|
||||
let script = read_to_string(&full_name)
|
||||
.await
|
||||
.unwrap();
|
||||
// NOTE: This path is relative to the lib
|
||||
// package, not the cwd or workspace root,
|
||||
// so we need to cd to the repo root first
|
||||
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let root_dir = crate_dir.join("../../").canonicalize()?;
|
||||
set_current_dir(root_dir)?;
|
||||
// The rest of the test logic can continue as normal
|
||||
let full_name = format!("tests/{}.luau", $value);
|
||||
let script = read_to_string(&full_name).await?;
|
||||
let lune = Lune::new()
|
||||
.with_args(
|
||||
ARGS
|
||||
|
@ -196,7 +204,8 @@ mod tests {
|
|||
)
|
||||
.with_all_globals();
|
||||
let script_name = full_name.strip_suffix(".luau").unwrap();
|
||||
lune.run(&script_name, &script).await
|
||||
let exit_code = lune.run(&script_name, &script).await?;
|
||||
Ok(exit_code)
|
||||
}
|
||||
)*
|
||||
}
|
|
@ -110,7 +110,7 @@ pub fn pretty_format_value(
|
|||
buffer: &mut String,
|
||||
value: &LuaValue,
|
||||
depth: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
) -> std::fmt::Result {
|
||||
// TODO: Handle tables with cyclic references
|
||||
match &value {
|
||||
LuaValue::Nil => write!(buffer, "nil")?,
|
||||
|
@ -135,7 +135,7 @@ pub fn pretty_format_value(
|
|||
let depth_indent = INDENT.repeat(depth);
|
||||
write!(buffer, "{STYLE_DIM}{{{STYLE_RESET}")?;
|
||||
for pair in tab.clone().pairs::<LuaValue, LuaValue>() {
|
||||
let (key, value) = pair?;
|
||||
let (key, value) = pair.unwrap();
|
||||
match &key {
|
||||
LuaValue::String(s) if can_be_plain_lua_table_key(s) => write!(
|
||||
buffer,
|
|
@ -1,14 +0,0 @@
|
|||
local function assert(condition, err)
|
||||
if not condition then
|
||||
console.error(err)
|
||||
process.exit(0)
|
||||
end
|
||||
end
|
||||
|
||||
local path = process.cwd .. "asdfghjkl"
|
||||
|
||||
assert(fs.isDir(path), "Process should exit")
|
||||
assert(fs.isDir(path), "Process should exit")
|
||||
assert(fs.isDir(path), "Process should exit")
|
||||
|
||||
error("Process should have exited...")
|
14
tests/process/exit.luau
Normal file
14
tests/process/exit.luau
Normal file
|
@ -0,0 +1,14 @@
|
|||
local function assert(condition, err)
|
||||
if not condition then
|
||||
console.error(err)
|
||||
process.exit(0)
|
||||
end
|
||||
end
|
||||
|
||||
local path = process.cwd .. "asdfghjkl"
|
||||
|
||||
assert(fs.isDir(path), "Process should exit with success")
|
||||
assert(fs.isDir(path), "Process should exit with success")
|
||||
assert(fs.isDir(path), "Process should exit with success")
|
||||
|
||||
error("Process should have exited with success...")
|
Loading…
Reference in a new issue