Skip to content

Commit

Permalink
Add cargo features
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjm committed Jun 6, 2024
1 parent 119277f commit 9b9ee50
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -84,6 +89,13 @@ 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

release:
name: Create release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -111,7 +123,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,
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
}
12 changes: 2 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(clippy::all, clippy::pedantic)]

use rust_github_actions_test::foo;

fn main() {
println!(
"Hello, world V2!: {:?} {:?}",
Expand Down Expand Up @@ -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");
}

0 comments on commit 9b9ee50

Please sign in to comment.