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 487bb6a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
13 changes: 9 additions & 4 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 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 487bb6a

Please sign in to comment.