From d95709f76c1f9f4b95890163195a72e7f0dcb7a1 Mon Sep 17 00:00:00 2001 From: Martin Michaelis Date: Thu, 6 Jun 2024 16:29:39 +0000 Subject: [PATCH] Add cargo features --- .github/workflows/ci.yaml | 23 ++++++++++++++++++----- Cargo.toml | 9 +++++++++ src/lib.rs | 13 +++++++++++++ src/main.rs | 12 ++---------- 4 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 src/lib.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ca0f45..72baad4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,18 +15,23 @@ env: jobs: test: - name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) + name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) ${{ matrix.features }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust: - stable + features: + - --no-default-features + - + - -F cli cmd: - name: Test run: cargo test --locked - name: Clippy - run: cargo clippy --locked --tests -- -D warnings + run: cargo clippy --locked --tests + run2: -D warnings timeout-minutes: 45 steps: - uses: actions/checkout@v4 @@ -36,7 +41,7 @@ jobs: - name: Install build dependencies run: sudo apt-get install -y libudev-dev - name: ${{ matrix.cmd.name }} - run: ${{ matrix.cmd.run }} + run: ${{ matrix.cmd.run }} ${{ matrix.features }} -- ${{ matrix.cmd.run2 }} build: name: Build for ${{ matrix.target.name }} @@ -72,7 +77,7 @@ jobs: run: ${{ matrix.target.pre-build }} if: matrix.target.pre-build - name: Build for ${{ matrix.target.name }} - run: cargo build --locked --release --target ${{ matrix.target.target }} + run: cargo build --locked --release --target ${{ matrix.target.target }} --no-default-features -F cli - name: Check file run: | file target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} @@ -84,6 +89,14 @@ jobs: path: rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} if-no-files-found: error + ready: + name: All required checks passed + needs: + - test + - build + runs-on: ubuntu-latest + steps: [] + release: name: Create release if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -111,7 +124,7 @@ jobs: const { data: release } = await github.rest.repos.createRelease({ owner: context.repo.owner, repo: context.repo.repo, - tag_name: `commit-${env.GITHUB_SHA.slice(0, 8)}`, + tag_name: `commit-${env.GITHUB_SHA.slice(0, 7)}`, target_commitish: env.GITHUB_SHA, draft: true, generate_release_notes: true, diff --git a/Cargo.toml b/Cargo.toml index dda7c94..91c44fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,14 @@ name = "rust-github-actions-test" version = "0.1.0" edition = "2021" +[[bin]] +name = "rust-github-actions-test" +required-features = ["cli"] + +[features] +default = ["example"] +example = [] +cli = ["example"] + [dependencies] hidapi = "2.6.1" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d2bc429 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +#![warn(clippy::all, clippy::pedantic)] + +#[cfg(feature = "example")] +#[cfg(target_feature = "crt-static")] +pub fn foo() { + println!("the C runtime should be statically linked"); +} + +#[cfg(feature = "example")] +#[cfg(not(target_feature = "crt-static"))] +pub fn foo() { + println!("the C runtime should be dynamically linked"); +} diff --git a/src/main.rs b/src/main.rs index 72e6f14..af65d04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ #![warn(clippy::all, clippy::pedantic)] +use rust_github_actions_test::foo; + fn main() { println!( "Hello, world V2!: {:?} {:?}", @@ -28,13 +30,3 @@ fn main() { Err(err) => eprintln!("Error: {err:?}"), } } - -#[cfg(target_feature = "crt-static")] -fn foo() { - println!("the C runtime should be statically linked"); -} - -#[cfg(not(target_feature = "crt-static"))] -fn foo() { - println!("the C runtime should be dynamically linked"); -}