Build shared and static in CI (#7472)
authorGereon Kremer <nafur42@gmail.com>
Thu, 28 Oct 2021 01:08:13 +0000 (18:08 -0700)
committerGitHub <noreply@github.com>
Thu, 28 Oct 2021 01:08:13 +0000 (01:08 +0000)
This PR changes our strategy to deal with shared vs. static builds in CI jobs.
All jobs now build cvc5 both shared and static by default. The builds happen in different build directories (build-shared and build-static), and we configure ccache such that these two build directories share a common cache.

.github/actions/add-to-release/action.yml
.github/actions/build-documentation/action.yml
.github/actions/configure-and-build/action.yml [new file with mode: 0644]
.github/actions/install-dependencies/action.yml
.github/actions/run-tests/action.yml
.github/actions/setup-cache/action.yml
.github/workflows/ci.yml

index 1db34bdf88d0e738534f90d16f2edb0014649b3d..a5939e20cda6910d951bcc6518f9405887b2fada 100644 (file)
@@ -1,6 +1,8 @@
 name: Add binary to release
 description: Add cvc5 binary to the current release
 inputs:
+  binary:
+    description: file name of binary
   github-token:
     description: token to upload binary
 runs:
@@ -9,7 +11,7 @@ runs:
     - name: Rename binaries for release
       shell: bash
       run: |
-        cp build/bin/cvc5 cvc5-${{ runner.os }}
+        cp ${{ inputs.binary }} cvc5-${{ runner.os }}
 
     - name: Add binaries to release
       uses: softprops/action-gh-release@v1
index cb5587c516ba953d09f3d82b4f4669d67e7dca47..8224ac4bbb46002bbb642f1b99c5ef62ec6e97e1 100644 (file)
@@ -1,5 +1,8 @@
 name: Build documentation
 description: Build documentation and store it as artifact
+inputs:
+  build-dir:
+    default: build
 runs:
   using: composite
   steps:
@@ -10,10 +13,10 @@ runs:
         if [ "${{ github.event_name }}" == "pull_request" ] ; then
           echo "${{ github.event.number }}" > docs/sphinx-gh/prnum
         fi
-      working-directory: build
+      working-directory: ${{ inputs.build-dir }}
     
     - name: Store Documentation
       uses: actions/upload-artifact@v2
       with:
         name: documentation
-        path: build/docs/sphinx-gh/
+        path: ${{ inputs.build-dir }}/docs/sphinx-gh/
diff --git a/.github/actions/configure-and-build/action.yml b/.github/actions/configure-and-build/action.yml
new file mode 100644 (file)
index 0000000..4e2bea7
--- /dev/null
@@ -0,0 +1,62 @@
+name: Configure and build
+description: Run configure script and build
+inputs:
+  configure-env:
+    default: ""
+  configure-config:
+    default: ""
+  build-shared:
+    default: true
+  build-static:
+    default: true
+outputs:
+  shared-build-dir:
+    description: build directory of the shared build
+    value: ${{ steps.shared-build.outputs.build-dir }}
+  static-build-dir:
+    description: build directory of the static build
+    value: ${{ steps.static-build.outputs.build-dir }}
+runs:
+  using: composite
+  steps:
+    - name: Shared build
+      id: shared-build
+      shell: bash
+      run: |
+        echo "::group::Shared build"
+        if [[ "${{ inputs.build-shared }}" != "true" ]]; then exit 0; fi
+        ${{ inputs.configure-env }} ./configure.sh ${{ inputs.configure-config }} \
+          --prefix=$(pwd)/build-shared/install --werror --name=build-shared
+        
+        # can not use `ccache --set-config=base_dir=` due to ccache bug, fixed with 3.7.10
+        cd build-shared/ && pwd=$(pwd)
+        $SED -i.orig -n -e '/^base_dir = /!p' -e "\$abase_dir = $pwd" $CCACHE_CONFIGPATH
+        
+        make -j${{ env.num_proc }}
+
+        echo "::set-output name=build-dir::$pwd"
+        echo "::endgroup::"
+
+    - name: Static build
+      id: static-build
+      shell: bash
+      run: |
+        echo "::group::Static build"
+        if [[ "${{ inputs.build-static }}" != "true" ]]; then exit 0; fi
+        ${{ inputs.configure-env }} ./configure.sh ${{ inputs.configure-config }} \
+          --prefix=$(pwd)/build-static/install --werror --static --name=build-static
+
+        cd build-static/ && pwd=$(pwd)
+        $SED -i.orig -n -e '/^base_dir = /!p' -e "\$abase_dir = $pwd" $CCACHE_CONFIGPATH
+
+        make -j${{ env.num_proc }}
+
+        echo "::set-output name=build-dir::$pwd"
+        echo "::endgroup::"
+        
+    - name: Reset ccache base_dir
+      shell: bash
+      run: |
+        echo "::group::Reset ccache base_dir"
+        $SED -i.orig -n -e '/^base_dir = /!p' -e "\$abase_dir =" $CCACHE_CONFIGPATH
+        echo "::endgroup::"
index f019594b28d65292719afabc774df2dcd53ef229..d1fb975a9d2135f25ae71b58b8981fabacc59c88 100644 (file)
@@ -11,6 +11,7 @@ runs:
     - name: Install Linux software
       shell: bash
       run: |
+        echo "::group::Install Linux software"
         if [[ $RUNNER_OS != "Linux" ]]; then exit 0; fi
         sudo apt-get update
         sudo apt-get install -y \
@@ -34,14 +35,18 @@ runs:
         # variables of the runner are not automatically imported:
         #
         # https://github.com/actions/runner/blob/master/docs/adrs/0278-env-context.md#dont-populate-the-env-context-with-environment-variables-from-runner-machine
+        echo "SED=sed" >> $GITHUB_ENV
+        echo "CCACHE_CONFIGPATH=/home/runner/.ccache/ccache.conf" >> $GITHUB_ENV
         echo "image_version=$ImageVersion" >> $GITHUB_ENV
         echo "num_proc=$(nproc)" >> $GITHUB_ENV
         echo "/usr/lib/ccache" >> $GITHUB_PATH
+        echo "::endgroup::"
 
     # Note: macOS comes with a libedit; it does not need to brew-installed
     - name: Install macOS software
       shell: bash
       run: |
+        echo "::group::Install macOS software"
         if [[ $RUNNER_OS != "macOS" ]]; then exit 0; fi
         brew update --quiet
         brew install \
@@ -49,31 +54,39 @@ runs:
           cln \
           gmp \
           pkgconfig \
-          flex
+          flex \
+          gnu-sed
         python3 -m pip install pexpect setuptools toml
         # Make ImageVersion accessible as env.image_version. Environment
         # variables of the runner are not automatically imported:
         #
         # https://github.com/actions/runner/blob/master/docs/adrs/0278-env-context.md#dont-populate-the-env-context-with-environment-variables-from-runner-machine
+        echo "SED=gsed" >> $GITHUB_ENV
+        echo "CCACHE_CONFIGPATH=/Users/runner/Library/Preferences/ccache/ccache.conf" >> $GITHUB_ENV
         echo "image_version=$ImageVersion" >> $GITHUB_ENV
         echo "num_proc=$(sysctl -n hw.logicalcpu)" >> $GITHUB_ENV
         echo "/usr/local/opt/ccache/libexec" >> $GITHUB_PATH
+        echo "::endgroup::"
 
-    - name: Install Python packages
+    - name: Install software for Python bindings
       shell: bash
       run: |
+        echo "::group::Install software for Python bindings"
         if [[ "${{ inputs.with-python-bindings }}" != "true" ]]; then exit 0; fi
         python3 -m pip install pytest scikit-build
         python3 -m pytest --version
         python3 -m pip install \
           Cython==0.29.* --install-option="--no-cython-compile"
         echo "$(python3 -m site --user-base)/bin" >> $GITHUB_PATH
+        echo "::endgroup::"
     
     - name: Install software for documentation
       shell: bash
       run: |
+        echo "::group::Install software for documentation"
         if [[ "${{ inputs.with-documentation }}" != "true" ]]; then exit 0; fi
         sudo apt-get install -y doxygen python3-docutils python3-jinja2
         python3 -m pip install \
           sphinxcontrib-bibtex sphinx-tabs sphinx-rtd-theme breathe \
           sphinxcontrib-programoutput
+        echo "::endgroup::"
index 2b2326699d38216148cad38a47f5740768f19ed8..bc3936d477e219524486d195a4f4d49dccd73737 100644 (file)
@@ -1,6 +1,8 @@
 name: Run tests
 description: Run all available tests
 inputs:
+  build-dir:
+    default: build/
   check-examples:
     default: true
   check-python-bindings:
@@ -22,14 +24,14 @@ runs:
         ARGS: --output-on-failure -LE regress[${{ inputs.regressions-exclude }}]
         CVC5_REGRESSION_ARGS: --no-early-exit
         RUN_REGRESSION_ARGS: ${{ inputs.regressions-args }}
-      working-directory: build
+      working-directory: ${{ inputs.build-dir }}
 
     - name: Run Unit Tests
       shell: bash
       run: |
         if [[ "${{ inputs.check-unit-tests }}" != "true" ]]; then exit 0; fi
         make -j${{ env.num_proc }} apitests units
-      working-directory: build
+      working-directory: ${{ inputs.build-dir }}
 
     - name: Install Check
       shell: bash
@@ -37,13 +39,13 @@ runs:
         make -j${{ env.num_proc }} install
         echo -e "#include <cvc5/cvc5.h>\nint main() { cvc5::api::Solver s; return 0; }" > /tmp/test.cpp
         g++ -std=c++17 /tmp/test.cpp -I install/include -L install/lib -lcvc5
-      working-directory: build
+      working-directory: ${{ inputs.build-dir }}
 
     - name: Python Install Check
       shell: bash
       run: |
         if [[ "${{ inputs.check-python-bindings }}" != "true" ]]; then exit 0; fi
-        export PYTHONPATH="$PYTHONPATH:$(dirname $(find build/install/ -name "pycvc5" -type d))"
+        export PYTHONPATH="$PYTHONPATH:$(dirname $(find ${{ inputs.build-dir }}/install/ -name "pycvc5" -type d))"
         python3 -c "import pycvc5"
 
     - name: Check Examples
@@ -52,7 +54,7 @@ runs:
         if [[ "${{ inputs.check-examples }}" != "true" ]]; then exit 0; fi
         mkdir build
         cd build
-        cmake .. -DCMAKE_PREFIX_PATH=$(pwd)/../../build/install/lib/cmake
+        cmake .. -DCMAKE_PREFIX_PATH=${{ inputs.build-dir }}/install/lib/cmake
         make -j${{ env.num_proc }}
         ctest -j${{ env.num_proc }} --output-on-failure
-      working-directory: examples
\ No newline at end of file
+      working-directory: examples
index ad485f2dc05a1acaccd54e3fbdb620db090157b4..5a20ebcdcc0e1db2f152b5b69e9296dc72369114 100644 (file)
@@ -64,6 +64,8 @@ runs:
     - name: Setup dependencies cache
       uses: actions/cache@v2
       with:
-        path: build/deps
+        path: |
+          build-shared/deps
+          build-static/deps
         key: ${{ inputs.cache-key }}-${{ runner.os }}-deps-${{ hashFiles('cmake/**') }}-${{ hashFiles('.github/**') }}
 
index 89c108b93249efd200e0e8da45b65d3b725a3cb2..82916f26b4187fe8389ca91442ccf20558f0d3f0 100644 (file)
@@ -70,15 +70,12 @@ jobs:
       with:
         cache-key: ${{ matrix.cache-key }}
 
-    - name: Configure
-      run: |
-        ${{ matrix.env }} ./configure.sh ${{ matrix.config }} \
-          --prefix=$(pwd)/build/install \
-          --werror
-
-    - name: Build
-      run: make -j${{ env.num_proc }}
-      working-directory: build
+    - name: Configure and build
+      id: configure-and-build
+      uses: ./.github/actions/configure-and-build
+      with:
+        configure-env: ${{ matrix.env }}
+        configure-config: ${{ matrix.config }}
 
     - name: ccache Statistics
       run: ccache -s
@@ -86,6 +83,7 @@ jobs:
     - name: Run tests
       uses: ./.github/actions/run-tests
       with:
+        build-dir: ${{ steps.configure-and-build.outputs.shared-build-dir }}
         check-examples: ${{ matrix.check-examples }}
         check-python-bindings: ${{ matrix.python-bindings }}
         check-unit-tests: ${{ matrix.check-units }}
@@ -95,9 +93,12 @@ jobs:
     - name: Build documentation
       if: matrix.build-documentation
       uses: ./.github/actions/build-documentation
+      with:
+        build-dir: ${{ steps.configure-and-build.outputs.shared-build-dir }}
 
     - name: Add binary to release
       if: matrix.store-to-release && startsWith(github.ref, 'refs/tags/')
       uses: ./.github/actions/add-to-release
       with:
+        binary: ${{ steps.configure-and-build.outputs.static-build-dir }}/bin/cvc5
         github-token: ${{ secrets.GITHUB_TOKEN }}