Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out C-API, Python API and solver tests into their own crates #80

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/capi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: C-API

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build-test:
name: Build and test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "build-test"
- name: Cargo build
run: cargo build -p rustsat-capi --verbose
env:
CMAKE_BUILD_PARALLEL_LEVEL: ${{ fromJSON('["", "4"]')[matrix.os == 'macos-latest'] }}
- name: Cargo test
run: cargo test -p rustsat-capi --verbose
env:
CMAKE_BUILD_PARALLEL_LEVEL: ${{ fromJSON('["", "4"]')[matrix.os == 'macos-latest'] }}

version:
name: Ensure C-API crate version is in sync
runs-on: ubuntu-latest
steps:
- name: Check
run: "[ \"$(grep '^version = ' rustsat/Cargo.toml)\" = \"$(grep '^version = ' capi/Cargo.toml)\" ]"

cbindgen:
name: Test generated C header
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Check C header
run: |
cargo install cbindgen
cbindgen -c capi/cbindgen.toml --crate rustsat-capi -o capi/rustsat.h --verify
4 changes: 3 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand All @@ -24,4 +26,4 @@ jobs:
- name: Check READMEs
run: |
cargo install cargo-rdme
for dir in rustsat tools cadical kissat minisat glucose ipasir; do cd ${dir} && (cargo rdme --check || echo "failed for ${dir}"); cd ..; done
for dir in rustsat tools cadical kissat minisat glucose ipasir capi pyapi; do cd ${dir} && (cargo rdme --check || echo "failed for ${dir}"); cd ..; done
2 changes: 2 additions & 0 deletions .github/workflows/glucose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/minisat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
- name: Build Python package
uses: PyO3/maturin-action@v1
with:
args: -i python --manifest-path rustsat/Cargo.toml
args: -i python --manifest-path pyapi/Cargo.toml
- name: Install Python package
run: pip install target/wheels/rustsat*.whl
run: pip install --no-index --find-links target/wheels/ rustsat
- name: Build Python API docs
run: pip install pdoc && pdoc -o _site/pyapi/ rustsat
- name: Upload artifact
Expand Down
64 changes: 59 additions & 5 deletions .github/workflows/pyapi.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is autogenerated by maturin v1.3.2
# To update, run
#
# maturin generate-ci -m rustsat/Cargo.toml github
# maturin generate-ci -m pyapi/Cargo.toml github
#
name: Python Build

Expand All @@ -19,6 +19,44 @@ permissions:
contents: read

jobs:
build-test:
name: Build and test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "build-test"
- name: Cargo build
run: cargo build -p rustsat-pyapi --verbose
env:
CMAKE_BUILD_PARALLEL_LEVEL: ${{ fromJSON('["", "4"]')[matrix.os == 'macos-latest'] }}
- name: Cargo test
run: cargo test -p rustsat-pyapi --verbose
env:
CMAKE_BUILD_PARALLEL_LEVEL: ${{ fromJSON('["", "4"]')[matrix.os == 'macos-latest'] }}
- name: Build Python package
uses: PyO3/maturin-action@v1
with:
args: -i python --manifest-path pyapi/Cargo.toml
- name: Install Python package
run: pip install --no-index --find-links target/wheels/ rustsat
- name: Test PyAPI example
run: python pyapi/examples/pyapi-dpw.py

version:
name: Ensure Python API crate version is in sync
runs-on: ubuntu-latest
steps:
- name: Check
run: "[ \"$(grep '^version = ' rustsat/Cargo.toml)\" = \"$(grep '^version = ' pyapi/Cargo.toml)\" ]"

linux:
runs-on: ubuntu-latest
strategy:
Expand All @@ -33,7 +71,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path rustsat/Cargo.toml
args: --release --out dist --manifest-path pyapi/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
Expand All @@ -42,6 +80,22 @@ jobs:
name: wheels-linux-${{ matrix.target }}
path: dist

