From 4ef9a32307a5e91868161a5f683b6b97ad9ebbdd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 2 Sep 2023 08:12:43 +0200 Subject: [PATCH] use a multi-call binary ('uni') to have only one build step (#987) This increases installation size, but should decrease build time as symbols and optimizations can be shared more. Once deduplication of generics has happened, these wins should increase even more. However, as it probably increases compile times for CI as it will take longer to build each binary with different compile time flags. Thus I just leave the `uni.rs` file for reference. --- Cargo.toml | 2 +- src/gix.rs | 1 - src/plumbing/main.rs | 14 ++++++-------- src/uni.rs | 28 ++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/uni.rs diff --git a/Cargo.toml b/Cargo.toml index c9f8cf70d4d..baec8272c27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ resolver = "2" [[bin]] name = "ein" -doc = false path = "src/ein.rs" +doc = false test = false doctest = false diff --git a/src/gix.rs b/src/gix.rs index 7e78175060b..8527e57926a 100644 --- a/src/gix.rs +++ b/src/gix.rs @@ -1,7 +1,6 @@ #![deny(unsafe_code, rust_2018_idioms)] mod plumbing; -mod shared; use anyhow::Result; diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 542fb402b4f..5ae9a9e3e78 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -13,16 +13,14 @@ use gitoxide_core as core; use gitoxide_core::{pack::verify, repository::PathsOrPatterns}; use gix::bstr::{io::BufReadExt, BString}; -use crate::{ - plumbing::{ - options::{ - attributes, commit, commitgraph, config, credential, exclude, free, index, mailmap, odb, revision, tree, - Args, Subcommands, - }, - show_progress, +use crate::plumbing::{ + options::{ + attributes, commit, commitgraph, config, credential, exclude, free, index, mailmap, odb, revision, tree, Args, + Subcommands, }, - shared::pretty::prepare_and_run, + show_progress, }; +use gitoxide::shared::pretty::prepare_and_run; #[cfg(feature = "gitoxide-core-async-client")] pub mod async_util { diff --git a/src/uni.rs b/src/uni.rs new file mode 100644 index 00000000000..b4a76ad6846 --- /dev/null +++ b/src/uni.rs @@ -0,0 +1,28 @@ +//! An experiment to see how a multi-call binary could look like. +//! For CI this would mean longer compile times though as it rebuilds `gix` +//! with varying compile flags, which also means that it recompiles all source or `ein`. +//! +//! However, doing this could be interesting for distribution if the files are hard-linked +//! instead of copied, which is why it is left here. +#![deny(unsafe_code, rust_2018_idioms)] + +use anyhow::{bail, Result}; + +mod plumbing; +mod porcelain; + +#[cfg(feature = "pretty-cli")] +fn main() -> Result<()> { + match std::env::current_exe()? + .file_stem() + .and_then(|stem| stem.to_str()) + .unwrap_or("gix") + { + "gix" => plumbing::main(), + "ein" => porcelain::main(), + unknown => bail!("Executable named '{unknown}' cannot be launched. Exe must be named either `gix` or `ein`."), + } +} + +#[cfg(not(feature = "pretty-cli"))] +compile_error!("Please set 'pretty-cli' feature flag");