make use of pimalaya/tui build module

This commit is contained in:
Clément DOUIN 2024-11-29 08:37:38 +01:00
parent 1a193f3ec3
commit 85a12a54c0
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
6 changed files with 66 additions and 202 deletions

77
Cargo.lock generated
View file

@ -475,9 +475,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da"
checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
[[package]]
name = "camellia"
@ -1334,12 +1334,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.9"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [
"libc",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@ -1794,7 +1794,6 @@ dependencies = [
"clap_mangen",
"color-eyre",
"email-lib",
"git2",
"mail-builder",
"mml-lib",
"once_cell",
@ -1828,18 +1827,6 @@ dependencies = [
"digest",
]
[[package]]
name = "hoot"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9faf289df1f00f6daaa1bcce481f6ef7f28f153a8ef985409914d357c9cd57a2"
dependencies = [
"http",
"httparse",
"log",
"url",
]
[[package]]
name = "hostname"
version = "0.3.1"
@ -2331,9 +2318,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.165"
version = "0.2.166"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb4d3d38eab6c5239a362fa8bae48c03baf980a6e7079f063942d563ef3533e"
checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36"
[[package]]
name = "libdbus-sys"
@ -2475,7 +2462,7 @@ checksum = "7a575d25cf00ed68e5790b473b29242a47e991c6187785d47b45e31fc5816554"
dependencies = [
"base64 0.22.1",
"gethostname",
"rustls 0.23.18",
"rustls 0.23.19",
"rustls-pki-types",
"smtp-proto",
"tokio",
@ -3090,7 +3077,7 @@ dependencies = [
[[package]]
name = "pimalaya-tui"
version = "0.1.0"
source = "git+https://github.com/pimalaya/tui#f59e1ac129962f9f219673284a0e25874d8ec679"
source = "git+https://github.com/pimalaya/tui#3b1ea19c0e384827eba5aea2ee935cd23b02be45"
dependencies = [
"async-trait",
"clap",
@ -3100,6 +3087,7 @@ dependencies = [
"dirs 4.0.0",
"email-lib",
"email_address",
"git2",
"inquire",
"md5",
"mml-lib",
@ -3464,9 +3452,9 @@ checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3"
[[package]]
name = "rsa"
version = "0.9.6"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc"
checksum = "47c75d7c5c6b673e58bf54d8544a9f432e3a925b0e80f7cd3602ab5c50c55519"
dependencies = [
"const-oid",
"digest",
@ -3524,9 +3512,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.23.18"
version = "0.23.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f"
checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1"
dependencies = [
"log",
"once_cell",
@ -3585,7 +3573,7 @@ dependencies = [
"jni",
"log",
"once_cell",
"rustls 0.23.18",
"rustls 0.23.19",
"rustls-native-certs",
"rustls-platform-verifier-android",
"rustls-webpki 0.102.8",
@ -3987,9 +3975,9 @@ checksum = "51b8ad3dd187f0d4debab02ad65405a9919d6a4f7bce25bd64a258781063a53a"
[[package]]
name = "socket2"
version = "0.5.7"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8"
dependencies = [
"libc",
"windows-sys 0.52.0",
@ -4270,7 +4258,7 @@ version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4"
dependencies = [
"rustls 0.23.18",
"rustls 0.23.19",
"rustls-pki-types",
"tokio",
]
@ -4325,9 +4313,9 @@ dependencies = [
[[package]]
name = "tracing"
version = "0.1.40"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"pin-project-lite",
"tracing-attributes",
@ -4336,9 +4324,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.27"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
@ -4480,26 +4468,37 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "ureq"
version = "3.0.0-rc2"
version = "3.0.0-rc3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a139c7262528ca928e9a4368281577453ae93953159d7d7b922165bd083049f"
checksum = "37c3a545fa4b66681e920b35c903c0e5c4ca706b25d68a209bdcd3f970d2436a"
dependencies = [
"base64 0.22.1",
"cc",
"flate2",
"hoot",
"http",
"log",
"once_cell",
"percent-encoding",
"rustls 0.23.18",
"rustls 0.23.19",
"rustls-pemfile 2.2.0",
"rustls-pki-types",
"rustls-platform-verifier",
"ureq-proto",
"utf-8",
"webpki-roots",
]
[[package]]
name = "ureq-proto"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcec9cbfbf05a7feef00db0295c6183f468635c7adb12a31e941f3660b071bff"
dependencies = [
"http",
"httparse",
"log",
"url",
]
[[package]]
name = "url"
version = "2.5.4"

View file

@ -45,9 +45,7 @@ pgp-gpg = ["email-lib/pgp-gpg", "mml-lib/pgp-gpg", "pimalaya-tui/pgp-gpg"]
pgp-native = ["email-lib/pgp-native", "mml-lib/pgp-native", "pimalaya-tui/pgp-native"]
[build-dependencies]
git2 = { version = "0.19", default-features = false }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
pimalaya-tui = { version = "=0.1", default-features = false, features = ["build-envs"] }
[dependencies]
ariadne = "0.2"
@ -72,6 +70,7 @@ uuid = { version = "0.8", features = ["v4"] }
[patch.crates-io]
email-lib = { git = "https://github.com/pimalaya/core" }
keyring-lib = { git = "https://github.com/pimalaya/core" }
mml-lib = { git = "https://github.com/pimalaya/core" }
oauth-lib = { git = "https://github.com/pimalaya/core" }
pimalaya-tui = { git = "https://github.com/pimalaya/tui" }

126
build.rs
View file

@ -1,129 +1,7 @@
use std::{
collections::HashMap,
env::{self, VarError},
};
use git2::{DescribeOptions, Repository};
use serde::Deserialize;
use pimalaya_tui::build::{features_env, git_envs, target_envs};
fn main() {
features_env();
features_env(include_str!("./Cargo.toml"));
target_envs();
git_envs();
}
/// Builds the `CARGO_FEATURES` environment variable.
///
/// This function turns enabled cargo features into a simple string
/// `+feature1 +feature2 +featureN`, which then exposes it via the
/// `CARGO_FEATURES` environment variable.
///
/// It first reads and parses the Cargo.toml in order to extract all
/// available features (omitting "default"). It then checks for
/// enabled features via `CARGO_FEATURE_<name>` to finally collect
/// them into a string.
fn features_env() {
#[derive(Deserialize)]
struct Config {
features: HashMap<String, Vec<String>>,
}
impl Config {
fn enabled_features(self) -> impl Iterator<Item = String> {
self.features
.into_keys()
.filter(|feature| feature != "default")
.filter(|feature| {
let feature = feature.replace('-', "_").to_uppercase();
env::var(format!("CARGO_FEATURE_{feature}")).is_ok()
})
}
}
let config: Config =
toml::from_str(include_str!("./Cargo.toml")).expect("should parse Cargo.toml");
let mut features = String::new();
for feature in config.enabled_features() {
if !features.is_empty() {
features.push(' ');
}
features.push_str(&format!("+{feature}"));
}
println!("cargo::rustc-env=CARGO_FEATURES={features}");
}
/// Builds environment variables related to the target platform.
///
/// This function basically forwards existing cargo environments
/// related to the target platform.
fn target_envs() {
forward_env("CARGO_CFG_TARGET_OS");
forward_env("CARGO_CFG_TARGET_ENV");
forward_env("CARGO_CFG_TARGET_ARCH");
}
/// Builds environment variables related to git.
///
/// This function basically tries to forward existing git environment
/// variables. In case of failure, it tries to build them using
/// [`git2`].
fn git_envs() {
let git = Repository::open(".").ok();
if try_forward_env("GIT_DESCRIBE").is_err() {
let description = match &git {
None => String::from("unknown"),
Some(git) => {
let mut opts = DescribeOptions::new();
opts.describe_all();
opts.show_commit_oid_as_fallback(true);
git.describe(&opts)
.expect("should describe git object")
.format(None)
.expect("should format git object description")
}
};
println!("cargo::rustc-env=GIT_DESCRIBE={description}");
};
if try_forward_env("GIT_REV").is_err() {
let rev = match &git {
None => String::from("unknown"),
Some(git) => {
let head = git.head().expect("should get git HEAD");
let commit = head.peel_to_commit().expect("should get git HEAD commit");
commit.id().to_string()
}
};
println!("cargo::rustc-env=GIT_REV={rev}");
};
}
/// Tries to forward the given environment variable.
///
/// For a more strict version, see [`forward_env`].
fn try_forward_env(key: &str) -> Result<String, VarError> {
let env = env::var(key);
if let Ok(val) = &env {
println!("cargo::rustc-env={key}={val}");
}
env
}
/// Forwards the given environment variable.
///
/// This function panics in case the forward fails (when the
/// environment variable does not exist for example).
///
/// For a less strict version, see [`try_forward_env`].
fn forward_env(key: &str) {
try_forward_env(key).expect(&format!("should get env {key}"));
}

6
flake.lock generated
View file

@ -39,11 +39,11 @@
"pimalaya": {
"flake": false,
"locked": {
"lastModified": 1732806838,
"narHash": "sha256-/Xp2qCuobXwomUX6m4+ceCcp59tSYnUfPsOkfcj2tDk=",
"lastModified": 1732861699,
"narHash": "sha256-zAH0R9TnwxqevDMtQlp1+K/FUvHD7vFCvxx1IAPJPkg=",
"owner": "pimalaya",
"repo": "nix",
"rev": "7d8d42cc1e0d01304e945441809d2e451268c5e8",
"rev": "5496d03953c15ce3022b76e9514ff083517cc740",
"type": "github"
},
"original": {

View file

@ -16,21 +16,25 @@
, buildFeatures ? [ ]
}:
let
version = "1.0.0-beta.4";
hash = "sha256-NrWBg0sjaz/uLsNs8/T4MkUgHOUvAWRix1O5usKsw6o=";
cargoHash = "sha256-YS8IamapvmdrOPptQh2Ef9Yold0IK1XIeGs0kDIQ5b8=";
in
rustPlatform.buildRustPackage rec {
inherit cargoHash version;
inherit buildNoDefaultFeatures buildFeatures;
pname = "himalaya";
version = "1.0.0-beta.4";
src = fetchFromGitHub {
owner = "soywod";
inherit hash;
owner = "pimalaya";
repo = "himalaya";
rev = "v${version}";
hash = "sha256-NrWBg0sjaz/uLsNs8/T4MkUgHOUvAWRix1O5usKsw6o=";
};
cargoHash = "sha256-YS8IamapvmdrOPptQh2Ef9Yold0IK1XIeGs0kDIQ5b8=";
nativeBuildInputs = [ pkg-config ]
++ lib.optional (installManPages || installShellCompletions) installShellFiles;
@ -62,11 +66,11 @@ rustPlatform.buildRustPackage rec {
installShellCompletion "$out"/share/completions/himalaya.{bash,fish,zsh}
'';
meta = {
meta = rec {
description = "CLI to manage emails";
mainProgram = "himalaya";
homepage = "https://github.com/pimalaya/himalaya/";
changelog = "https://github.com/soywod/himalaya/blob/v${version}/CHANGELOG.md";
homepage = "https://github.com/pimalaya/himalaya";
changelog = "${homepage}/blob/v${version}/CHANGELOG.md";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ soywod toastal yanganto ];
};

View file

@ -2,12 +2,15 @@ use std::path::PathBuf;
use clap::{Parser, Subcommand};
use color_eyre::Result;
use pimalaya_tui::terminal::{
cli::{
arg::path_parser,
printer::{OutputFmt, Printer},
use pimalaya_tui::{
long_version,
terminal::{
cli::{
arg::path_parser,
printer::{OutputFmt, Printer},
},
config::TomlConfig as _,
},
config::TomlConfig as _,
};
use crate::{
@ -27,7 +30,7 @@ use crate::{
#[derive(Parser, Debug)]
#[command(name = env!("CARGO_PKG_NAME"))]
#[command(author, version, about)]
#[command(long_version = Cli::LONG_VERSION)]
#[command(long_version = long_version!())]
#[command(propagate_version = true, infer_subcommands = true)]
pub struct Cli {
#[command(subcommand)]
@ -75,25 +78,6 @@ pub struct Cli {
pub trace: bool,
}
impl Cli {
pub const LONG_VERSION: &'static str = concat!(
"v",
env!("CARGO_PKG_VERSION"),
" ",
env!("CARGO_FEATURES"),
"\nbuild: ",
env!("CARGO_CFG_TARGET_OS"),
" ",
env!("CARGO_CFG_TARGET_ENV"),
" ",
env!("CARGO_CFG_TARGET_ARCH"),
"\ngit: ",
env!("GIT_DESCRIBE"),
", rev ",
env!("GIT_REV"),
);
}
#[derive(Subcommand, Debug)]
pub enum HimalayaCommand {
#[command(subcommand)]