pystubs:
name: Test python stubs
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install maturin from PyPI
uses: install-pinned/maturin@dfebcaa782a69944b584ec164e97fbbd09885352
- name: Install mypy from PyPI
uses: install-pinned/mypy@c2223951641cbb406fa8526d08f0690899f130e4
- name: Install python project
run: maturin build -m pyapi/Cargo.toml && pip install --no-index --find-links target/wheels/ rustsat
- name: Test stubs
run: stubtest --mypy-config-file pyapi/pyproject.toml --allowlist pyapi/stubtest-allowlist.txt rustsat

windows:
runs-on: windows-latest
strategy:
Expand All @@ -57,7 +111,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path rustsat/Cargo.toml
args: --release --out dist --manifest-path pyapi/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -79,7 +133,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path rustsat/Cargo.toml
args: --release --out dist --manifest-path pyapi/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -95,7 +149,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path rustsat/Cargo.toml
args: --out dist --manifest-path pyapi/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
Expand Down
31 changes: 2 additions & 29 deletions .github/workflows/rustsat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand All @@ -32,32 +34,3 @@ jobs:
run: cargo test -p rustsat --verbose --features=all
env:
CMAKE_BUILD_PARALLEL_LEVEL: ${{ fromJSON('["", "4"]')[matrix.os == 'macos-latest'] }}

pystubs:
name: Test python stubs
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install maturin from PyPI
uses: install-pinned/maturin@dfebcaa782a69944b584ec164e97fbbd09885352
- name: Install mypy from PyPI
uses: install-pinned/mypy@c2223951641cbb406fa8526d08f0690899f130e4
- name: Install python project
run: maturin build -m rustsat/Cargo.toml && pip install --no-index --find-links target/wheels/ rustsat
- name: Test stubs
run: stubtest --mypy-config-file rustsat/pyproject.toml --allowlist rustsat/stubtest-allowlist.txt rustsat

cbindgen:
name: Test generated C header
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Check C header
run: |
cargo install cbindgen
cbindgen -c rustsat/cbindgen.toml --crate rustsat -o rustsat/rustsat.h --verify
2 changes: 2 additions & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

**/*.o
**/*.out
**/*.so

rustsat/pydocs/
**/__pycache__/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "minisat/cppsrc"]
path = minisat/cppsrc
url = git@github.com:chrjabs/minisat.git
[submodule "glucose/cppsrc"]
path = glucose/cppsrc
url = git@github.com:chrjabs/glucose4.git
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ members = [
"glucose",
"minisat",
"ipasir",
"solvertests",
"capi",
"pyapi",
]
resolver = "2"

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ crate](https://crates.io/crates/rustsat_tools) at `tools/src/bin`. For a bigger
example you can look at this [multi-objective optimization
solver](https://github.com/chrjabs/scuttle).

For an example of how to use the C-API, see `rustsat/examples/capi*.cpp`.
Similarly, for an example of using the Python API, see `rustsat/examples/pyapi*.py`.

<!-- cargo-rdme end -->

## Python Bindings
Expand Down
3 changes: 3 additions & 0 deletions cadical/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ cc = { version = "1.0.83", features = ["parallel"] }
git2 = "0.18.1"
glob = "0.3.1"
chrono = "0.4.31"

[dev-dependencies]
rustsat-solvertests = { path = "../solvertests" }
14 changes: 6 additions & 8 deletions cadical/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ fn main() {

let out_dir = env::var("OUT_DIR").unwrap();

#[cfg(target_os = "macos")]
println!("cargo:rustc-flags=-l dylib=c++");

#[cfg(not(target_os = "macos"))]
println!("cargo:rustc-flags=-l dylib=stdc++");

// Built solver is in out_dir
println!("cargo:rustc-link-search={}", out_dir);
println!("cargo:rustc-link-search={}/lib", out_dir);
Expand Down Expand Up @@ -149,14 +155,6 @@ fn build(repo: &str, branch: &str, reference: &str, patch: &str) {
.files(src_files)
.compile("cadical");
};

println!("cargo:rustc-link-lib=static=cadical");

#[cfg(target_os = "macos")]
println!("cargo:rustc-flags=-l dylib=c++");

#[cfg(not(target_os = "macos"))]
println!("cargo:rustc-flags=-l dylib=stdc++");
}

/// Returns true if there were changes, false if not
Expand Down
Loading
Loading