From 40fd7d3e823bfe0e6ba0ec8f880b2ed77b08637b Mon Sep 17 00:00:00 2001 From: Jan Baudisch Date: Fri, 3 May 2024 00:38:44 +0200 Subject: [PATCH] feat: enable nix build --- .github/workflows/CI.yaml | 32 ++++++ .github/workflows/{CI.yml => Windows.yaml} | 60 ++-------- flake.lock | 127 +++++++++++++++++++++ flake.nix | 81 +++++++++++++ 4 files changed, 249 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/CI.yaml rename .github/workflows/{CI.yml => Windows.yaml} (63%) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..ae92f78 --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,32 @@ +name: CI + +on: + - push + +jobs: + Build: + strategy: + fail-fast: false + matrix: + target: + - triple: x86_64-unknown-linux-gnu + runner: ubuntu-latest + - triple: x86_64-apple-darwin + runner: macos-13 + - triple: aarch64-apple-darwin + runner: macos-latest + runs-on: ${{ matrix.target.runner }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Nix + uses: DeterminateSystems/nix-installer-action@v10 + - name: Cache + uses: DeterminateSystems/magic-nix-cache-action@v4 + - name: Build + run: nix build .#bundled + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: ddnnife-d4-${{ matrix.target.triple }} + path: result diff --git a/.github/workflows/CI.yml b/.github/workflows/Windows.yaml similarity index 63% rename from .github/workflows/CI.yml rename to .github/workflows/Windows.yaml index 1b9079b..d6a4ca4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/Windows.yaml @@ -1,6 +1,7 @@ name: CI -on: [workflow_dispatch, push] +on: + - push env: CARGO_TERM_COLOR: always @@ -9,66 +10,35 @@ env: CMAKE_CXX_COMPILER_LAUNCHER: sccache RUSTC_WRAPPER: sccache SCCACHE_GHA_ENABLED: true - # FIXME: cc-rs on mac currently won't set the C++ standard correctly (https://github.com/dtolnay/cxx/issues/1217). - CXXFLAGS: -std=c++17 jobs: - Format: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Format - run: cargo fmt --check - Build: strategy: fail-fast: false matrix: target: - - os: linux - runner: ubuntu-latest - triple: x86_64-unknown-linux-gnu - shell: bash - coverage: true - - os: macos - runner: macos-latest - triple: x86_64-apple-darwin - shell: bash - - os: windows - runner: windows-latest - triple: x86_64-pc-windows-gnu - shell: msys2 - msystem: ucrt64 + - triple: x86_64-pc-windows-gnu toolchain: - stable d4: - include - exclude - runs-on: ${{ matrix.target.runner }} + runs-on: windows-latest defaults: run: - shell: ${{ matrix.target.shell }} {0} + shell: msys2 {0} env: CARGO_BUILD_TARGET: ${{ matrix.target.triple }} steps: - name: Checkout uses: actions/checkout@v4 - name: Setup MSYS2 (Windows) - if: ${{ matrix.target.os == 'windows' }} uses: msys2/setup-msys2@v2 with: path-type: inherit - msystem: ${{ matrix.target.msystem }} + msystem: ucrt64 pacboy: git m4 cmake:p ninja:p - - name: Install dependencies (Linux) - if: ${{ matrix.target.os == 'linux' }} - run: sudo apt-get install ninja-build libtbb-dev libhwloc-dev libboost-program-options-dev - - name: Install dependencies (macOS) - if: ${{ matrix.target.os == 'macos' }} - run: brew install ninja boost hwloc tbb - - name: Install dependencies (Windows) - if: ${{ matrix.target.os == 'windows' }} + - name: Install dependencies run: | pacboy -S --noconfirm toolchain:p tbb:p hwloc:p boost:p mv /${{ matrix.target.msystem }}/lib/libtbb12.dll.a /${{ matrix.target.msystem }}/lib/libtbb.dll.a @@ -91,29 +61,18 @@ jobs: 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/ -# 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 (including d4) if: ${{ matrix.d4 == 'include' }} run: cargo build - name: Build (excluding d4) if: ${{ matrix.d4 == 'exclude' }} run: cargo build --no-default-features - - name: Test - # FIXME: Some tests are currently not platform independent and fail on macos and windows and without d4 - if: ${{ matrix.d4 == 'include' && matrix.target.os != 'macos' && matrix.target.os != 'windows' }} - run: cargo test - - name: Install coverage tool - if: ${{ matrix.target.coverage }} - uses: taiki-e/install-action@cargo-llvm-cov - - name: Coverage - if: ${{ matrix.target.coverage && matrix.d4 == 'include' }} - run: cargo llvm-cov - name: Package run: | mkdir -p $BUILD_ROOT/bin @@ -130,8 +89,7 @@ jobs: if: ${{ matrix.d4 == 'exclude' }} run: | cp doc/built/${{ matrix.target.os }}.md $BUILD_ROOT/README.md - - name: Package dependencies (Windows) - if: ${{ matrix.target.os == 'windows' }} + - name: Package dependencies run: | ./package-msys.bash $BUILD_ROOT $BUILD_ROOT/bin/* rm -f $BUILD_ROOT/bin/b2 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a571e7d --- /dev/null +++ b/flake.lock @@ -0,0 +1,127 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710886643, + "narHash": "sha256-saTZuv9YeZ9COHPuj8oedGdUwJZcbQ3vyRqe7NVJMsQ=", + "owner": "ipetkov", + "repo": "crane", + "rev": "5bace74e9a65165c918205cf67ad3977fe79c584", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "ref": "v0.16.3", + "repo": "crane", + "type": "github" + } + }, + "d4": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714688695, + "narHash": "sha256-ZKVxTY6fOLDhE28mswcrxFdWrXfruch6EJD8V4R8WCY=", + "owner": "SoftVarE-Group", + "repo": "d4v2", + "rev": "5ca09bcc603a7b4ba5b6348e5c52b4f15628097c", + "type": "github" + }, + "original": { + "owner": "SoftVarE-Group", + "ref": "nix", + "repo": "d4v2", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "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": { + "crane": "crane", + "d4": "d4", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713752081, + "narHash": "sha256-x0QDETp7paa8qq+LX6191JwSq8abUFXCnKNulQ8L7ps=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "606c0ecb23c676c444a0b026eecf800d5bd5fec2", + "type": "github" + }, + "original": { + "owner": "oxalica", + "ref": "stable", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d7b44fc --- /dev/null +++ b/flake.nix @@ -0,0 +1,81 @@ +{ + description = "Packages and development environments for d4"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + crane = { + url = "github:ipetkov/crane/v0.16.3"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay/stable"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + d4 = { + url = "github:SoftVarE-Group/d4v2/nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, crane, rust-overlay, d4, ... }: + 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: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + lib = pkgs.lib; + toolchain = pkgs.rust-bin.stable.latest.default; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + in { + default = self.packages.${system}.ddnnife; + + ddnnife = craneLib.buildPackage { + pname = "ddnnife"; + version = "0.7.0"; + + src = pkgs.fetchFromGitHub { + owner = "SoftVarE-Group"; + repo = "d-dnnf-reasoner"; + rev = "main"; + hash = "sha256-uUzzuKOmTeGAyIHJpRTrarNx5uSBTtXUzn0pJS7SZM4="; + }; + + strictDeps = true; + + buildInputs = + [ pkgs.boost.dev pkgs.gmp.dev d4.packages.${system}.mt-kahypar ]; + + nativeBuildInputs = [ pkgs.gnum4 pkgs.pkg-config ]; + + doCheck = false; + + meta = with lib; { + description = "A d-DNNF reasoner"; + homepage = "https://github.com/SoftVarE-Group/d-dnnf-reasoner"; + license = licenses.lgpl3Plus; + platforms = systems; + }; + }; + + container = pkgs.dockerTools.buildLayeredImage { + name = "ddnnife"; + contents = [ self.packages.${system}.ddnnife ]; + config.Entrypoint = [ "/bin/ddnnife" ]; + }; + + bundled = pkgs.buildEnv { + name = "bundled"; + paths = + [ self.packages.${system}.ddnnife d4.packages.${system}.bundled-deps ]; + }; + }); + }; +}