Skip to content

Commit

Permalink
feat: enable nix build
Browse files Browse the repository at this point in the history
  • Loading branch information
uulm-janbaudisch committed May 2, 2024
1 parent 8cd1816 commit 31b1d93
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 115 deletions.
125 changes: 10 additions & 115 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,135 +3,30 @@ name: CI
on:
- push

env:
CMAKE_GENERATOR: Ninja
SCCACHE_GHA_ENABLED: true

jobs:
Build:
strategy:
fail-fast: false
matrix:
target:
- os: linux
- triple: x86_64-unknown-linux-gnu
runner: ubuntu-latest
triple: x86_64-unknown-linux-gnu
shell: bash
- os: macos
- triple: x86_64-apple-darwin
runner: macos-13
triple: x86_64-apple-darwin
shell: bash
- os: macos
- triple: aarch64-apple-darwin
runner: macos-latest
triple: aarch64-apple-darwin
shell: bash
- os: windows
runner: windows-latest
triple: x86_64-pc-windows-gnu
shell: msys2
compiler:
- cc: gcc
cxx: g++
msystem: ucrt64
- cc: clang
cxx: clang++
msystem: clang64
solver:
- minisat
- glucose
exclude:
- target: { os: macos }
compiler: { cc: gcc }
runs-on: ${{ matrix.target.runner }}
defaults:
run:
shell: ${{ matrix.target.shell }} {0}
env:
CC: ${{ matrix.compiler.cc }}
CXX: ${{ matrix.compiler.cxx }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup MSYS2
if: ${{ matrix.target.os == 'windows' }}
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: ${{ matrix.compiler.msystem }}
pacboy: git cmake:p ninja:p
- name: Install dependencies
if: ${{ matrix.target.os == 'linux' }}
run: sudo apt install ninja-build libboost-program-options-dev libhwloc-dev libtbb-dev
- name: Install dependencies
if: ${{ matrix.target.os == 'macos' }}
run: brew install ninja boost hwloc tbb
- name: Install dependencies
if: ${{ matrix.target.os == 'windows' }}
run: |
pacboy -S --noconfirm toolchain:p boost:p gmp:p hwloc:p tbb:p
mv /${{ matrix.compiler.msystem }}/lib/libtbb12.dll.a /${{ matrix.compiler.msystem }}/lib/libtbb.dll.a
- name: Setup sccache
if: ${{ matrix.target.triple != 'aarch64-apple-darwin' }}
uses: mozilla-actions/sccache-action@v0.0.4
- name: Setup sccache environment
if: ${{ matrix.target.triple != 'aarch64-apple-darwin' }}
run: |
echo CMAKE_C_COMPILER_LAUNCHER=sccache >> $GITHUB_ENV
echo CMAKE_CXX_COMPILER_LAUNCHER=sccache >> $GITHUB_ENV
- name: Setup environment
run: |
export BUILD_ROOT=$(mktemp -d)
echo BUILD_ROOT=$BUILD_ROOT >> $GITHUB_ENV
echo BUILD_ROOT_EXPORT=$(python3 -c "import os; print(os.environ['BUILD_ROOT'])") >> $GITHUB_ENV
- name: Build Mt-KaHyPar
run: |
cd $(mktemp -d)
git clone --recursive https://github.com/kahypar/mt-kahypar.git .
cmake -B build -D CMAKE_INSTALL_PREFIX=$BUILD_ROOT -D MT_KAHYPAR_DISABLE_BOOST=true
cmake --build build --target mtkahypar
cmake --install build
mkdir -p $BUILD_ROOT/licenses/mt-kahypar
cp LICENSE $BUILD_ROOT/licenses/mt-kahypar/
# TODO: currently, macOS is only supported on master, move below clone to check out latest version when released.
# git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
- name: Build glucose
if: ${{ matrix.solver == 'glucose' }}
run: |
cd 3rdParty/glucose-3.0
cmake -B build -D CMAKE_INSTALL_PREFIX=$BUILD_ROOT
cmake --build build --target glucose
cmake --install build
- name: Configure
run: >-
cmake -B build
-D CMAKE_INSTALL_PREFIX=$BUILD_ROOT
-D MtKaHyPar_ROOT=$BUILD_ROOT
-D glucose_ROOT=$BUILD_ROOT
-D D4_SOLVER=${{ matrix.solver }}
-D D4_PREPROC_SOLVER=${{ matrix.solver }}
- name: Nix
uses: DeterminateSystems/nix-installer-action@v10
- name: Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v4
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build
- name: Package
if: ${{ matrix.target.os == 'windows' }}
run: |
./package-msys.bash $BUILD_ROOT $BUILD_ROOT/bin/*
rm -f $BUILD_ROOT/bin/b2
rm -f $BUILD_ROOT/bin/bjam
rm -f $BUILD_ROOT/bin/glucose
rm -f $BUILD_ROOT/bin/hwloc*
rm -f $BUILD_ROOT/bin/lstopo*
rm -rf $BUILD_ROOT/lib
- name: Package
run: |
rm -rf $BUILD_ROOT/include
rm -rf $BUILD_ROOT/share
mkdir -p $BUILD_ROOT/licenses/d4
cp LICENSE $BUILD_ROOT/licenses/d4/
cp doc/built/${{ matrix.target.os }}.md $BUILD_ROOT/README.md
run: nix build .#bundled
- name: Upload
uses: actions/upload-artifact@v4
with:
name: d4-${{ matrix.target.triple }}-${{ matrix.compiler.cc }}-${{ matrix.solver }}
path: ${{ env.BUILD_ROOT_EXPORT }}
name: d4-${{ matrix.target.triple }}
path: result
111 changes: 111 additions & 0 deletions .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Windows

on:
- push

env:
CMAKE_GENERATOR: Ninja
SCCACHE_GHA_ENABLED: true

jobs:
Build:
strategy:
fail-fast: false
matrix:
target:
- os: windows
runner: windows-latest
triple: x86_64-pc-windows-gnu
shell: msys2
compiler:
- cc: gcc
cxx: g++
msystem: ucrt64
- cc: clang
cxx: clang++
msystem: clang64
solver:
- minisat
- glucose
runs-on: ${{ matrix.target.runner }}
defaults:
run:
shell: msys2 {0}
env:
CC: ${{ matrix.compiler.cc }}
CXX: ${{ matrix.compiler.cxx }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup MSYS2
if: ${{ matrix.target.os == 'windows' }}
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: ${{ matrix.compiler.msystem }}
pacboy: git cmake:p ninja:p
- name: Install dependencies
run: |
pacboy -S --noconfirm toolchain:p boost:p gmp:p hwloc:p tbb:p
mv /${{ matrix.compiler.msystem }}/lib/libtbb12.dll.a /${{ matrix.compiler.msystem }}/lib/libtbb.dll.a
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.4
- name: Setup sccache environment
run: |
echo CMAKE_C_COMPILER_LAUNCHER=sccache >> $GITHUB_ENV
echo CMAKE_CXX_COMPILER_LAUNCHER=sccache >> $GITHUB_ENV
- name: Setup environment
run: |
export BUILD_ROOT=$(mktemp -d)
echo BUILD_ROOT=$BUILD_ROOT >> $GITHUB_ENV
echo BUILD_ROOT_EXPORT=$(python3 -c "import os; print(os.environ['BUILD_ROOT'])") >> $GITHUB_ENV
- name: Build Mt-KaHyPar
run: |
cd $(mktemp -d)
git clone --recursive https://github.com/kahypar/mt-kahypar.git .
git checkout c51ffeaa3b1040530bf821b7f323e3790b147b33
cmake -B build -D CMAKE_INSTALL_PREFIX=$BUILD_ROOT -D MT_KAHYPAR_DISABLE_BOOST=true
cmake --build build --target mtkahypar
cmake --install build
mkdir -p $BUILD_ROOT/licenses/mt-kahypar
cp LICENSE $BUILD_ROOT/licenses/mt-kahypar/
- name: Build glucose
if: ${{ matrix.solver == 'glucose' }}
run: |
cd 3rdParty/glucose-3.0
cmake -B build -D CMAKE_INSTALL_PREFIX=$BUILD_ROOT
cmake --build build --target glucose
cmake --install build
- name: Configure
run: >-
cmake -B build
-D CMAKE_INSTALL_PREFIX=$BUILD_ROOT
-D MtKaHyPar_ROOT=$BUILD_ROOT
-D glucose_ROOT=$BUILD_ROOT
-D D4_SOLVER=${{ matrix.solver }}
-D D4_PREPROC_SOLVER=${{ matrix.solver }}
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build
- name: Package
run: |
./package-msys.bash $BUILD_ROOT $BUILD_ROOT/bin/*
rm -f $BUILD_ROOT/bin/b2
rm -f $BUILD_ROOT/bin/bjam
rm -f $BUILD_ROOT/bin/glucose
rm -f $BUILD_ROOT/bin/hwloc*
rm -f $BUILD_ROOT/bin/lstopo*
rm -rf $BUILD_ROOT/lib
- name: Package
run: |
rm -rf $BUILD_ROOT/include
rm -rf $BUILD_ROOT/share
mkdir -p $BUILD_ROOT/licenses/d4
cp LICENSE $BUILD_ROOT/licenses/d4/
cp doc/built/${{ matrix.target.os }}.md $BUILD_ROOT/README.md
- name: Upload
uses: actions/upload-artifact@v4
with:
name: d4-${{ matrix.target.triple }}-${{ matrix.compiler.cc }}-${{ matrix.solver }}
path: ${{ env.BUILD_ROOT_EXPORT }}
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
description = "Packages and development environments for d4";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";

outputs = { self, nixpkgs, ... }:
let
systems = nixpkgs.lib.systems.doubles.unix;
eachSystem = nixpkgs.lib.genAttrs systems;
in {
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt;

packages = eachSystem (system:
with import nixpkgs { inherit system; }; {
default = self.packages.${system}.d4;

d4 = stdenv.mkDerivation {
pname = "d4";
version = "2.0";

src = fetchgit {
url = "https://github.com/SoftVarE-Group/d4v2.git";
rev = "8cd1816ca10a9286ea7955ef9f37b5001f976290";
hash = "sha256-GmlU0w/skqMcTIrLDaYU7eZxxdEJRjnDFOOyaXBBbbU=";
};

buildInputs =
[ self.packages.${system}.mt-kahypar boost.dev gmp.dev ];

nativeBuildInputs = [ cmake ninja ];

meta = with lib; {
description = "A CNF to d-DNNF compiler";
homepage = "https://github.com/SoftVarE-Group/d4v2";
license = licenses.lgpl3Plus;
platforms = systems;
};
};

container = dockerTools.buildLayeredImage {
name = "d4v2";
contents = [ self.packages.${system}.d4 ];
config.Entrypoint = [ "/bin/d4" ];
};

mt-kahypar = let
tbb' = if stdenv.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "11.0" then
tbb
else
tbb_2021_8;
in stdenv.mkDerivation {
pname = "mt-kahypar";
version = "1.4";

src = fetchgit {
url = "https://github.com/kahypar/mt-kahypar.git";
rev = "c51ffeaa3b1040530bf821b7f323e3790b147b33";
hash = "sha256-MlF6ZGsqtGQxzDJHbvo5uFj+6w8ehr9V4Ul5oBIGzws=";
fetchSubmodules = true;
};

buildInputs = [ boost.dev git hwloc.dev tbb'.dev ];

nativeBuildInputs = [ cmake ninja ];

patches = [ ./mt-kahypar-pc.patch ];

cmakeFlags = [
"-D KAHYPAR_PYTHON=false"
"-D MT_KAHYPAR_DISABLE_BOOST=true"
"-D KAHYPAR_ENFORCE_MINIMUM_TBB_VERSION=false"
"-G Ninja"
];

buildPhase = "cmake --build . --target mtkahypar";
installPhase = "cmake --install .";

meta = with lib; {
description =
"A shared-memory multilevel graph and hypergraph partitioner";
longDescription = ''
Mt-KaHyPar (Multi-Threaded Karlsruhe Hypergraph Partitioner) is a shared-memory multilevel graph and hypergraph partitioner equipped with parallel implementations of techniques used in the best sequential partitioning algorithms.
Mt-KaHyPar can partition extremely large hypergraphs very fast and with high quality.
'';
homepage = "https://github.com/kahypar/mt-kahypar";
license = licenses.mit;
platforms = systems;
};
};

bundled = buildEnv {
name = "bundled";
paths =
[ self.packages.${system}.d4 self.packages.${system}.mt-kahypar ] ++ lib.optionals stdenv.isDarwin [ libcxx libcxxabi tbb_2021_8 hwloc.lib boost gmp ];
};
});
};
}
Loading

0 comments on commit 31b1d93

Please sign in to comment.