From e64f1c43a8ace7b4a80b06329e0563b3daf7f246 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 30 Dec 2023 20:28:47 +0100 Subject: [PATCH 1/3] feat: Add tls-native, tls-rustls features to allow building w/o Rustls --- .github/workflows/ci.yml | 12 ++++++++---- .github/workflows/cross-ci.yml | 6 ++++++ Cargo.toml | 7 +++++-- README.md | 6 ++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65d5c5b59..7662c18d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,10 @@ on: merge_group: types: [checks_requested] +env: + # Comma-separated list of all non-conflicting features. + all_features: cli + jobs: fmt: name: Rustfmt @@ -41,7 +45,7 @@ jobs: components: clippy - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2 - name: Run clippy - run: cargo clippy --all-targets --all-features -- -D warnings + run: cargo clippy --all-targets --features ${{ env.all_features }} -- -D warnings test: name: Test @@ -71,7 +75,7 @@ jobs: toolchain: ${{ matrix.rust }} - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2 - name: Run Cargo Test - run: cargo +${{ matrix.rust }} test -r --all-targets --all-features --workspace + run: cargo +${{ matrix.rust }} test -r --all-targets --features ${{ env.all_features }} --workspace docs: name: Build docs @@ -101,7 +105,7 @@ jobs: toolchain: ${{ matrix.rust }} - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2 - name: Run Cargo Doc - run: cargo +${{ matrix.rust }} doc --no-deps --all-features --workspace --examples + run: cargo +${{ matrix.rust }} doc --no-deps --features ${{ env.all_features }} --workspace --examples powerset: name: Check Powerset of Features @@ -135,7 +139,7 @@ jobs: tool: cargo-hack - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2 - name: Run Cargo Hack - run: cargo +${{ matrix.rust }} hack check --feature-powerset --no-dev-deps + run: cargo +${{ matrix.rust }} hack check --feature-powerset --features tls-rustls --skip tls-native --no-dev-deps result: name: Result (CI) diff --git a/.github/workflows/cross-ci.yml b/.github/workflows/cross-ci.yml index 0afe339c0..1f03b5c5d 100644 --- a/.github/workflows/cross-ci.yml +++ b/.github/workflows/cross-ci.yml @@ -17,6 +17,10 @@ defaults: run: shell: bash +env: + # Comma-separated list of all non-conflicting features. + all_features: cli + jobs: cross-check: name: Cross checking ${{ matrix.job.target }} @@ -87,6 +91,8 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.job.target }} use-cross: ${{ matrix.job.use-cross }} + all-features: false + feature: ${{ env.all_features }} result: name: Result (Cross-CI) diff --git a/Cargo.toml b/Cargo.toml index a207748b8..e2a197419 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,10 +35,13 @@ harness = true edition = "2021" [features] -default = [] +default = ["tls-rustls"] cli = ["merge", "clap"] merge = ["dep:merge"] clap = ["dep:clap"] +# The tls-* features should be treated as mutually exclusive. +tls-native = ["reqwest/native-tls"] +tls-rustls = ["reqwest/rustls-tls-native-roots"] [package.metadata.docs.rs] all-features = true @@ -96,7 +99,7 @@ walkdir = "2.4.0" # rest backend backoff = "0.4.0" -reqwest = { version = "0.11.23", default-features = false, features = ["json", "rustls-tls-native-roots", "stream", "blocking"] } +reqwest = { version = "0.11.23", default-features = false, features = ["json", "stream", "blocking"] } url = "2.5.0" # rclone backend diff --git a/README.md b/README.md index be79047c0..ba279cfb7 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ This crate exposes a few features for controlling dependency usage: by default*. - **clap** - Enables a dependency on the `clap` crate and enables parsing from the commandline. *This feature is disabled by default*. +- **tls-native** - Builds with native TLS support (i.e. link against system TLS + library). This feature should be treated as mutually exclusive with + `tls-rustls`. *This features is disabled by default*. +- **tls-rustls** - Builds with Rustls support (i.e. with bundled TLS library). + This feature should be treated as mutually exclusive with `tls-native`. *This + feature is enabled by default*. ## Examples From 0a3007b195a06701517d199c1d517ff1757e3081 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 30 Dec 2023 21:01:15 +0100 Subject: [PATCH 2/3] ci: check powerset with tls-native too --- .github/workflows/ci.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7662c18d3..f03fa03a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -138,9 +138,18 @@ jobs: with: tool: cargo-hack - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2 - - name: Run Cargo Hack + + - name: Install libssl-dev + if: ${{ matrix.os == 'ubuntu-latest' }} + run: sudo apt-get install libssl-dev + + - name: Run Cargo Hack with tls-rustls run: cargo +${{ matrix.rust }} hack check --feature-powerset --features tls-rustls --skip tls-native --no-dev-deps + - name: Run Cargo Hack with tls-native + if: ${{ matrix.os == 'ubuntu-latest' }} + run: cargo +${{ matrix.rust }} hack check --feature-powerset --features tls-native --skip tls-rustls --no-dev-deps + result: name: Result (CI) runs-on: ubuntu-latest From eabff5526fc800d2b6941725d67fc98ed4dff98d Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 5 Jan 2024 01:26:40 +0100 Subject: [PATCH 3/3] feat: fail build if both tls-native and tls-rustls are enabled --- Cargo.toml | 2 +- README.md | 8 ++++---- src/lib.rs | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2a197419..4f9fe84ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ default = ["tls-rustls"] cli = ["merge", "clap"] merge = ["dep:merge"] clap = ["dep:clap"] -# The tls-* features should be treated as mutually exclusive. +# tls-native and tls-rustls are mutually exclusive. tls-native = ["reqwest/native-tls"] tls-rustls = ["reqwest/rustls-tls-native-roots"] diff --git a/README.md b/README.md index ba279cfb7..c39bd6f7c 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ This crate exposes a few features for controlling dependency usage: - **clap** - Enables a dependency on the `clap` crate and enables parsing from the commandline. *This feature is disabled by default*. - **tls-native** - Builds with native TLS support (i.e. link against system TLS - library). This feature should be treated as mutually exclusive with - `tls-rustls`. *This features is disabled by default*. + library). *This feature is mutually exclusive with `tls-rustls` and it is + disabled by default*. - **tls-rustls** - Builds with Rustls support (i.e. with bundled TLS library). - This feature should be treated as mutually exclusive with `tls-native`. *This - feature is enabled by default*. + *This feature is mutually exclusive with `tls-native` and it is enabled by + default*. ## Examples diff --git a/src/lib.rs b/src/lib.rs index 04bda03e8..387b21856 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,6 +139,9 @@ This crate exposes a few features for controlling dependency usage. #![allow(rustdoc::private_intra_doc_links)] #![allow(clippy::needless_raw_string_hashes)] +#[cfg(all(feature = "tls-native", feature = "tls-rustls"))] +compile_error!("features \"tls-native\" and \"tls-rustls\" cannot be enabled at the same time. Please disable one of them."); + pub(crate) mod archiver; pub(crate) mod backend; pub(crate) mod blob;