From fcf89032ddde7efeb4e402c555fd4d4323c70218 Mon Sep 17 00:00:00 2001 From: Martin Michaelis Date: Wed, 5 Jun 2024 16:14:00 +0000 Subject: [PATCH] Add CI config --- .github/workflows/ci.yaml | 136 ++++++++++++++++++++++++++++++++++++++ Cargo.lock | 106 +++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 39 ++++++++++- 4 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5c17dbf --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,136 @@ +name: CI + +on: + - push + - pull_request + - workflow_dispatch + +permissions: + contents: read + +env: + CARGO_INCREMENTAL: 0 + CARGO_TERM_COLOR: always + +jobs: + # test: + # name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) + # runs-on: ubuntu-latest + # strategy: + # fail-fast: false + # matrix: + # rust: + # - stable + # cmd: + # - name: Test + # run: cargo test --locked + # - name: Clippy + # run: cargo clippy --locked --tests -- -D warnings + # timeout-minutes: 45 + # steps: + # - uses: actions/checkout@v4 + # - name: Setup rust + # run: | + # rustup toolchain install ${{ matrix.rust }} --profile minimal --no-self-update + # - name: ${{ matrix.cmd.name }} + # run: ${{ matrix.cmd.run }} + + build: + name: Build for ${{ matrix.target.name }} + runs-on: ${{ matrix.target.runs-on }} + strategy: + fail-fast: false + matrix: + target: + - name: Linux (x86_64) + runs-on: ubuntu-latest + target: x86_64-unknown-linux-gnu + pre-build: | + sudo apt-get install -y libudev-dev + # - name: Windows (x86_64) + # runs-on: windows-latest + # target: x86_64-pc-windows-msvc + # ext: .exe + # - name: MacOS (x86_64) + # runs-on: macos-latest + # target: x86_64-apple-darwin + # - name: MacOS (arm64) + # runs-on: macos-latest + # target: aarch64-apple-darwin + timeout-minutes: 45 + # env: + # RUSTFLAGS: -C target-feature=+crt-static + steps: + - uses: actions/checkout@v4 + - name: Setup rust + run: | + rustup toolchain install stable --target ${{ matrix.target.target }} --profile minimal --no-self-update + - name: Install build dependencies + 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 }} + - name: Run for ${{ matrix.target.name }} + run: cargo run --locked --release --target ${{ matrix.target.target }} + - name: Check file + run: | + file target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} + stat target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} + mv target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} + - uses: actions/upload-artifact@v4 + with: + name: rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} + path: rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} + if-no-files-found: error + + release: + name: Update release + permissions: + contents: write + needs: build + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/download-artifact@v4 + with: + pattern: rust-github-actions-test.* + merge-multiple: true + - run: find -exec ls -ld {} + + - uses: actions/github-script@v7 + id: upload-release-asset + with: + script: | + const fs = require('fs'); + const { env } = process; + + 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)}`, + target_commitish: env.GITHUB_SHA, + draft: true, + generate_release_notes: true, + }); + console.log('release:', release.id, release); + + + const artifacts = fs.readdirSync('.'); + console.log('artifacts:', artifacts); + + for (const name of artifacts) { + const data = fs.readFileSync(name); + await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + name, + data, + }); + } + + await github.rest.repos.updateRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + draft: false, + }); diff --git a/Cargo.lock b/Cargo.lock index b6816fd..93ecf2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,112 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "hidapi" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e58251020fe88fe0dae5ebcc1be92b4995214af84725b375d08354d0311c23c" +dependencies = [ + "cc", + "cfg-if", + "libc", + "pkg-config", + "windows-sys", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "rust-github-actions-test" version = "0.1.0" +dependencies = [ + "hidapi", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index b4826aa..dda7c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +hidapi = "2.6.1" diff --git a/src/main.rs b/src/main.rs index e7a11a9..a1a611b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,40 @@ +#![warn(clippy::all, clippy::pedantic)] + fn main() { - println!("Hello, world!"); + println!( + "Hello, world!: {:?} {:?}", + std::path::MAIN_SEPARATOR, + std::env::current_dir().unwrap(), + ); + + foo(); + + match hidapi::HidApi::new() { + Ok(hidapi) => { + println!("devices:"); + for device in hidapi.device_list() { + println!( + "- vendor={:?} {:?} product={:?} {:?} serial={:?} path={:?}", + device.vendor_id(), + device.manufacturer_string(), + device.product_id(), + device.product_string(), + device.serial_number(), + device.path(), + ); + } + println!("--- done"); + } + 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"); }