Skip to content

Commit

Permalink
[CI][CMAKE][SCRIPT][PY] Fix some issues when building on GitHub
Browse files Browse the repository at this point in the history
* Build scripts *

- Added
  + Support for --no-gitee
  + Support for not building the documentation

* CMake *

- Added
  + ENABLE_DOCUMENTATION option (defaults to OFF)
- Changed
  + Do not perform RPATH/RUNPATH test when compiling for local developments
  + Do not bother with RPATH/RUNPATH for local builds (ie. if not for wheel packaging)
  + Remove explicit setting of RPATH for mqbackend
- Fixed
  + Make sure that test executable are built with "build" RPATH
    (NB: those are never installed or packaged anyway so that should be fine)
  + Force static compilation of gmp if compiled locally

* Python *

- Updated
  + Improved argument parsing in setup.py

* GitHub Actions *

- Updated
  + Configuration to avoid build failures
  • Loading branch information
Takishima committed Jun 22, 2022
1 parent e48f943 commit f20d499
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 83 deletions.
64 changes: 47 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ jobs:
- name: Configure
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --no-gitee --debug
--configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"
-- -DPython_FIND_UNVERSIONED_NAMES:STRING='FIRST'
- name: Build
run: ./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache
Expand All @@ -108,12 +109,7 @@ jobs:
- name: Run C++ tests
run: |
cd build
ctest --output-on-failure
- name: Run Python tests
run: |
. venv/bin/activate
python3 -m pytest -v
catchsegv ctest --output-on-failure
# ------------------------------------------------------------------------

Expand Down Expand Up @@ -176,7 +172,7 @@ jobs:
mkdir -p "${{ github.workspace }}/wheel_build"
cp -r "${{ github.workspace }}/build/.mqlibs" "${{ github.workspace }}/wheel_build"
./build.sh --cxx --with-projectq --debug-cmake --test --build="${{ github.workspace }}/wheel_build" \
--no-delocate --ccache --cmake-no-registry
--no-delocate --ccache --cmake-no-registry --no-gitee
# ============================================================================

Expand Down Expand Up @@ -239,7 +235,7 @@ jobs:

- name: Configure
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest --no-gitee --debug
--configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"
- name: Build
Expand All @@ -248,6 +244,11 @@ jobs:
- name: Install
run: ./build_locally.sh --install # NB: no need to pass the other parameters

- name: Run C++ tests
run: |
cd build
ctest --output-on-failure
# ============================================================================

gcc:
Expand Down Expand Up @@ -319,7 +320,7 @@ jobs:

- name: Configure
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest --no-gitee --debug
--configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"
- name: Build
Expand All @@ -328,6 +329,10 @@ jobs:
- name: Install
run: ./build_locally.sh --install # NB: no need to pass the other parameters

- name: Run C++ tests
run: |
cd build
catchsegv ctest --output-on-failure
# ============================================================================

Expand Down Expand Up @@ -405,7 +410,7 @@ jobs:

- name: Configure
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache --only-pytest --no-gitee --debug
--configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"
- name: Build
Expand All @@ -414,6 +419,11 @@ jobs:
- name: Install
run: ./build_locally.sh --install # NB: no need to pass the other parameters

- name: Run C++ tests
run: |
cd build
catchsegv ctest --output-on-failure
# ============================================================================

msvc:
Expand Down Expand Up @@ -482,7 +492,7 @@ jobs:
CC: cl
CXX: cl
run: >-
./build_locally.ps1 -Cxx -WithProjectq -DebugCmake -Ninja -Test -CCache -OnlyPytest
./build_locally.ps1 -Cxx -WithProjectq -DebugCmake -Ninja -Test -CCache -OnlyPytest -NoGitee
-ConfigureOnly -C -Clean3rdParty -Prefix "${{ github.workspace }}/install"
-DUSE_PARALLEL_STL=OFF
Expand All @@ -492,6 +502,11 @@ jobs:
- name: Install
run: ./build_locally.ps1 -Install

# - name: Run C++ tests
# run: |
# cd build
# ctest --output-on-failure

