Skip to content

Commit

Permalink
Merge pull request #90 from alliander-opensource/feature/simplify-build
Browse files Browse the repository at this point in the history
Simplify build process
  • Loading branch information
TonyXiang8787 authored Jul 18, 2022
2 parents f8e810b + 5c0fd3c commit 0a4e808
Show file tree
Hide file tree
Showing 33 changed files with 1,312 additions and 1,334 deletions.
50 changes: 18 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ jobs:

build-cpp-test-linux:
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch') || (!startsWith(github.head_ref, 'release'))
runs-on: ubuntu-latest
container: ghcr.io/alliander-opensource/power-grid-model-build-env:latest
runs-on: ubuntu-22.04
strategy:
matrix:
build-option: [ Debug, Release ]
cpp-compiler: [g++-11, clang++-14]
env:
CMAKE_PREFIX_PATH: /home/linuxbrew/.linuxbrew
CXX: ${{ matrix.cpp-compiler }}

steps:
- uses: actions/checkout@v3

- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build
- name: Install C++ dependencies
run: |
brew install boost eigen nlohmann-json doctest
- name: Run build script
run: ./build.sh ${{ matrix.build-option }}

Expand All @@ -50,16 +59,14 @@ jobs:
& "$env:CONDA\condabin\conda" init
- name: Install conda environment
# TODO removed pinned v2 of catch2, see https://github.com/alliander-opensource/power-grid-model/issues/73
run: |
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen nlohmann_json catch2==2.13.9
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen nlohmann_json doctest
- name: Build and test
run: |
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath
Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64'
$env:Path += ";C:\conda_envs\cpp_pkgs\Library\bin"
mkdir cpp_build_${{ matrix.build-option }}
cd cpp_build_${{ matrix.build-option }}
# generate cmake cache
Expand Down Expand Up @@ -88,10 +95,8 @@ jobs:
- uses: actions/checkout@v3

- name: Install cpp dependencies
# TODO removed pinned v2 of catch2, see https://github.com/alliander-opensource/power-grid-model/issues/73
run: |
brew install ninja boost eigen nlohmann-json
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/5e5abb11bf49787d01164c4066119365262c21ed/Formula/catch2.rb > $(find $(brew --repository) -name catch2.rb) && brew reinstall catch2
brew install ninja boost eigen nlohmann-json doctest
- name: Build and test
run: |
Expand All @@ -106,24 +111,18 @@ jobs:
os: ubuntu-latest
cc: gcc
cxx: g++
boost:
eigen:
cibw_build: "cp*-manylinux_x86_64 cp*-manylinux_aarch64"
archs: "x86_64 aarch64"
- platform: macos
os: macos-latest
cc: clang
cxx: clang++
boost: /usr/local/include
eigen: /usr/local/include/eigen3
cibw_build: cp*-macosx_*
archs: "x86_64 arm64"
- platform: windows
os: windows-latest
cc:
cxx:
boost: C:\conda_envs\cpp_pkgs\Library\include
eigen: C:\conda_envs\cpp_pkgs\Library\include\eigen3
cibw_build: cp*-win_amd64
archs: AMD64

Expand All @@ -133,26 +132,18 @@ jobs:
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
BOOST_INCLUDE: ${{ matrix.boost }}
EIGEN_INCLUDE: ${{ matrix.eigen }}
CIBW_BUILD_VERBOSITY: 1
CIBW_BUILD_FRONTEND: "build"
CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_ARCHS: ${{ matrix.archs }}
CIBW_TEST_REQUIRES: pytest pytest-cov
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: pytest {package}/tests
# Skip trying to test arm64 builds on Intel Macs
CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64"
CIBW_MANYLINUX_X86_64_IMAGE: ghcr.io/alliander-opensource/power-grid-model-build-env
CIBW_MANYLINUX_AARCH64_IMAGE: ghcr.io/alliander-opensource/power-grid-model-build-env-arm64
CIBW_ENVIRONMENT_PASS_LINUX: GITHUB_SHA GITHUB_REF GITHUB_RUN_NUMBER
CIBW_BEFORE_ALL_MACOS: >
which clang++ &&
clang++ --version &&
brew install boost eigen
CIBW_ENVIRONMENT_PASS_LINUX: GITHUB_SHA GITHUB_REF GITHUB_RUN_NUMBER CC CXX
MACOSX_DEPLOYMENT_TARGET: 10.15
CIBW_BEFORE_ALL_WINDOWS : >
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014

steps:
- uses: actions/checkout@v3
Expand All @@ -161,11 +152,6 @@ jobs:
if: matrix.platform == 'linux'
uses: docker/setup-qemu-action@v2

- name: Activate conda for windows
if: matrix.platform == 'windows'
run: |
& "$env:CONDA\condabin\conda" init
- name: Build wheels
uses: pypa/[email protected]

Expand Down
28 changes: 21 additions & 7 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@ jobs:
sonar-cloud:
if: (github.event_name == 'push') || (!startsWith(github.head_ref, 'release'))
name: SonarCloud
runs-on: ubuntu-latest
container: ghcr.io/alliander-opensource/power-grid-model-build-env-sonar:latest
runs-on: ubuntu-22.04
env:
SONAR_SCANNER_VERSION: 4.4.0.2170
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
CMAKE_PREFIX_PATH: /home/linuxbrew/.linuxbrew
LLVM_COV: llvm-cov-14
CC: clang-14
CXX: clang++-14
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build lcov gcovr
- name: Install C++ dependencies
run: |
brew install boost eigen nlohmann-json doctest
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'microsoft'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
Expand All @@ -52,16 +66,15 @@ jobs:
- name: Python test and coverage
run: |
/opt/venv/bin/pip install -e .
/opt/venv/bin/pip install -r dev-requirements.txt
/opt/venv/bin/pytest
pip install -e .[dev]
pytest
# remove cython generated cpp file
rm -rf src/power_grid_model/*.cpp
- name: Run build-wrapper for C++
run: |
mkdir cpp_build
cmake -S . -B cpp_build -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
cmake -S . -B cpp_build -GNinja -DCMAKE_BUILD_TYPE=Debug -DPOWER_GRID_MODEL_COVERAGE=1
VERBOSE=1 build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build cpp_build/
- name: C++ test and coverage
Expand All @@ -74,7 +87,8 @@ jobs:
sed -i -r "s/\s*branchesToCover\s*=\s*\"[0-9]+\"\s+coveredBranches\s*=\s*\"[0-9]+\"//g" cpp_coverage.xml
- name: Run sonar-scanner
if: github.event_name == 'push' # only run sonar server in push event
# only run sonar server in push event or pull request event from own repo
if: github.event_name == 'push' || ${{ github.event.pull_request.head.repo.owner.login }} == 'alliander-opensource'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
6 changes: 2 additions & 4 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
Expand All @@ -21,8 +20,7 @@
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}
10 changes: 0 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ fi
BUILD_DIR=cpp_build_$1
echo "Build dir: ${BUILD_DIR}"

if [[ ! -z "${VCPKG_ROOT}" ]]; then
PATH_FOR_CMAKE=-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
elif [[ ! -z "${CMAKE_PREFIX_PATH}" ]]; then
PATH_FOR_CMAKE=-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
else
PATH_FOR_CMAKE=
fi

echo ${PATH_FOR_CMAKE}

rm -rf ${BUILD_DIR}/
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
Expand Down
6 changes: 0 additions & 6 deletions dev-requirements.txt

This file was deleted.

Loading

0 comments on commit 0a4e808

Please sign in to comment.