diff --git a/.github/workflows/cargo-msrv.yml b/.github/workflows/cargo-msrv.yml new file mode 100644 index 0000000000..6aa1447612 --- /dev/null +++ b/.github/workflows/cargo-msrv.yml @@ -0,0 +1,76 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "Verify Minimum Supported Rust Version (MSRV)" +on: + push: + branches: [ "main", dev/*, rel/*, feature/* ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main", dev/*, feature/* ] + schedule: + - cron: '20 10 * * 3' + +jobs: + msrv: + name: Verify MSRV + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install cargo-msrv + run: cargo install cargo-msrv + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Check MSRV + run: | + # Ensure the expected MSRV file exists. + if [ ! -f MINIMUM_SUPPORTED_RUST_VERSION.txt ]; then + echo "Error: MINIMUM_SUPPORTED_RUST_VERSION.txt not found." + exit 1 + fi + + # Check the MSRV and store the output in a file. + cargo msrv find --output-format json > CARGO_MSRV.log + if [ ! -f CARGO_MSRV.log ]; then + echo "Error: Failed to detect MSRV." + exit 1 + fi + + # Read the detected MSRV from the file. + MIN_RUST_VERSION=$(jq -r 'select(.type=="subcommand_result" and .result.success==true) | .result.version' CARGO_MSRV.log) + if [ -z "$MIN_RUST_VERSION" ]; then + echo "Error: Could not determine MSRV." + exit 1 + fi + + echo "Detected minimum Rust version: $MIN_RUST_VERSION" + + # Read the expected MSRV from the file. + EXPECTED_MIN_RUST_VERSION=$(tr -d '\r\n' < MINIMUM_SUPPORTED_RUST_VERSION.txt) + echo "Expected minimum Rust version: $EXPECTED_MIN_RUST_VERSION" + + # Compare the expected MSRV with the actual MSRV. + if [ "$MIN_RUST_VERSION" != "$EXPECTED_MIN_RUST_VERSION" ]; then + echo "Error: MSRV mismatch. Expected: $EXPECTED_MIN_RUST_VERSION, Found: $MIN_RUST_VERSION" + echo "Please update 'MINIMUM_SUPPORTED_RUST_VERSION.txt' or adjust your code to be compatible with the current MSRV." + exit 1 + else + echo "MSRV check passed. Expected: $EXPECTED_MIN_RUST_VERSION, Found: $MIN_RUST_VERSION" + fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f65e24ab4..c4aa22e59c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,14 @@ math(EXPR LIBFRESHCLAM_SOVERSION "${LIBFRESHCLAM_CURRENT} - ${LIBFRESHCLAM_AGE}" set(LIBFRESHCLAM_VERSION "${LIBFRESHCLAM_SOVERSION}.${LIBFRESHCLAM_AGE}.${LIBFRESHCLAM_REVISION}") HexVersion(LIBFRESHCLAM_VERSION_NUM ${LIBFRESHCLAM_CURRENT} ${LIBFRESHCLAM_REVISION} ${LIBFRESHCLAM_AGE}) +# Minimum Rust Supported Version +# To determine this, install cargo-msrv and run: `cargo msrv` + +# # Read the MSRV (Minimum Rust Supported Version) from the MSRV.txt file. +# file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/MINIMUM_SUPPORTED_RUST_VERSION.txt" RUSTC_MINIMUM_REQUIRED +# LIMIT_COUNT 1 +# REGEX "^[0-9]+\\.[0-9]+\\.[0-9]+$") + set(GENERATE_WARNING "WARNING: This file was generated by CMake. Do not edit!") # diff --git a/MINIMUM_SUPPORTED_RUST_VERSION.txt b/MINIMUM_SUPPORTED_RUST_VERSION.txt new file mode 100644 index 0000000000..20f3b74a48 --- /dev/null +++ b/MINIMUM_SUPPORTED_RUST_VERSION.txt @@ -0,0 +1 @@ +1.85.1 \ No newline at end of file