Skip to content

Commit

Permalink
refactor(crates): change to workspace with separate crates (#66)
Browse files Browse the repository at this point in the history
* refactor(crates): change to workspace with separate crates

* ci(lint): add workaround for msrv workspace inheritance

* build(wix): move wxs to bin crate

* test: fix testcases for gh actions

* refactor(dependencies): limit tokio to required features

* refactor(ci): use package metadata for msrv workaround

Refs: #66

* fix(logging): fix logging for split crates

Refs: #66

* docs(lib): update the lib description

* style(logger): update the formatting of logger::init

* style(audio): use explicit import for Result type

* refactor(lib): move color-printing functionality to CLI

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Orhun Parmaksız <[email protected]>
  • Loading branch information
3 people committed Nov 5, 2023
1 parent 5327b23 commit 5776676
Show file tree
Hide file tree
Showing 20 changed files with 257 additions and 186 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,10 @@ jobs:
select(.name | ascii_downcase | test(\"linux.*x86_64|x86_64.*linux\")).browser_download_url" | \
wget -qi -
tar -xvf cargo-msrv*.tar* -C ~/.cargo/bin/ cargo-msrv
printf "%s" "Checking MSRV..."
cargo msrv --output-format json verify | tail -n 1 | jq --exit-status '.success'
# Workaround for https://github.com/foresterre/cargo-msrv/issues/590
for package in $(cargo metadata --format-version 1 --no-deps | jq -r ".workspace_members[]" | awk '{print $1}'); do
version=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name | test("^daktilo$")) | .rust_version')
printf "Checking MSRV $version for $package..."
echo -e "[package.metadata]\nmsrv = \"${version}\"" >> "crates/${package}/Cargo.toml"
cargo msrv --output-format json --path "crates/${package}" verify | tail -n 1 | jq --exit-status '.success'
done
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
with:
submodules: recursive
- name: Install cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.2/cargo-dist-installer.sh | sh"
- id: plan
run: |
cargo dist plan ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
with:
submodules: recursive
- name: Install cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.2/cargo-dist-installer.sh | sh"
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch local artifacts
uses: actions/download-artifact@v3
Expand Down
69 changes: 23 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 8 additions & 42 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[package]
name = "daktilo"
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.5.0"
description = "Turn your keyboard into a typewriter! 📇"
authors = ["Orhun Parmaksız <[email protected]>"]
Expand All @@ -9,43 +12,16 @@ homepage = "https://github.com/orhun/daktilo"
repository = "https://github.com/orhun/daktilo"
keywords = ["typewriter", "keyboard", "nostalgic", "type"]
categories = ["command-line-utilities", "multimedia"]
default-run = "daktilo"
rust-version = "1.70.0"
edition = "2021"

[features]
audio-tests = []

[[bin]]
name = "daktilo-completions"
path = "src/bin/completions.rs"

[[bin]]
name = "daktilo-mangen"
path = "src/bin/mangen.rs"

[dependencies]
rdev = { version = "0.5.3", features = ["serialize"] }
rodio = { version = "0.17.3", default-features = false, features = [
"symphonia-mp3",
] }
rust-embed = { version = "8.0.0", features = ["debug-embed", "compression"] }
[workspace.dependencies]
thiserror = "1.0.50"
tokio = { version = "1.33.0", features = ["full"] }
serde = { version = "1.0.190", features = ["derive"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
clap = { version = "4.4.7", features = ["derive", "env", "wrap_help", "cargo"] }
serde = { version = "1.0.190", features = ["derive"] }
dirs = "5.0.1"
toml = "0.8.6"
regex = "1.10.2"
serde_regex = "1.1.0"
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread", "sync"] }
colored = "2.0.4"
clap_complete = "4.4.4"
clap_mangen = "0.2.15"
fastrand = "2.0.1"

[dev-dependencies]
pretty_assertions = "1.4.0"

[profile.dev]
Expand Down Expand Up @@ -93,13 +69,3 @@ targets = [
pr-run-mode = "upload"
# Skip checking whether the specified configuration files are up to date
allow-dirty = ["ci", "msi"]

[workspace.metadata.dist.dependencies.apt]
libasound2-dev = '*'
libxi-dev = '*'
libxtst-dev = '*'
pkg-config = '*'

[package.metadata.wix]
upgrade-guid = "51610A8E-55C9-4F49-8C9F-3529499D5C60"
path-guid = "2198A7FB-5F3C-4FAB-B253-2314115AD2DD"
51 changes: 51 additions & 0 deletions crates/daktilo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[package]
name = "daktilo"
version.workspace = true
description.workspace = true
authors.workspace = true
license.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
rust-version.workspace = true
edition.workspace = true
default-run = "daktilo"

[features]
audio-tests = []

[[bin]]
name = "daktilo-completions"
path = "src/bin/completions.rs"

[[bin]]
name = "daktilo-mangen"
path = "src/bin/mangen.rs"

[dependencies]
clap = { version = "4.4.7", features = ["derive", "env", "wrap_help", "cargo"] }
dirs = "5.0.1"
regex = "1.10.2"
serde_regex = "1.1.0"
clap_complete = "4.4.4"
clap_mangen = "0.2.15"
colored = "2.0.4"
tokio.workspace = true
serde.workspace = true
tracing.workspace = true
daktilo_lib = { path = "../daktilo_lib" }

[dev-dependencies]
pretty_assertions.workspace = true

[package.metadata.dist.dependencies.apt]
libasound2-dev = '*'
libxi-dev = '*'
libxtst-dev = '*'
pkg-config = '*'

[package.metadata.wix]
upgrade-guid = "51610A8E-55C9-4F49-8C9F-3529499D5C60"
path-guid = "2198A7FB-5F3C-4FAB-B253-2314115AD2DD"
6 changes: 3 additions & 3 deletions src/args.rs → crates/daktilo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use clap::Parser;

use crate::config::SoundVariation;
use daktilo_lib::config::SoundVariation;

/// Typewriter ASCII banner.
pub const BANNER: &str = r#"
Expand Down Expand Up @@ -34,8 +34,8 @@ pub const BANNER: &str = r#"
)]
pub struct Args {
/// Enables verbose logging.
#[arg(short, long, env)]
pub verbose: bool,
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Sets the name of the sound preset to use.
///
/// Can be specified multiple times to play multiple presets at once.
Expand Down
12 changes: 10 additions & 2 deletions src/bin/completions.rs → crates/daktilo/src/bin/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ fn main() -> Result<()> {

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use super::*;
#[test]
fn generate_completions() -> Result<()> {
if env::var(OUT_DIR_ENV).is_ok() {
main()?;
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../");
if let Ok(out_dir) = env::var(OUT_DIR_ENV) {
path = path.join(out_dir);
} else {
path = path.join("target");
}

env::set_var(OUT_DIR_ENV, path);
main()?;
Ok(())
}
}
11 changes: 9 additions & 2 deletions src/bin/mangen.rs → crates/daktilo/src/bin/mangen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ fn main() -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn generate_manpage() -> Result<()> {
if env::var(OUT_DIR_ENV).is_ok() {
main()?;
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../");
if let Ok(out_dir) = env::var(OUT_DIR_ENV) {
path = path.join(out_dir);
} else {
path = path.join("target");
}

env::set_var(OUT_DIR_ENV, path);
main()?;
Ok(())
}
}
8 changes: 8 additions & 0 deletions crates/daktilo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Turn your keyboard into a typewriter! 📇

#![warn(missing_docs)]

/// CLI argument parser.
///
/// Needs to be in a lib for completions and mangen.
pub mod args;
Loading

0 comments on commit 5776676

Please sign in to comment.