From 1be97dd559400410af90b65c704b7dc6af833bac Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 12 Apr 2024 10:48:20 -0700 Subject: [PATCH] fix windows build We shouldn't be passing gcc params to MSVC Signed-off-by: William Casarin --- .github/workflows/linux.yml | 29 ++++++++++++++++++ .github/workflows/rust.yml | 55 ----------------------------------- .github/workflows/windows.yml | 55 +++++++++++++++++++++++++++++++++++ build.rs | 27 +++++++++++------ ci/build_and_test.bat | 8 +++++ 5 files changed, 110 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/linux.yml delete mode 100644 .github/workflows/rust.yml create mode 100644 .github/workflows/windows.yml create mode 100644 ci/build_and_test.bat diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..8d7e09b --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,29 @@ +name: Linux + +on: + push: + branches: + - master + - ci + pull_request: + branches: + - master + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Initialize Submodules + run: git submodule update --init --recursive + - name: Build + run: cargo build --verbose + - name: Tests + run: cargo test --verbose + - name: Clippy + run: cargo clippy ${{ matrix.build-args }} -- -D warnings + diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index f970ec3..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Rust - -on: - push: - branches: [ "master", "ci" ] - pull_request: - branches: [ "master" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Initialize Submodules - run: git submodule update --init --recursive - - name: Build - run: cargo build --verbose - - name: Tests - run: cargo test --verbose - - name: Clippy - run: cargo clippy ${{ matrix.build-args }} -- -D warnings - - build-msrv-1660: - name: Build - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - version: stable # STABLE - - version: 1.66.0 # MSRV - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Cache - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-msrv-1.66.0-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - - name: Set default toolchain - run: rustup default ${{ matrix.rust.version }} - - name: Set profile - run: rustup set profile minimal && rustup component add clippy - - name: Build - run: cargo build ${{ matrix.build-args }} - - name: Tests - run: cargo test ${{ matrix.build-args }} - - name: Clippy - run: cargo clippy ${{ matrix.build-args }} -- -D warnings diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..0b43699 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,55 @@ +name: Windows +on: + push: + branches: + - master + - ci + pull_request: + +jobs: + test: + runs-on: windows-latest + name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }}) + strategy: + fail-fast: false + matrix: + target: [ + i686-pc-windows-gnu, + i686-pc-windows-msvc, + x86_64-pc-windows-gnu, + x86_64-pc-windows-msvc, + ] + cfg_release_channel: [nightly, stable] + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Initialize Submodules + run: git submodule update --init --recursive + + # Run build + - name: Install Rustup using win.rustup.rs + run: | + # Disable the download progress bar which can cause perf issues + $ProgressPreference = "SilentlyContinue" + Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe + .\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none + del rustup-init.exe + rustup target add ${{ matrix.target }} + shell: powershell + + - name: Add mingw32 to path for i686-gnu + run: | + echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH + if: matrix.target == 'i686-pc-windows-gnu' && matrix.channel == 'nightly' + shell: bash + + - name: Add mingw64 to path for x86_64-gnu + run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH + if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly' + shell: bash + + - name: Build and Test + shell: cmd + run: ci\build_and_test.bat diff --git a/build.rs b/build.rs index 3962132..90152d8 100644 --- a/build.rs +++ b/build.rs @@ -74,15 +74,24 @@ fn main() { ]) .include("nostrdb/deps/lmdb") .include("nostrdb/deps/flatcc/include") - .include("nostrdb/deps/secp256k1/include") - // Add other include paths - //.flag("-Wall") - .flag("-Wno-sign-compare") - .flag("-Wno-misleading-indentation") - .flag("-Wno-unused-function") - .flag("-Wno-unused-parameter"); - //.flag("-Werror") - //.flag("-g") + .include("nostrdb/deps/secp256k1/include"); + + // Detect the compiler being used: MSVC or GCC (like MinGW on Windows) + if env::var("TARGET").unwrap().contains("msvc") { + // MSVC-specific flags + // Example: build.flag("/W4"); // Set warning level to 4 for MSVC + // Suppress specific warnings in MSVC: + build.flag("/wd4100"); // unreferenced formal parameter + // Add more MSVC-specific flags as needed + } else { + // GCC-specific flags + build + .flag("-Wno-sign-compare") + .flag("-Wno-misleading-indentation") + .flag("-Wno-unused-function") + .flag("-Wno-unused-parameter"); + // Add more GCC-specific flags as needed + } if env::var("PROFILE").unwrap() == "debug" { build.flag("-DDEBUG"); diff --git a/ci/build_and_test.bat b/ci/build_and_test.bat new file mode 100644 index 0000000..74734c3 --- /dev/null +++ b/ci/build_and_test.bat @@ -0,0 +1,8 @@ +set "RUSTFLAGS=-D warnings" + +:: Print version information +rustc -Vv || exit /b 1 +cargo -V || exit /b 1 + +cargo build || exit /b 1 +cargo test || exit /b 1