Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support release build on Linux CI #1

Closed
wants to merge 12 commits into from
74 changes: 56 additions & 18 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,62 @@ jobs:
strategy:
fail-fast: false
matrix:
build_type: [ Debug ] # TODO: Release
build_type: [ Debug, Release ]
compiler:
- {
cc: clang-7, cxx: clang++-7,
pacakge: clang-7,
package: clang-7,
subpackage: lld-7,
}
- {
cc: clang-8, cxx: clang++-8,
pacakge: clang-8,
package: clang-8,
subpackage: lld-8,
}
- {
cc: clang-9, cxx: clang++-9,
pacakge: clang-9,
package: clang-9,
subpackage: lld-9,
}
- {
cc: clang-10, cxx: clang++-10,
pacakge: clang-10,
package: clang-10,
subpackage: lld-10,
}
- {
cc: gcc-8, cxx: g++-8,
pacakge: g++-8,
package: g++-8,
subpackage: binutils,
}
- {
cc: gcc-9, cxx: g++-9,
pacakge: g++-9,
package: g++-9,
subpackage: binutils,
}
- {
cc: gcc-10, cxx: g++-10,
pacakge: g++-10,
package: g++-10,
subpackage: binutils,
}
include:
- build_type: Coverage
compiler: {
cc: gcc-10, cxx: g++-10,
pacakge: g++-10,
package: g++-10,
subpackage: binutils,
}
env:
CC: ${{ matrix.compiler.cc }}
CXX: ${{ matrix.compiler.cxx }}
CACHE_KEY_PREFIX: ${{ github.job }}-${{ matrix.compiler.pacakge }}-${{ matrix.build_type }}
CACHE_KEY_PREFIX: ${{ github.job }}-${{ matrix.compiler.package }}-${{ matrix.build_type }}
steps:
- uses: actions/checkout@v2.3.4

- name: Install ${{ matrix.compiler.pacakge }}
- name: Install ${{ matrix.compiler.package }} and ${{ matrix.compiler.subpackage }}
run: |
sudo apt-get -qq clean
sudo apt-get -qq update
sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.pacakge }}
sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.package }} ${{ matrix.compiler.subpackage }}

- name: Restore & Cache CMake build results
if: matrix.build_type != 'Coverage'
Expand Down Expand Up @@ -110,17 +119,45 @@ jobs:
sudo ./b2 link=static install -j2 --prefix=${{ runner.temp }}/libs/boost || exit 0
working-directory: ${{ runner.temp }}

- name: Install libacl
run: sudo apt-get install -y -qq libacl1-dev

- name: Install libarchive
run: sudo apt-get install -y -qq libarchive-dev

- name: Restore & Cache libgit2 (${{ env.LIBGIT2_VERSION }})
- name: Restore & Cache static libgit2 (${{ env.LIBGIT2_VERSION }})
uses: actions/cache@v2.1.4
if: matrix.build_type == 'Release'
id: libgit2-static-cache
with:
path: ${{ runner.temp }}/libs/libgit2
key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-static-${{ env.LIBGIT2_VERSION }}
- name: Install libgit2 (${{ env.LIBGIT2_VERSION }}) as static
if: steps.libgit2-cache.outputs.cache-hit != 'true' && matrix.build_type == 'Release'
run: |
mkdir -p ${{ runner.temp }}/libs/libgit2
git clone -q -b v${{ env.LIBGIT2_VERSION }} https://github.com/libgit2/libgit2.git
mkdir libgit2/build && cd libgit2/build
cmake .. \
-DCMAKE_INSTALL_PREFIX=${{ runner.temp }}/libs/libgit2 \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_CLAR=OFF \
-DCMAKE_C_FLAGS=-fPIC \
-DREGEX_BACKEND=builtin
make
sudo make install
working-directory: ${{ runner.temp }}