- name: Print CCache statistics
run: |
ccache -sv
Expand Down Expand Up @@ -577,7 +592,7 @@ jobs:
CC: cc
CXX: c++
run: >-
./build_locally.ps1 -Cxx -WithProjectq -DebugCmake -Ninja -Test -CCache -OnlyPytest
./build_locally.ps1 -Cxx -WithProjectq -DebugCmake -Ninja -Test -CCache -OnlyPytest -NoGitee
-ConfigureOnly -C -Clean3rdParty -Prefix "${{ github.workspace }}/install"
-G "MinGW Makefiles" -DUSE_PARALLEL_STL=OFF
Expand All @@ -587,6 +602,11 @@ jobs:
- name: Install
run: ./build_locally.ps1 -Install

- name: Run C++ tests
run: |
cd build
ctest --output-on-failure
# ============================================================================

msys2:
Expand Down Expand Up @@ -720,7 +740,7 @@ jobs:
CC: ${{ matrix.CC }}
CXX: ${{ matrix.CXX }}
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache -v --only-pytest
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache -v --only-pytest --no-gitee
--configure-only -c --clean-3rdparty --prefix="$PWD/install"
${{ matrix.cmake_generator }}
Expand Down Expand Up @@ -846,7 +866,7 @@ jobs:
shell: bash --login -eo pipefail -o igncr {0}
run: |
export PATH="$PATH:$PWD/ccache/bin"
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache -v --only-pytest \
./build_locally.sh --cxx --with-projectq --debug-cmake --test --ccache -v --only-pytest --no-gitee \
--configure-only -c --clean-3rdparty --prefix=$PWD/install \
${{ matrix.cmake_generator }}
Expand All @@ -860,6 +880,11 @@ jobs:
shell: bash --login -eo pipefail -o igncr {0}
run: ./build_locally.sh --install

- name: Run C++ tests
run: |
cd build
ctest --output-on-failure
- name: Print CCache statistics
shell: bash --login -eo pipefail -o igncr {0}
run: |
Expand Down Expand Up @@ -945,7 +970,7 @@ jobs:

- name: Configure
run: >-
./build_locally.sh --cxx --with-projectq --debug-cmake --gpu --test --ccache --only-pytest
./build_locally.sh --cxx --with-projectq --debug-cmake --gpu --test --ccache --only-pytest --no-gitee
--configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"
- name: Build
Expand All @@ -954,6 +979,11 @@ jobs:
- name: Install
run: ./build_locally.sh --install

- name: Run C++ tests
run: |
cd build
catchsegv ctest --output-on-failure
# ============================================================================

# NB: Disabled due to compilation error in tweedledum library
Expand Down Expand Up @@ -1025,7 +1055,7 @@ jobs:
# if [ -f /opt/intel/oneapi/tbb/latest/env/vars.sh ]; then
# source /opt/intel/oneapi/tbb/latest/env/vars.sh
# fi
# ./build_locally.sh --cxx --with-projectq --debug-cmake --test --gpu \
# ./build_locally.sh --cxx --with-projectq --debug-cmake --test --gpu --no-gitee \
# --configure-only -c --clean-3rdparty --prefix="${{ github.workspace }}/install"

# - name: Build
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ endif()

# ==============================================================================

