Skip to content

Commit

Permalink
Merge pull request #5 from niklasdewally/build-using-minion
Browse files Browse the repository at this point in the history
Minion: Use minion's build system not build.rs to build libminion, and CI tweaks
  • Loading branch information
ozgurakgun authored Sep 29, 2023
2 parents f413dfa + dc84e54 commit 54c3873
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 80 deletions.
66 changes: 64 additions & 2 deletions .github/workflows/minion-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# https://doc.rust-lang.org/cargo/guide/continuous-integration.html
# https://ectobit.com/blog/speed-up-github-actions-rust-pipelines/
name: 'solvers/minion'
on:
push:
Expand All @@ -16,33 +17,94 @@ jobs:
steps:
- uses: actions/checkout@v2

# https://stackoverflow.com/questions/32327108/get-the-current-commit-id-of-specified-submodule
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Get minion hash for cache invalidation
id: minion-cache
run: |
echo "minion_sha=$(git rev-parse HEAD:solvers/minion/vendor)" >> "$GITHUB_OUTPUT"
- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
solvers/minion/vendor
key: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# match minion exactly, cargo inexactly
restore-keys: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha}}-cargo-

- working-directory: ./solvers/minion
run: rustup update stable && rustup default stable

- working-directory: ./solvers/minion
run: cargo build --verbose
run: cargo build -vv

mac:
name: 'solvers/minion: Mac Build'
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- name: Get minion hash for cache invalidation
id: minion-cache
run: |
echo "minion_sha=$(git rev-parse HEAD:solvers/minion/vendor)" >> "$GITHUB_OUTPUT"
- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
solvers/minion/vendor
key: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# match minion exactly, cargo inexactly
restore-keys: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha}}-cargo-

- working-directory: ./solvers/minion
run: rustup update stable && rustup default stable

- working-directory: ./solvers/minion
run: rustup target add aarch64-apple-darwin

- working-directory: ./solvers/minion
run: cargo build --verbose
run: cargo build -vv

tests:
name: 'solvers/minion: Tests'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# https://stackoverflow.com/questions/32327108/get-the-current-commit-id-of-specified-submodule
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Get minion hash for cache invalidation
id: minion-cache
run: |
echo "minion_sha=$(git rev-parse HEAD:solvers/minion/vendor)" >> "$GITHUB_OUTPUT"
- name: Set up cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
solvers/minion/vendor
key: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# match minion exactly, cargo inexactly
restore-keys: ${{ runner.os }}-minion-${{ steps.minion-cache.outputs.minion_sha}}-cargo-

- working-directory: ./solvers/minion
run: rustup update stable && rustup default stable

Expand Down
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "minion-bindings/vendor"]
path = solvers/minion/vendor
url = https://github.com/niklasdewally/minion
branch = conjure-oxide-devel
99 changes: 40 additions & 59 deletions solvers/minion/build.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
// adapted from
// https://github.com/gokberkkocak/rust_glucose/blob/master/build.rs
// and
// 1https://rust-lang.github.io/rust-bindgen/non-system-libraries.html
// - https://github.com/gokberkkocak/rust_glucose/blob/master/build.rs
// - https://rust-lang.github.io/rust-bindgen/non-system-libraries.html
// - https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed

use glob::glob;
use std::env;
use std::path::PathBuf;
use std::process::Command;

fn main() {
vendor_configure();
bind();
println!("cargo:rustc-rerun-if-changed=vendor");
println!("cargo:rerun-if-changed=build.rs");

// must be ./ to be recognised as relative path
// from project root
println!("cargo:rustc-link-search=all=./solvers/minion/vendor/build/");
println!("cargo:rustc-link-lib=static=minion");

// also need to (dynamically) link to c++ stdlib
// https://flames-of-code.netlify.app/blog/rust-and-cmake-cplusplus/
let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}

build();
bind();
}

fn vendor_configure() {
// ./configure.py generates cpp and h files to /vendor/build.
Command::new("bash")
.args(["prebuild.sh"])
fn build() {
let output = Command::new("bash")
.args(["build.sh"])
.output()
.expect("Failed to run prebuild.sh");
.expect("Failed to run build.sh");

/*
do cargo build -vv to see
*/
println!("stdout");
println!("{}", String::from_utf8_lossy(&output.stdout));
println!("stderr");
println!("{}", String::from_utf8_lossy(&output.stderr));

if !output.status.success() {
panic!("build.sh has non zero exit status")
}
}

fn bind() {
Expand Down Expand Up @@ -50,52 +78,5 @@ fn bind() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}

fn build() {
let mut binding = cc::Build::new();
let mut builder = binding
.include("vendor/minion")
.include("vendor/build/src")
.cpp(true)
// vendor/minion
.file("vendor/minion/minion.cpp")
.file("vendor/minion/help/help.cpp")
.file("vendor/minion/inputfile_parse/inputfile_parse.cpp")
.file("vendor/minion/system/sha1.cpp")
.file("vendor/minion/system/trigger_timer.cpp")
.file("vendor/minion/BuildCSP.cpp")
.file("vendor/minion/BuildVariables.cpp")
.file("vendor/minion/command_search.cpp")
.file("vendor/minion/commandline_parse.cpp")
.file("vendor/minion/debug_functions.cpp")
.file("vendor/minion/dump_state.cpp")
.file("vendor/minion/get_info.cpp")
.file("vendor/minion/globals.cpp")
.file("vendor/minion/info_dumps.cpp")
.file("vendor/minion/parallel.cpp")
.file("vendor/minion/preprocess.cpp")
.file("vendor/minion/search_dump.cpp")
.file("vendor/minion/search_dump_sql.cpp");

// Generated by configure.py
// vendor/build
for path in glob("vendor/build/src/*.cpp")
.unwrap()
.filter_map(Result::ok)
{
builder = builder.file(path);
}

builder
.flag_if_supported("-D__STDC_LIMIT_MACROS")
.flag_if_supported("-D__STDC_FORMAT_MACROS")
.flag_if_supported("-DNDEBUG")
.flag_if_supported("-fomit-frame-pointer")
.flag_if_supported("-std=c++11")
.flag_if_supported("-xc++")
.flag_if_supported("-w")
.opt_level(3)
.compile("minion");
.expect("Couldn't write bindings to file!");
}
23 changes: 23 additions & 0 deletions solvers/minion/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

SCRIPT_DIR=$(dirname "$0")

git submodule init
git submodule update
cd "$SCRIPT_DIR"

echo "------ CONFIGURE STEP ------"

if [ -d vendor/build ]; then
echo "vendor/build already exists; skipping"
echo "if you need to reconfigure minion (such as after an update), delete this directory!"
else
mkdir -p vendor/build
cd vendor/build
python3 ../configure.py --library
fi

echo "------ BUILD STEP ------"
cd "$SCRIPT_DIR"
cd vendor/build
make all
17 changes: 0 additions & 17 deletions solvers/minion/prebuild.sh

This file was deleted.

2 changes: 1 addition & 1 deletion solvers/minion/vendor
Submodule vendor updated 154 files

0 comments on commit 54c3873

Please sign in to comment.