- name: Restore & Cache shared libgit2 (${{ env.LIBGIT2_VERSION }})
uses: actions/cache@v2.1.4
id: libgit2-cache
if: matrix.build_type != 'Release'
id: libgit2-shared-cache
with:
path: ${{ runner.temp }}/libs/libgit2
key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-${{ env.LIBGIT2_VERSION }}
key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-shared-${{ env.LIBGIT2_VERSION }}
- name: Install libgit2 (${{ env.LIBGIT2_VERSION }}) as shared
if: steps.libgit2-cache.outputs.cache-hit != 'true'
if: steps.libgit2-cache.outputs.cache-hit != 'true' && matrix.build_type != 'Release'
run: |
mkdir -p ${{ runner.temp }}/libs/libgit2
git clone -q -b v${{ env.LIBGIT2_VERSION }} https://github.com/libgit2/libgit2.git
Expand All @@ -130,7 +167,8 @@ jobs:
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_CLAR=OFF \
-DCMAKE_C_FLAGS=-fPIC
-DCMAKE_C_FLAGS=-fPIC \
-DREGEX_BACKEND=builtin
make
sudo make install
working-directory: ${{ runner.temp }}
Expand Down Expand Up @@ -164,7 +202,7 @@ jobs:
uses: actions/upload-artifact@v2.2.2
if: matrix.build_type == 'Release'
with:
name: ${{ github.job }}-${{ matrix.compiler.pacakge }}
name: ${{ github.job }}-${{ matrix.compiler.package }}
path: poac

- uses: actions/setup-python@v2.2.1
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC

include(cmake/PoacConfig.cmake)
include(cmake/AddPoacDependencies.cmake)
if (NOT APPLE AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND POAC_DEPENDENCIES "-lstdc++fs")
endif ()
target_link_libraries(
${PROJECT_NAME}
${STATIC_LINK_FLAG}
Expand Down
15 changes: 15 additions & 0 deletions cmake/AddLibArchive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@ endif()

find_package(LibArchive)
if (LibArchive_FOUND)
if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE AND ${LibArchive_LIBRARIES} MATCHES ".*\.so$")
unset(LibArchive_LIBRARIES)
unset(LibArchive_LIBRARY CACHE)
find_library(LibArchive_LIBRARY
NAMES libarchive.a)
mark_as_advanced(LibArchive_LIBRARY)
set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
set_target_properties(LibArchive::LibArchive PROPERTIES
IMPORTED_LOCATION "${LibArchive_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LibArchive_INCLUDE_DIR}")
endif ()
message(CHECK_PASS "added")
message(STATUS "LibArchive include directory is ... ${LibArchive_INCLUDE_DIR}")
message(STATUS "LibArchive library is ... ${LibArchive_LIBRARIES}")

target_include_directories(${PROJECT_NAME} PRIVATE ${LibArchive_INCLUDE_DIR})
list(APPEND POAC_DEPENDENCIES ${LibArchive_LIBRARIES})
if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE)
list(APPEND POAC_DEPENDENCIES acl)
list(APPEND POAC_DEPENDENCIES z)
endif ()
else ()
message(CHECK_FAIL "not found")
list(APPEND missingDependencies libarchive)
Expand Down
10 changes: 9 additions & 1 deletion cmake/AddOpenSSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ endif ()

find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE)
foreach(x IN LISTS OPENSSL_LIBRARIES)
string(REGEX REPLACE "[.]so" ".a" x ${x})
list(APPEND OPENSSL_STATIC_LIBRARIES ${x})
endforeach()
set(OPENSSL_LIBRARIES ${OPENSSL_STATIC_LIBRARIES})
unset(OPENSSL_STATIC_LIBRARIES)
endif ()
message(CHECK_PASS "added")
if (LINUX)
if (UNIX AND NOT APPLE)
list(APPEND OPENSSL_LIBRARIES ssl crypto dl)
elseif (APPLE)
list(APPEND OPENSSL_LIBRARIES dl)
Expand Down
16 changes: 13 additions & 3 deletions cmake/ConfigRelease.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ include_guard(GLOBAL)
if (APPLE)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -mtune=native -march=native")
else ()
set(STATIC_LINK_FLAG "-static") # ref: https://stackoverflow.com/a/3801032
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto") # -mtune=powerpc64le -mcpu=powerpc64le
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (${CMAKE_CXX_COMPILER} MATCHES "-[0-9]+$")
string(REGEX REPLACE [[.*clang\+\+(-[0-9]+)$]] [[lld\1]] LD ${CMAKE_CXX_COMPILER})
set(STATIC_LINK_FLAG "-static -fuse-ld=${LD}")
else ()
set(STATIC_LINK_FLAG "-static -fuse-ld=lld")
endif ()
else ()
set(STATIC_LINK_FLAG "-static") # ref: https://stackoverflow.com/a/3801032
endif ()
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # -mtune=powerpc64le -mcpu=powerpc64le
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif ()
if (LINUX)
if (UNIX AND NOT APPLE)
set(Boost_USE_STATIC_LIBS ON)
endif ()