From dd763ffccdb7db66fa1ba59a37cf9aee92b2fb35 Mon Sep 17 00:00:00 2001 From: thdaele Date: Tue, 6 May 2025 14:57:56 +0200 Subject: [PATCH 1/2] enable cli only build gated by cargo features --- Cargo.toml | 15 ++++++++++----- src/errors.rs | 1 + src/main.rs | 1 + src/ui/mod.rs | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ffbfaf..66846cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,19 +12,24 @@ base64 = "0.22.1" chrono = { version = "0.4.40", features = ["serde"] } clap = { version = "4.5.35", features = ["cargo", "derive", "string"] } cli-clipboard = "0.4.0" -eframe = { version = "0.31.1", features = ["wgpu"] } -egui = "0.31.1" -egui-dropdown = "0.13.0" +eframe = { version = "0.31.1", features = ["wgpu"], optional = true } +egui = { version = "0.31.1", optional = true } +egui-dropdown = { version = "0.13.0", optional = true } env_logger = "0.11.8" log = "0.4.27" reqwest = { version = "0.12.15", features = ["json"] } -rfd = "0.15.3" +rfd = { version = "0.15.3", optional = true } serde = { version = "1.0.219", features = ["derive"] } serde_json = { version = "1.0.140", features = ["preserve_order"] } tokio = { version = "1", features = ["macros", "net", "rt-multi-thread"] } -webbrowser = "1.0.4" +webbrowser = { version = "1.0.4", optional = true } zip = { version = "2.6.1", features = ["deflate-flate2"] } +[features] +default = ["gui"] + +gui = ["dep:eframe", "dep:egui", "dep:egui-dropdown", "dep:rfd", "dep:webbrowser"] + [build-dependencies] embed-resource = "1.6.0" winres = "0.1.11" diff --git a/src/errors.rs b/src/errors.rs index 4d5429c..1f48805 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,6 +3,7 @@ use std::{fmt::Debug, path::StripPrefixError}; #[derive(Debug)] pub struct InstallerError(pub String); +#[cfg(feature = "gui")] impl From for InstallerError { fn from(value: eframe::Error) -> Self { InstallerError(format!("{:?}", value)) diff --git a/src/main.rs b/src/main.rs index 2c25075..72ea014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ async fn main() { info!("Ornithe Installer v{}", VERSION); // The first argument is the binary name + #[cfg(feature = "gui")] if std::env::args().count() <= 1 { if let Ok(_) = crate::ui::gui::run().await { return; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 130fa60..7e06e35 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,6 +1,8 @@ use std::path::PathBuf; pub mod cli; + +#[cfg(feature = "gui")] pub mod gui; #[derive(PartialEq, Clone, Copy, Debug)] From 45e56215b4b7dd28e592d719b12075b5ed24a7ca Mon Sep 17 00:00:00 2001 From: thdaele Date: Tue, 6 May 2025 23:14:39 +0200 Subject: [PATCH 2/2] cli-only build: github workflow --- .github/workflows/publish.yml | 7 +++++++ build.gradle.kts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 94c390f..650194f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,6 +54,13 @@ jobs: toolchain: stable - uses: Swatinem/rust-cache@v2 - run: rustup target add ${{ matrix.target }} + # Build the CLI only binary + - run: cargo build --no-default-features --release --target ${{ matrix.target }} + - run: mv "target/${{ matrix.target }}/release/ornithe-installer-rs" "target/${{ matrix.target }}/release/ornithe-installer-rs-cli.bin" + if: runner.os != 'Windows' + - run: mv "target/${{ matrix.target }}/release/ornithe-installer-rs.exe" "target/${{ matrix.target }}/release/ornithe-installer-rs-cli.exe" + if: runner.os == 'Windows' + # Regular build with GUI - run: cargo build --release --target ${{ matrix.target }} - run: mv "target/${{ matrix.target }}/release/ornithe-installer-rs" "target/${{ matrix.target }}/release/ornithe-installer-rs.bin" if: runner.os != 'Windows' diff --git a/build.gradle.kts b/build.gradle.kts index 65ee56c..7fa367b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,14 @@ publishing { "exe" else "bin" ) } + artifact ( + file( + "$projectDir/target/$target/release/ornithe-installer-rs-cli." + if (os?.contains("windows") == true) // thanks kotlin + "exe" else "bin" + ) + ) { + classifier = "cli" + } } }