Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cargo features
Browse files Browse the repository at this point in the history
mgjm committed Jun 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 119277f commit d95709f
Showing 4 changed files with 42 additions and 15 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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,
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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!: {:?} {:?}",
@@ -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 d95709f

Please sign in to comment.