diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index c5a4585f..c01782e1 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -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: 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 -L .#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 diff --git a/.github/workflows/Windows.yml b/.github/workflows/Windows.yml new file mode 100644 index 00000000..4b5faedb --- /dev/null +++ b/.github/workflows/Windows.yml @@ -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/windows.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 }} diff --git a/doc/aarch64-darwin.md b/doc/aarch64-darwin.md new file mode 120000 index 00000000..dcd1e006 --- /dev/null +++ b/doc/aarch64-darwin.md @@ -0,0 +1 @@ +x86_64-darwin.md \ No newline at end of file diff --git a/doc/built/windows.md b/doc/windows.md similarity index 100% rename from doc/built/windows.md rename to doc/windows.md diff --git a/doc/built/macos.md b/doc/x86_64-darwin.md similarity index 100% rename from doc/built/macos.md rename to doc/x86_64-darwin.md diff --git a/doc/built/linux.md b/doc/x86_64-linux.md similarity index 100% rename from doc/built/linux.md rename to doc/x86_64-linux.md diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..0db1ca68 --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "v1.0.0", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714531828, + "narHash": "sha256-ILsf3bdY/hNNI/Hu5bSt2/KbmHaAVhBbNUOdGztTHEg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0638fe2715d998fa81d173aad264eb671ce2ebc1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..0bb14c47 --- /dev/null +++ b/flake.nix @@ -0,0 +1,132 @@ +{ + description = "Packages and development environments for d4"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + flake-utils.url = "github:numtide/flake-utils/v1.0.0"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + let + lib = nixpkgs.lib; + systems = lib.systems.doubles.unix; + in flake-utils.lib.eachSystem systems (system: + let + pkgs = import nixpkgs { inherit system; }; + + tbb = if pkgs.stdenv.isDarwin + && lib.versionOlder pkgs.stdenv.hostPlatform.darwinMinVersion + "10.13" then + pkgs.tbb + else + pkgs.tbb_2021_8; + in { + formatter = pkgs.nixfmt; + + packages = { + default = self.packages.${system}.d4; + + d4 = pkgs.stdenv.mkDerivation { + pname = "d4"; + version = "2.0"; + + src = ./.; + + buildInputs = [ + self.packages.${system}.mt-kahypar + pkgs.boost.dev + pkgs.gmp.dev + ]; + + nativeBuildInputs = [ pkgs.cmake pkgs.ninja ]; + + meta = with lib; { + description = "A CNF to d-DNNF compiler"; + homepage = "https://github.com/SoftVarE-Group/d4v2"; + license = licenses.lgpl3Plus; + platforms = systems; + }; + }; + + container = pkgs.dockerTools.buildLayeredImage { + name = "d4v2"; + contents = [ self.packages.${system}.d4 ]; + config.Entrypoint = [ "/bin/d4" ]; + }; + + mt-kahypar = pkgs.stdenv.mkDerivation { + pname = "mt-kahypar"; + version = "1.4"; + + src = pkgs.fetchgit { + url = "https://github.com/kahypar/mt-kahypar.git"; + rev = "c51ffeaa3b1040530bf821b7f323e3790b147b33"; + hash = "sha256-MlF6ZGsqtGQxzDJHbvo5uFj+6w8ehr9V4Ul5oBIGzws="; + fetchSubmodules = true; + }; + + outputs = [ "out" "dev" ]; + + buildInputs = [ pkgs.boost.dev pkgs.git pkgs.hwloc.dev tbb.dev ]; + + nativeBuildInputs = [ pkgs.cmake pkgs.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-deps = pkgs.buildEnv { + name = "bundled-deps"; + paths = [ + self.packages.${system}.mt-kahypar + pkgs.hwloc.lib + pkgs.boost + pkgs.gmp + tbb + ] ++ lib.optionals pkgs.stdenv.cc.isClang [ + pkgs.libcxx + pkgs.libcxxabi + ]; + }; + + bundled-doc = pkgs.stdenv.mkDerivation { + name = "bundled-doc"; + src = ./doc; + installPhase = '' + mkdir $out + cp ${system}.md $out/README.md + ''; + }; + + bundled = pkgs.buildEnv { + name = "bundled"; + paths = [ + self.packages.${system}.d4 + self.packages.${system}.bundled-deps + self.packages.${system}.bundled-doc + ]; + }; + }; + }); +} diff --git a/mt-kahypar-pc.patch b/mt-kahypar-pc.patch new file mode 100644 index 00000000..c9ab7956 --- /dev/null +++ b/mt-kahypar-pc.patch @@ -0,0 +1,19 @@ +diff '--color=auto' -Naur a/lib/CMakeLists.txt b/lib/CMakeLists.txt +--- a/lib/CMakeLists.txt 2024-04-30 16:31:54.639650905 +0200 ++++ b/lib/CMakeLists.txt 2024-04-30 16:32:12.586535317 +0200 +@@ -22,15 +22,10 @@ + + target_include_directories(mtkahypar SYSTEM PUBLIC ../include) + +-configure_file(libmtkahypar.pc.in libmtkahypar.pc @ONLY) +- + install(TARGETS mtkahypar + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +-install(FILES ${CMAKE_BINARY_DIR}/lib/libmtkahypar.pc +- DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) +- + configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY) + + add_custom_target(uninstall-mtkahypar "${CMAKE_COMMAND}" -P cmake_uninstall.cmake)