if(NOT IS_PYTHON_BUILD)
if(NOT IS_PYTHON_BUILD AND ENABLE_DOCUMENTATION)
find_package(Doxygen QUIET)
if(Doxygen_FOUND)
add_subdirectory(docs)
Expand Down
4 changes: 4 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Param(
[switch]$Ninja,
[switch]$NoBuildIsolation,
[switch]$NoDelocate,
[switch]$NoGitee,
[switch]$OnlyPytest,
[Alias("O")][ValidateNotNullOrEmpty()][string]$Output,
[ValidateNotNullOrEmpty()][string]$PlatName,
Expand Down Expand Up @@ -399,6 +400,9 @@ Ignore any configuration file
.PARAMETER NoDelocate
Do not delocate the binary wheels after build is finished (pass -Delocate to enable)
.PARAMETER NoGitee
Do not favor Gitee over Github/Gitlab
.PARAMETER OnlyPytest
Only install pytest and its dependencies when creating/building the virtualenv
Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ fi
# ==============================================================================
# Default values for this particular script

enable_gitee=1
if [ "$_IS_MINDSPORE_CI" -eq 1 ]; then
enable_gitee=1
fi

# ------------------------------------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions build_locally.bat
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ if !enable_gpu! == 1 (
if NOT "!cuda_arch!" == "" set cmake_args=!cmake_args! -DCMAKE_CUDA_ARCHITECTURES:STRING=!cuda_arch!
)

if !do_docs! == 1 (
set cmake_args=!cmake_args! -DENABLE_DOCUMENTATION:BOOL=ON
) else (
set cmake_args=!cmake_args! -DENABLE_DOCUMENTATION:BOOL=OFF
)

if !enable_projectq! == 1 (
set cmake_args=!cmake_args! -DENABLE_PROJECTQ:BOOL=ON
) else (
Expand Down
5 changes: 5 additions & 0 deletions build_locally.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Param(
[Alias("J")][ValidateRange("Positive")][int]$Jobs,
[switch]$Ninja,
[switch]$NoConfig,
[switch]$NoGitee,
[switch]$OnlyPytest,
[ValidateNotNullOrEmpty()][string]$Prefix,
[switch]$Quiet,
Expand Down Expand Up @@ -195,6 +196,7 @@ $cmake_args = @('-DIN_PLACE_BUILD:BOOL=ON'
"-DENABLE_CMAKE_DEBUG:BOOL={0}" -f $CMAKE_BOOL[$cmake_debug_mode]
"-DENABLE_CUDA:BOOL={0}" -f $CMAKE_BOOL[$enable_gpu]
"-DENABLE_CXX_EXPERIMENTAL:BOOL={0}" -f $CMAKE_BOOL[$enable_cxx]
"-DENABLE_DOCUMENTATION:BOOL={0}" -f $CMAKE_BOOL[$do_docs]
"-DENABLE_GITEE:BOOL={0}" -f $CMAKE_BOOL[$enable_gitee]
"-DBUILD_TESTING:BOOL={0}" -f $CMAKE_BOOL[$enable_tests]
"-DCLEAN_3RDPARTY_INSTALL_DIR:BOOL={0}" -f $CMAKE_BOOL[$do_clean_3rdparty]
Expand Down Expand Up @@ -395,6 +397,9 @@ Build using Ninja instead of make
.PARAMETER NoConfig
Ignore any configuration file
.PARAMETER NoGitee
Do not favor Gitee over Github/Gitlab
.PARAMETER OnlyPytest
Only install pytest and its dependencies when creating/building the virtualenv
Expand Down
1 change: 1 addition & 0 deletions build_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ cmake_args=(-DIN_PLACE_BUILD:BOOL=ON
-DENABLE_CMAKE_DEBUG:BOOL="${CMAKE_BOOL[$cmake_debug_mode]}"
-DENABLE_CUDA:BOOL="${CMAKE_BOOL[$enable_gpu]}"
-DENABLE_CXX_EXPERIMENTAL:BOOL="${CMAKE_BOOL[$enable_cxx]}"
-DENABLE_DOCUMENTATION:BOOL="${CMAKE_BOOL[$do_docs]}"
-DENABLE_GITEE:BOOL="${CMAKE_BOOL[$enable_gitee]}"
-DBUILD_TESTING:BOOL="${CMAKE_BOOL[$enable_tests]}"
-DCLEAN_3RDPARTY_INSTALL_DIR:BOOL="${CMAKE_BOOL[$do_clean_3rdparty]}"
Expand Down
2 changes: 0 additions & 2 deletions ccsrc/mqbackend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ target_include_directories(mqbackend PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LI
force_at_least_cxx17_workaround(mqbackend)
target_link_libraries(mqbackend PUBLIC ${MQ_OPENMP_TARGET} "$<$<BOOL:${ENABLE_PROJECTQ}>:mq_projectq>" mq_base)

python_install_set_rpath(mqbackend "")

get_target_property(_mqbackend_output_dir mqbackend LIBRARY_OUTPUT_DIRECTORY)
if(NOT _mqbackend_output_dir)
set(_mqbackend_output_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
Expand Down
9 changes: 7 additions & 2 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#
# All of this should achieve the desired effect on all platforms and compilers

set(CMAKE_BUILD_SKIP_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
if(IN_PLACE_BUILD)
set(CMAKE_BUILD_SKIP_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
else()
set(CMAKE_BUILD_SKIP_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()

# CMake usually does not add /usr/local/include to any compiler commands. This can lead to some issues on Mac OS when
# using the -isysroot option so we allow for explicit -I/usr/local/include on the command line.
Expand Down
4 changes: 3 additions & 1 deletion cmake/linker_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ else()
endif()

if(UNIX AND NOT APPLE)
if(NOT DEFINED _cmake_rpath_check)
if(IN_PLACE_BUILD)
set(_cmake_rpath_check FALSE)
elseif(NOT DEFINED _cmake_rpath_check)
set(_cmake_rpath_check FALSE)
find_program(_readelf readelf)
if(_readelf)
Expand Down
2 changes: 2 additions & 0 deletions cmake/macros_more.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function(add_test_executable target)

add_executable(${target} ${target}.cpp ${${target}_UNPARSED_ARGUMENTS})
force_at_least_cxx17_workaround(${target})
# NB: these will never be installed so need RPATH if we want to run them
set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE SKIP_BUILD_RPATH FALSE)
target_include_directories(${target} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/tests>
$<INSTALL_INTERFACE:${MQ_INSTALL_INCLUDEDIR}/include/tests>)
target_link_libraries(${target} PRIVATE Catch2::Catch2 ${${target}_LIBS})
Expand Down
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ include(CMakeDependentOption)
option(ENABLE_PROJECTQ "Enable ProjectQ support" ON)
option(ENABLE_GITEE "Use Gitee instead of GitHub for checking out third-party dependencies" OFF)
option(ENABLE_CXX_EXPERIMENTAL "Enable the new (experimental) C++ backend" OFF)
option(ENABLE_DOCUMENTATION "Enable building of the documentation using Doxygen" OFF)

# ==============================================================================
# Python related options
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,9 @@ manylinux-x86_64-image = 'manylinux2014'
select = 'cp3{6,7,8,9}-*'
manylinux-x86_64-image = 'manylinux2010'

# [tool.cibuildwheel.linux]
[tool.cibuildwheel.linux]

# MQ_CIBW_BUILD_ARGS is a comma-separated list of arguments to pass onto `python3 -m build` when running within
# cibuildwheel (e.g. MQ_CIBW_BUILD_ARGS='--set,ENABLE_GITEE')
environment-pass = ['MQ_CIBW_BUILD_ARGS']
# repair-wheel-command = "auditwheel -v repair -w {dest_dir} {wheel}"
4 changes: 4 additions & 0 deletions scripts/build/parse_common_args.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function Help-Message() {
Write-Output (" Defaults to: {0}" -f $n_jobs_default)
Write-Output ' -LocalPkgs Compile third-party dependencies locally'
Write-Output ' -NoConfig Ignore any configuration file'
Write-Output ' -NoGitee Do not favor Gitee over Github/Gitlab'
Write-Output ' -Ninja Build using Ninja instead of make'
Write-Output ' -Quiet Disable verbose build rules'
Write-Output ' -ShowLibraries Show all known third-party libraries'
Expand Down Expand Up @@ -170,6 +171,9 @@ if ($DebugCMake.IsPresent) {
if ($Gitee.IsPresent) {
Set-Value 'enable_gitee'
}
if ($NoGitee.IsPresent) {
Set-Value 'enable_gitee' $false
}

if ($Gpu.IsPresent) {
Set-Value 'enable_gpu'
Expand Down
4 changes: 4 additions & 0 deletions scripts/build/parse_common_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ help_message() {
echo ' --debug Build in debug mode'
echo ' --debug-cmake Enable debugging mode for CMake configuration step'
echo ' --gitee Use Gitee (where possible) instead of Github/Gitlab'
echo ' --no-gitee Do not favor Gitee over Github/Gitlab'
echo ' --gpu Enable GPU support'
echo ' -j,--jobs [N] Number of parallel jobs for building'
echo " Defaults to: $n_jobs_default"
Expand Down Expand Up @@ -227,6 +228,9 @@ while getopts "${getopts_args}" OPT; do
gitee ) no_arg;
set_var enable_gitee
;;
no-gitee ) no_arg;
set_var enable_gitee 0
;;
gpu ) no_arg;
set_var enable_gpu
;;
Expand Down
Loading

0 comments on commit f20d499

Please sign in to comment.