From 65f5d26644544b0fff4928cfd25994f04310f40b Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Tue, 25 Jun 2024 10:22:31 +1000 Subject: [PATCH] Update CaDiCaL to work on Windows --- .github/workflows/rust.yml | 50 +++++--------------- crates/pindakaas-cadical/build.rs | 7 +++ crates/pindakaas-cadical/src/msvc/unistd.h | 55 ++++++++++++++++++++++ crates/pindakaas-derive/src/lib.rs | 2 + 4 files changed, 77 insertions(+), 37 deletions(-) create mode 100644 crates/pindakaas-cadical/src/msvc/unistd.h diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 95b8ede9b9..1eb59afa02 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,28 +13,11 @@ env: RUST_FMT_CHANNEL: nightly jobs: - # build: - # runs-on: ubuntu-latest - # strategy: - # matrix: - # crate: [] - # steps: - # - uses: actions/checkout@v3 - # - name: Install Rust toolchain - # run: | - # rustup toolchain install --profile minimal --no-self-update ${{ env.RUST_CHANNEL }} - # rustup default ${{ env.RUST_CHANNEL }} - # - name: Cache dependencies - # uses: Swatinem/rust-cache@v2 - # - name: Build ${{ matrix.crate }} - # run: cargo install --root dist/ --path crates/${{ matrix.crate }} - # - name: Upload build artifact - # uses: actions/upload-artifact@v3 - # with: - # name: ${{ matrix.crate }}-${{ matrix.os }} - # path: dist/ test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 with: @@ -43,10 +26,14 @@ jobs: run: | rustup toolchain install --profile minimal --no-self-update ${{ env.RUST_CHANNEL }} rustup default ${{ env.RUST_CHANNEL }} - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Run cargo test + run: cargo test --features splr,cadical,kissat,intel-sat,ipasir-up + if: matrix.os == 'ubuntu-latest' - name: Run cargo test - run: cargo test --all-features + run: cargo test -p pindakaas --features splr,cadical,ipasir-up + if: matrix.os == 'windows-latest' clippy: runs-on: ubuntu-latest steps: @@ -57,8 +44,8 @@ jobs: run: | rustup toolchain install --profile minimal --component clippy --no-self-update ${{ env.RUST_CHANNEL }} rustup default ${{ env.RUST_CHANNEL }} - - name: Cache dependencies - uses: Swatinem/rust-cache@v2 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.5 - name: Run clippy run: cargo clippy --tests --features splr,cadical,kissat,intel-sat,ipasir-up -- -D warnings format: @@ -73,14 +60,3 @@ jobs: rustup default ${{ env.RUST_CHANNEL }} - name: Run cargo format run: cargo +nightly fmt --all --check - # TODO: Re-enable after first release - # semver: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # with: - # submodules: true - # - name: Check semver - # uses: obi1kenobi/cargo-semver-checks-action@v2 - # with: - # crate-name: pindakaas diff --git a/crates/pindakaas-cadical/build.rs b/crates/pindakaas-cadical/build.rs index 7ba8069fa8..2d56fdaec0 100644 --- a/crates/pindakaas-cadical/build.rs +++ b/crates/pindakaas-cadical/build.rs @@ -1,3 +1,5 @@ +use std::path::Path; + fn main() { let src = [ "src/ccadical_override.cpp", @@ -94,6 +96,11 @@ fn main() { .define("NTRACING", None) .define("QUIET", None); + if build.get_compiler().is_like_msvc() { + build.include(Path::new("src/msvc")); + build.define(r"__attribute__\(x\)", ""); + } + assert_eq!( env!("CARGO_PKG_VERSION"), include_str!("vendor/cadical/VERSION").trim() diff --git a/crates/pindakaas-cadical/src/msvc/unistd.h b/crates/pindakaas-cadical/src/msvc/unistd.h new file mode 100644 index 0000000000..ec6ebe4f0f --- /dev/null +++ b/crates/pindakaas-cadical/src/msvc/unistd.h @@ -0,0 +1,55 @@ +#ifndef _UNISTD_H +#define _UNISTD_H 1 + +/* This is intended as a drop-in replacement for unistd.h on Windows. + * Please add functionality as needed. + * https://stackoverflow.com/a/826027/1202830 + */ + +#include +#include +#include /* for getpid() and the exec..() family */ +#include /* for _getcwd() and _chdir() */ + +#define srandom srand +#define random rand + +/* Values for the second argument to access. + These may be OR'd together. */ +#define R_OK 4 /* Test for read permission. */ +#define W_OK 2 /* Test for write permission. */ +//#define X_OK 1 /* execute permission - unsupported in windows*/ +#define F_OK 0 /* Test for existence. */ + +#define access _access +#define dup2 _dup2 +#define execve _execve +#define ftruncate _chsize +#define unlink _unlink +#define fileno _fileno +#define getcwd _getcwd +#define chdir _chdir +#define isatty _isatty +#define lseek _lseek +/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ + +#ifdef _WIN64 +#define ssize_t __int64 +#else +#define ssize_t long +#endif + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +/* should be in some equivalent to */ +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +#endif /* unistd.h */ diff --git a/crates/pindakaas-derive/src/lib.rs b/crates/pindakaas-derive/src/lib.rs index 711bcf15bf..2fd5e8f289 100644 --- a/crates/pindakaas-derive/src/lib.rs +++ b/crates/pindakaas-derive/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::manual_unwrap_or_default)] // TODO: Remove this when fixed in darling + use darling::FromDeriveInput; use proc_macro::TokenStream; use quote::{format_ident, quote};