From 32d1e2cd29de98e136279248d14bdc0c99b4a953 Mon Sep 17 00:00:00 2001 From: Melfely Date: Tue, 8 Sep 2026 16:43:50 -0500 Subject: [PATCH] ci: Added lint.yml which tests for linting and build on multiple platforms This uses a 3 step process Lint -> Linux x86 Build -> [Linux x86 Test, Windows x86 Build, MacOS Check, Linux aarch64 Build] The build steps being seperate from the linux build is so that its clear WHICH OS is preventing the build, along with if it doesn't build for linux x86 (MY dev machines) then there is ZERO point in checking other OS since all of my work happens on linux x86. This reduces Runtime on just outright bad pull-requests. Then we have plenty of runners, so we can easily run all 4 of the other jobs in the final step in parallel. The MacOS steps includes a build BUT will pass regardless of its output, because the build step for MacOS is fairly unrelaible, so this relies on a check only. The main difference between a check and a builds is that build calls the linker, while the check does not. Since the linker commonly fails in a cross-compile, while check verifies the rust code itself is techincally compatible with the OS. (IE no dependencies outright do not support the target). Which is a good enough for the most part. --- .cargo/config.toml | 2 + .gitea/workflows/lint.yml | 150 ++++++++++++++++++++++++++++++++++++++ Cargo.lock | 11 +++ Cargo.toml | 3 + example_bin/Cargo.toml | 6 ++ example_bin/src/main.rs | 3 + example_lib/Cargo.toml | 6 ++ example_lib/src/lib.rs | 14 ++++ 8 files changed, 195 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitea/workflows/lint.yml create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 example_bin/Cargo.toml create mode 100644 example_bin/src/main.rs create mode 100644 example_lib/Cargo.toml create mode 100644 example_lib/src/lib.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..4bf0f90 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[registries.gitea] +index = "sparse+https://gitea.example.com/api/packages/crates/cargo/" diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..cd6cbe6 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,150 @@ +name: Crossplatform Linting && Build + +on: + push: + branches: [ main, master ] + pull_request: + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Install cargo sort + uses: taiki-e/install-action@v2 + with: + tool: cargo-sort + + - name: Install cargo machete + uses: taiki-e/install-action@v2 + with: + tool: cargo-machete + + - name: Check formatting + run: cargo fmt --check + + - name: Check import sorting + run: cargo sort --workspace --grouped --check --check-format + + - name: Check for unused dependencies + run: cargo machete + + - name: Clippy for Linux x86 (GNU ONLY) + run: | + cargo clippy --target x86_64-unknown-linux-gnu -- -D warnings + build: + name: Build + runs-on: ubuntu-latest + needs: lint + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-unknown-linux-musl + + - name: Build for Linux x86 (GNU and MUSL) + run: | + cargo build --target x86_64-unknown-linux-gnu --release --locked + cargo build --target x86_64-unknown-linux-musl --release --locked + + + cross_build_linux: + name: Cross-Build-Linux + runs-on: ubuntu-latest + needs: [lint, build] + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Crosscompile for aarch64 linux, windows, macos + uses: zijiren233/cargo-cross@v1 + with: + targets: | + aarch64-unknown-linux-musl + aarch64-unknown-linux-gnu + + cross_build_windows: + name: Cross-Build-Windows + runs-on: ubuntu-latest + needs: [lint, build] + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Crosscompile for targets + uses: zijiren233/cargo-cross@v1 + with: + targets: | + x86_64-pc-windows-gnu + + cross_Build_osx: + name: Cross-Build-MacOS + runs-on: ubuntu-latest + needs: [lint, build] + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + + # CrossCheck for MacOS first, which checks for a valid rust project on MacOS + - name: Crosscheck for MacOS + uses: zijiren233/cargo-cross@v1 + with: + command: check + targets: | + aarch64-apple-darwin + + + # MacOS is known for having a problematic linker step from linux, we should not fail the job if this fails, but this Workflow ALSO has the seperate cargo check + - name: Crosscompile for targets + continue-on-error: true + uses: zijiren233/cargo-cross@v1 + with: + targets: | + aarch64-apple-darwin + + test_linux: + name: Test + runs-on: ubuntu-latest + needs: [build, lint] + + steps: + - name: Checkout Project + uses: actions/checkout@v5 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-unknown-linux-musl + + - name: Test for Linux x86 (GNU and MUSL) + run: | + cargo test --target x86_64-unknown-linux-gnu --release --locked + cargo test --target x86_64-unknown-linux-musl --release --locked + + diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3bc11c1 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,11 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "example_bin" +version = "0.1.0" + +[[package]] +name = "example_lib" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c609f26 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "3" +members = ["example_bin", "example_lib"] diff --git a/example_bin/Cargo.toml b/example_bin/Cargo.toml new file mode 100644 index 0000000..d734bc5 --- /dev/null +++ b/example_bin/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "example_bin" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/example_bin/src/main.rs b/example_bin/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/example_bin/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/example_lib/Cargo.toml b/example_lib/Cargo.toml new file mode 100644 index 0000000..2794f7e --- /dev/null +++ b/example_lib/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "example_lib" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/example_lib/src/lib.rs b/example_lib/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/example_lib/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}