Merge pull request #219 from pinnacle-comp/justfile

Add justfile and nuke build.rs
This commit is contained in:
Ottatop 2024-04-24 18:46:19 -05:00 committed by GitHub
commit 9f97fab0ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 124 additions and 74 deletions

View file

@ -51,14 +51,14 @@ jobs:
luaVersion: "5.4"
- name: Setup LuaRocks
uses: leafo/gh-actions-luarocks@v4
- name: Install Lua library
run: cd ./api/lua && luarocks make --local
- name: Setup just
uses: extractions/setup-just@v1
- name: Test
if: ${{ runner.debug != '1' }}
run: cargo test -- --test-threads=1
run: just install test -- --test-threads=1
- name: Test (debug)
if: ${{ runner.debug == '1' }}
run: RUST_LOG=debug cargo test -- --nocapture --test-threads=1
run: RUST_LOG=debug RUST_BACKTRACE=1 just install test -- --nocapture --test-threads=1
check-format:
runs-on: ubuntu-latest
name: Check formatting
@ -92,4 +92,4 @@ jobs:
- name: Setup LuaRocks
uses: leafo/gh-actions-luarocks@v4
- name: Clippy check
run: cargo clippy -- -D warnings
run: cargo clippy --all -- -D warnings

View file

@ -75,6 +75,13 @@ You will need:
```sh
sudo apt install protobuf-compiler
```
- [just](https://github.com/casey/just), to automate installation of libraries and files
- You don't *need* this but without installation you will not be able to run `cargo run -- config gen` or
use the Lua API (it requires the protobuf definitions at runtime)
- Arch:
```sh
sudo pacman -S just
```
If you would like to use the Lua API, you will additionally need:
@ -99,20 +106,18 @@ Build the project with:
cargo build [--release]
```
> [!NOTE]
> On build, [`build.rs`](build.rs) will:
> - Copy Protobuf definition files to `$XDG_DATA_HOME/pinnacle/protobuf`
> - Copy the [Lua default config](api/lua/examples/default) and
> [Rust default config](api/rust/examples/default_config/for_copying) to
> `$XDG_DATA_HOME/pinnacle/default_config/{lua,rust}`
To additionally install the default configs, protobuf definitions, and Lua API, run:
```sh
just install build [--release] # Order matters, put build/run/test last to pass through arguments
```
# Running
> [!TIP]
> Before running, read the information in [Configuration](#configuration).
> [!IMPORTANT]
> If you are going to use a Lua config, you must `cd` into [`api/lua`](api/lua)
> and run `luarocks make [--local]` to install Pinnacle's Lua library.
> If you are going to use a Lua config, you must run `just install` to install the protobuf definitions
> and Lua library.
After building, run the executable located in either:
```sh
@ -123,9 +128,12 @@ After building, run the executable located in either:
Or, run the project directly with
```sh
cargo run [--release]
# With installation:
just install run [--release]
```
See flags you can pass in by running `cargo run -- --help` (or `-h`).
See flags Pinnacle accepts by running `cargo run -- --help` (or `-h`).
# Configuration
Pinnacle is configured in your choice of Lua or Rust.
@ -137,9 +145,11 @@ the Lua or Rust default configs standalone, run one of the following in the crat
```sh
# For a Lua configuration
cargo run -- -c "./api/lua/examples/default"
just install run -- -c "./api/lua/examples/default"
# For a Rust configuration
cargo run -- -c "./api/rust/examples/default_config"
just install run -- -c "./api/rust/examples/default_config"
```
## Custom configuration
@ -150,6 +160,12 @@ cargo run -- -c "./api/rust/examples/default_config"
### Generating a config
> [!NOTE]
> The default configs must be installed for them to be copied:
> ```sh
> just install-configs # Or alternatively, `just install` which installs everything
> ```
Run the following command to open up the interactive config generator:
```sh
cargo run -- config gen
@ -175,7 +191,7 @@ that exists from the following:
1. The directory passed in through `--config-dir`/`-c`
2. `$PINNACLE_CONFIG_DIR`
3. `$XDG_CONFIG_HOME/pinnacle`
4. `~/.config/pinnacle` if $XDG_CONFIG_HOME is not defined
4. `~/.config/pinnacle` if `$XDG_CONFIG_HOME` is not defined
If there is no `metaconfig.toml` file in that directory, Pinnacle will start the embedded
Rust config.

View file

@ -1,59 +0,0 @@
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=api/lua");
println!("cargo:rerun-if-changed=api/protocol");
let xdg = xdg::BaseDirectories::with_prefix("pinnacle").unwrap();
let proto_dir = xdg.place_data_file("protobuf").unwrap();
let default_config_dir = xdg.place_data_file("default_config").unwrap();
let default_lua_config_dir = default_config_dir.join("lua");
let default_rust_config_dir = default_config_dir.join("rust");
let remove_protos = format!("rm -r {proto_dir:?}");
let copy_protos = format!("cp -r ./api/protocol {proto_dir:?}");
let remove_default_config_dir = format!("rm -r {default_config_dir:?}");
let copy_default_lua_config =
format!("cp -r ./api/lua/examples/default {default_lua_config_dir:?}");
let copy_default_rust_config = format!(
"cp -LR ./api/rust/examples/default_config/for_copying {default_rust_config_dir:?}"
);
Command::new("/bin/sh")
.arg("-c")
.arg(&remove_protos)
.spawn()?
.wait()?;
Command::new("/bin/sh")
.arg("-c")
.arg(&copy_protos)
.spawn()?
.wait()?;
Command::new("/bin/sh")
.arg("-c")
.arg(&remove_default_config_dir)
.spawn()?
.wait()?;
std::fs::create_dir_all(&default_config_dir)?;
Command::new("/bin/sh")
.arg("-c")
.arg(&copy_default_lua_config)
.spawn()?
.wait()?;
Command::new("/bin/sh")
.arg("-c")
.arg(&copy_default_rust_config)
.spawn()?
.wait()?;
Ok(())
}

92
justfile Normal file
View file

@ -0,0 +1,92 @@
set shell := ["bash", "-c"]
rootdir := justfile_directory()
xdg_data_dir := `echo "${XDG_DATA_HOME:-$HOME/.local/share}/pinnacle"`
root_xdg_data_dir := "/usr/share/pinnacle"
root_xdg_config_dir := "/etc/xdg/pinnacle"
list:
@just --list --unsorted
# Install the configs, protobuf definitions, and the Lua library (requires Luarocks)
install: install-configs install-protos install-lua-lib
# Install the default Lua and Rust configs
install-configs:
#!/usr/bin/env bash
set -euxo pipefail
default_config_dir="{{xdg_data_dir}}/default_config"
default_lua_dir="${default_config_dir}/lua"
default_rust_dir="${default_config_dir}/rust"
rm -rf "${default_config_dir}"
mkdir -p "${default_config_dir}"
cp -r "{{rootdir}}/api/lua/examples/default" "${default_lua_dir}"
cp -LR "{{rootdir}}/api/rust/examples/default_config/for_copying" "${default_rust_dir}"
# Install the protobuf definitions (only needed for the Lua API)
install-protos:
#!/usr/bin/env bash
set -euxo pipefail
proto_dir="{{xdg_data_dir}}/protobuf"
rm -rf "${proto_dir}"
mkdir -p "{{xdg_data_dir}}"
cp -r "{{rootdir}}/api/protocol" "${proto_dir}"
# Install the Lua library (requires Luarocks)
install-lua-lib:
#!/usr/bin/env bash
cd "{{rootdir}}/api/lua"
luarocks make --local
# Remove installed configs and the Lua API (requires Luarocks)
clean:
rm -rf "{{xdg_data_dir}}"
-luarocks remove --local pinnacle-api
# [root] Remove installed configs and the Lua API (requires Luarocks)
clean-root:
rm -rf "{{root_xdg_data_dir}}"
rm -rf "{{root_xdg_config_dir}}"
-luarocks remove pinnacle-api
# [root] Install the configs, protobuf definitions, and the Lua library (requires Luarocks)
install-root: install-configs-root install-protos-root install-lua-lib-root
# [root] Install the default Lua and Rust configs
install-configs-root:
#!/usr/bin/env bash
set -euxo pipefail
default_config_dir="{{root_xdg_config_dir}}/default_config"
default_lua_dir="${default_config_dir}/lua"
default_rust_dir="${default_config_dir}/rust"
rm -rf "${default_config_dir}"
mkdir -p "${default_config_dir}"
cp -r "{{rootdir}}/api/lua/examples/default" "${default_lua_dir}"
cp -LR "{{rootdir}}/api/rust/examples/default_config/for_copying" "${default_rust_dir}"
# [root] Install the protobuf definitions (only needed for the Lua API)
install-protos-root:
#!/usr/bin/env bash
set -euxo pipefail
proto_dir="{{root_xdg_data_dir}}/protobuf"
rm -rf "${proto_dir}"
mkdir -p "{{root_xdg_data_dir}}"
cp -r "{{rootdir}}/api/protocol" "${proto_dir}"
# [root] Install the Lua library (requires Luarocks)
install-lua-lib-root:
#!/usr/bin/env bash
cd "{{rootdir}}/api/lua"
luarocks make
# Run `cargo build`
build *args:
cargo build {{args}}
# Run `cargo run`
run *args:
cargo run {{args}}
# Run `cargo test`
test *args:
cargo test {{args}}

View file

@ -329,6 +329,7 @@ fn generate_config(args: ConfigGen) -> anyhow::Result<()> {
let xdg_base_dirs = xdg::BaseDirectories::with_prefix("pinnacle")?;
let mut default_config_dir = xdg_base_dirs.get_data_file("default_config");
std::fs::create_dir_all(&default_config_dir)?;
// %F = %Y-%m-%d or year-month-day in ISO 8601
// %T = %H:%M:%S