From 7335c9755fc7fca7a388a7fc8a360b4e1b5d52d7 Mon Sep 17 00:00:00 2001 From: David Rich <31897211+davidrich27@users.noreply.github.com> Date: Wed, 8 May 2024 08:34:31 -0600 Subject: [PATCH] Added CI build github action. (#80) - Added a Github actions that builds and runs larch tests. - Added a `CMAKE_NUM_THREADS` argument for protobuf.cmake --- .github/workflows/build-larch.yml | 45 +++++++++++++++++++++++++++++++ README.md | 2 ++ protobuf.cmake | 25 ++++++++++------- 3 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build-larch.yml diff --git a/.github/workflows/build-larch.yml b/.github/workflows/build-larch.yml new file mode 100644 index 00000000..0c4dfea8 --- /dev/null +++ b/.github/workflows/build-larch.yml @@ -0,0 +1,45 @@ +name: Build and run tests +on: + workflow_dispatch: +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + submodules: true + - name: Prepare build environment + run: | + sudo apt-get update + sudo apt-get install build-essential cmake zlib1g-dev python3-pip python3-pytest + - name: Install conda + run: | + curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh > Miniconda3-latest-Linux-x86_64.sh + bash Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda + ~/miniconda/bin/conda update -n base -c defaults conda + - name: Create conda env + run: | + source ~/miniconda/etc/profile.d/conda.sh + conda env create -f environment.yml + - name: Build (cmake step) + run: | + source ~/miniconda/etc/profile.d/conda.sh + conda activate larch-dev + mkdir build + cd build + export CMAKE_NUM_THREADS="8" + cmake -DCMAKE_BUILD_TYPE=Debug .. + - name: Build (make step) + run: | + source ~/miniconda/etc/profile.d/conda.sh + conda activate larch-dev + cd build + make -j20 + ln -s ../data + - name: Run tests + run: | + source ~/miniconda/etc/profile.d/conda.sh + conda activate larch-dev + cd build + ./larch-test -tag slow diff --git a/README.md b/README.md index 84a314b3..2ede660e 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ file provided: Building -------- +- Note: If you run against memory limitations during the cmake step, you can regulate number of parallel threads with `export CMAKE_NUM_THREADS="8"` (reduce number as necessary). + `git submodule update --init --recursive` `mkdir build` `cd build` diff --git a/protobuf.cmake b/protobuf.cmake index fe9e723e..1f4c7ef5 100644 --- a/protobuf.cmake +++ b/protobuf.cmake @@ -3,6 +3,10 @@ include(FetchContent) set(Protobuf_USE_STATIC_LIBS ON) cmake_policy(SET CMP0026 OLD) +if(NOT DEFINED CMAKE_NUM_THREADS) + set(CMAKE_NUM_THREADS "16") +endif() + FetchContent_Declare( protocolbuffers_protobuf GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git @@ -19,33 +23,36 @@ set(Protobuf_ROOT ${protocolbuffers_protobuf_SOURCE_DIR}) message(STATUS "Setting up protobuf ...") execute_process( COMMAND - ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -D protobuf_BUILD_TESTS=OFF -D protobuf_BUILD_PROTOC_BINARIES=ON -D CMAKE_POSITION_INDEPENDENT_CODE=ON -G "${CMAKE_GENERATOR}" . + ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -D protobuf_BUILD_TESTS=OFF -D protobuf_BUILD_PROTOC_BINARIES=ON -D CMAKE_POSITION_INDEPENDENT_CODE=ON -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${Protobuf_ROOT}) + if(result) message(FATAL_ERROR "Failed to download protobuf (${result})!") endif() message(STATUS "Building protobuf ...") execute_process( - COMMAND ${CMAKE_COMMAND} --build . --parallel + COMMAND ${CMAKE_COMMAND} --build . --parallel ${CMAKE_NUM_THREADS} RESULT_VARIABLE result WORKING_DIRECTORY ${Protobuf_ROOT}) + if(result) message(FATAL_ERROR "Failed to build protobuf (${result})!") endif() message(STATUS "Installing protobuf ...") execute_process( - COMMAND ${CMAKE_COMMAND} --install . --config ${CMAKE_BUILD_TYPE} --prefix ${Protobuf_ROOT}/install -RESULT_VARIABLE result -WORKING_DIRECTORY ${Protobuf_ROOT}) + COMMAND ${CMAKE_COMMAND} --install . --config ${CMAKE_BUILD_TYPE} --prefix ${Protobuf_ROOT}/install + RESULT_VARIABLE result + WORKING_DIRECTORY ${Protobuf_ROOT}) + if(result) - message(FATAL_ERROR "Failed to build protobuf (${result})!") + message(FATAL_ERROR "Failed to build protobuf (${result})!") endif() -if (NOT EXISTS ${Protobuf_ROOT}/install/lib64) - file (CREATE_LINK ${Protobuf_ROOT}/install/lib ${Protobuf_ROOT}/install/lib64 SYMBOLIC) +if(NOT EXISTS ${Protobuf_ROOT}/install/lib64) + file(CREATE_LINK ${Protobuf_ROOT}/install/lib ${Protobuf_ROOT}/install/lib64 SYMBOLIC) endif() find_package(Protobuf CONFIG REQUIRED HINTS ${Protobuf_ROOT}/install/lib64/cmake) @@ -67,7 +74,7 @@ if(Protobuf_FOUND) else() message( FATAL_ERROR - "Protobuf package not found -> specify search path via Protobuf_ROOT variable" + "Protobuf package not found -> specify search path via Protobuf_ROOT variable" ) endif()