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

Replace Travis CI by GitHub Actions CI #74

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .cmake/create_buildandinstall_target.cmake

This file was deleted.

39 changes: 27 additions & 12 deletions .cmake/create_targets_both_lib_types.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,43 @@ function(create_targets_both_lib_types basename)

# Object target to unify source building for both (shared/static) real targets
add_library(${lib_objlib} OBJECT ${SRC_FILES})
set_target_properties(${lib_objlib} PROPERTIES POSITION_INDEPENDENT_CODE 1)

# The two real targets
add_library(${lib_shared} SHARED $<TARGET_OBJECTS:${lib_objlib}>)
add_library(${lib_static} STATIC $<TARGET_OBJECTS:${lib_objlib}>)

# Internal deps
foreach(idep ${ARGN})
add_dependencies(${lib_objlib} ${idep}_objlib)
add_dependencies(${lib_shared} ${idep}_shared)
add_dependencies(${lib_static} ${idep}_static)
if(${idep} MATCHES "^(ti[a-z]+)2$")
set(INTERNAL_DEP_LIB_DIR ${CMAKE_BINARY_DIR}/lib${CMAKE_MATCH_1}/trunk)
set(INTERNAL_DEP_INC_DIR ${CMAKE_SOURCE_DIR}/lib${CMAKE_MATCH_1}/trunk/src)
else()
set(INTERNAL_DEP_LIB_DIR ${CMAKE_BINARY_DIR}/lib${idep}/trunk)
set(INTERNAL_DEP_INC_DIR ${CMAKE_SOURCE_DIR}/lib${idep}/trunk/src)
endif()
target_include_directories(${lib_objlib} PRIVATE ${INTERNAL_DEP_INC_DIR})
if(TRY_STATIC_LIBS)
target_link_libraries(${lib_shared} "${INTERNAL_DEP_LIB_DIR}/${STATIC_LIB_PREFIX}${idep}${STATIC_LIB_EXT}")
else()
target_link_directories(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}")
target_link_libraries(${lib_shared} "${idep}")
endif()
endforeach()

# Main properties
set_target_properties(${lib_shared} ${lib_static} PROPERTIES
if(MSVC)
set(static_lib_output_name "${basename}-static")
else()
set(static_lib_output_name "${basename}")
endif()
set_target_properties(${lib_shared} PROPERTIES
OUTPUT_NAME ${basename}
PUBLIC_HEADER "${PUBLIC_HEADERS}")
set_target_properties(${lib_static} PROPERTIES
OUTPUT_NAME ${static_lib_output_name}
PUBLIC_HEADER "${PUBLIC_HEADERS}")

# Defines
target_compile_definitions(${lib_objlib} PRIVATE PACKAGE="${PROJECT_NAME}" VERSION="${PROJECT_VERSION}")
Expand All @@ -30,15 +51,11 @@ function(create_targets_both_lib_types basename)
target_include_directories(${lib_objlib} PRIVATE src)

# Link-related properties, flags...
target_link_directories(${lib_shared} PRIVATE ${DEPS_LIBRARY_DIRS})
if(TRY_STATIC_LIBS)
target_link_libraries(${lib_shared} ${TRY_STATIC_DEPS_LDFLAGS})
if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN)
target_include_directories(${lib_shared} PRIVATE ${Iconv_INCLUDE_DIRS})
target_link_libraries(${lib_shared} ${Iconv_LIBRARIES})
endif()
target_link_libraries(${lib_shared} ${TRY_STATIC_DEPS_LIBRARIES})
else()
link_directories(${DEPS_LIBRARY_DIRS})
target_link_libraries(${lib_shared} "${DEPS_LDFLAGS}" ${DEPS_LIBRARIES} ${Intl_LIBRARIES})
target_link_libraries(${lib_shared} ${DEPS_LIBRARIES})
endif()

# Stuff to install and developer-related things
Expand All @@ -49,6 +66,4 @@ function(create_targets_both_lib_types basename)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tilp2)

configure_and_install_pc_file(${basename} ${PROJECT_VERSION})

create_buildandinstall_target(${PROJECT_NAME} ${lib_shared} ${lib_static})
endfunction()
101 changes: 43 additions & 58 deletions .cmake/try_static_libs.cmake
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
if(APPLE OR UNIX)
set(STATIC_LIB_EXT ".a")
elseif(WIN32 OR MINGW)
set(STATIC_LIB_EXT ".lib")
endif()

if(NOT CMAKE_FIND_LIBRARY_PREFIXES)
set(STATIC_LIB_PREFIX "")
else()
list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 STATIC_LIB_PREFIX)
endif()

macro(try_static_libs_if_needed)
if (TRY_STATIC_LIBS)
if(NOT CMAKE_FIND_LIBRARY_PREFIXES)
set(STATIC_LIB_PREFIX "")
else()
list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 STATIC_LIB_PREFIX)
endif()
list(APPEND DEPS_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
list(APPEND DEPS_STATIC_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
if(APPLE)
set(DYNAMIC_LIB_EXTS ".dylib" ".tbd")
set(STATIC_LIB_EXT ".a")
list(APPEND DEPS_LIBRARY_DIRS "/usr/lib" "${CMAKE_OSX_SYSROOT}/usr/lib" "/opt/homebrew/lib" "/usr/local/opt" "/usr/local/lib" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
list(APPEND DEPS_LIBRARY_DIRS "/usr/lib" "${CMAKE_OSX_SYSROOT}/usr/lib" "/opt/homebrew/lib" "/usr/local/opt" "/usr/local/lib")
list(APPEND DEPS_STATIC_LIBRARY_DIRS "/opt/homebrew/lib" "/usr/local/opt" "/usr/local/lib" "${CMAKE_OSX_SYSROOT}/usr/lib" )
elseif(UNIX)
set(DYNAMIC_LIB_EXTS ".so")
set(STATIC_LIB_EXT ".a")
elseif(WIN32 OR MINGW)
set(DYNAMIC_LIB_EXTS ".dll")
set(STATIC_LIB_EXT ".lib")
endif()
list(REMOVE_DUPLICATES DEPS_STATIC_LIBRARIES)
list(REMOVE_DUPLICATES DEPS_STATIC_LIBRARY_DIRS)
set(TRY_STATIC_DEPS_LDFLAGS "")

foreach(LIB_NAME ${DEPS_STATIC_LIBRARIES})
set(LIB_NAME_FULL ${LIB_NAME})
# there's a weird libarchive/zlib issue with static on linux right now:
# /usr/lib/x86_64-linux-gnu/libarchive.a(archive_read_support_filter_gzip.o): undefined reference to symbol 'inflateEnd'
# /lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line
# there are relocation issues when linking BZip2, zlib, and libusb on linux:
# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libbz2.a(bzlib.o): relocation R_X86_64_PC32 against symbol `BZ2_crc32Table'
# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg'
# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libusb-1.0.a(libusb_1_0_la-core.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5'
# can not be used when making a shared object; recompile with -fPIC
if( (LIB_NAME STREQUAL "archive" AND CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
OR (LIB_NAME MATCHES "^(bz2|z|usb-1.0)$" AND CMAKE_SYSTEM_NAME STREQUAL "Linux"))
message(WARNING "[Linux] Skipping '${LIB_NAME}' static lib search due to a linking issue, will fallback on the shared lib")
list(APPEND TRY_STATIC_DEPS_LIBRARIES "${LIB_NAME}")
set(${LIB_NAME}_FOUND YES)
continue()
endif()

foreach(LIB_DIR ${DEPS_STATIC_LIBRARY_DIRS})
if(NOT EXISTS ${LIB_DIR})
continue()
endif()
# there's a weird libarchive/zlib issue with static on linux right now:
# /usr/lib/x86_64-linux-gnu/libarchive.a(archive_read_support_filter_gzip.o): undefined reference to symbol 'inflateEnd'
# /lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line
if(LIB_NAME STREQUAL "archive" AND CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(WARNING "[GCC Linux] Skipping libarchive static lib search due to a linking issue, will fallback on the shared lib")
break()
set(LIB_FULLPATH "${LIB_DIR}/lib${LIB_NAME}-static${STATIC_LIB_EXT}")
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/${STATIC_LIB_PREFIX}${LIB_NAME}${STATIC_LIB_EXT}")
endif()
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/lib${LIB_NAME}${STATIC_LIB_EXT}")
endif()
set(LIB_FULLPATH "${LIB_DIR}/${STATIC_LIB_PREFIX}${LIB_NAME}${STATIC_LIB_EXT}")
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/${LIB_NAME_FULL}/lib/${STATIC_LIB_PREFIX}${LIB_NAME}-static${STATIC_LIB_EXT}")
endif()
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/lib${LIB_NAME_FULL}/lib/${STATIC_LIB_PREFIX}${LIB_NAME}${STATIC_LIB_EXT}")
endif()
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_NAME_FULL ${LIB_NAME})
if(LIB_NAME_FULL STREQUAL "bz2")
set(LIB_NAME_FULL "bzip2")
elseif(LIB_NAME_FULL STREQUAL "z")
Expand All @@ -51,48 +66,18 @@ macro(try_static_libs_if_needed)
endif()
if(EXISTS ${LIB_FULLPATH})
message("[Info] Found static lib '${LIB_NAME}' for '${PROJECT_NAME}': ${LIB_FULLPATH}")
list(APPEND TRY_STATIC_DEPS_LDFLAGS ${LIB_FULLPATH})
list(APPEND TRY_STATIC_DEPS_LIBRARIES ${LIB_FULLPATH})
set(${LIB_NAME}_FOUND YES)
break()
endif()
endforeach()
if(NOT ${LIB_NAME}_FOUND)
foreach(LIB_DIR ${DEPS_LIBRARY_DIRS})
if(NOT EXISTS ${LIB_DIR})
continue()
endif()
foreach(DYNAMIC_LIB_EXT ${DYNAMIC_LIB_EXTS})
set(LIB_FULLPATH "${LIB_DIR}/${STATIC_LIB_PREFIX}${LIB_NAME}${DYNAMIC_LIB_EXT}")
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/${LIB_NAME_FULL}/lib/${STATIC_LIB_PREFIX}${LIB_NAME}${DYNAMIC_LIB_EXT}")
endif()
if(NOT EXISTS ${LIB_FULLPATH})
set(LIB_FULLPATH "${LIB_DIR}/lib${LIB_NAME_FULL}/lib/${STATIC_LIB_PREFIX}${LIB_NAME}${DYNAMIC_LIB_EXT}")
endif()
if(EXISTS ${LIB_FULLPATH})
list(PREPEND TRY_STATIC_DEPS_LDFLAGS "-l${LIB_NAME}")
set(${LIB_NAME}_FOUND YES)
message("[Warning] Could not find static lib '${LIB_NAME}' for '${PROJECT_NAME}', using found shared lib instead: ${LIB_FULLPATH}")
break()
endif()
endforeach()
if(${LIB_NAME}_FOUND)
break()
endif()
endforeach()
if(NOT ${LIB_NAME}_FOUND)
message("[Warning] Could not find static nor shared lib '${LIB_NAME}' for '${PROJECT_NAME}'. Adding '-l${LIB_NAME}' directly anyway!")
list(APPEND TRY_STATIC_DEPS_LDFLAGS "-l${LIB_NAME}")
endif()
endif()
endforeach()
foreach(LIB_DIR ${DEPS_LIBRARY_DIRS})
if(EXISTS ${LIB_DIR})
list(PREPEND TRY_STATIC_DEPS_LDFLAGS "-L${LIB_DIR}")
message("[Warning] Could not find static lib '${LIB_NAME}' for '${PROJECT_NAME}'. Adding it directly anyway!")
list(APPEND TRY_STATIC_DEPS_LIBRARIES "${LIB_NAME}")
endif()
endforeach()
string(REPLACE ";" " " DEPS_STATIC_LDFLAGS_OTHER "${DEPS_STATIC_LDFLAGS_OTHER}")
list(APPEND TRY_STATIC_DEPS_LDFLAGS "${DEPS_STATIC_LDFLAGS_OTHER}")
list(REMOVE_DUPLICATES TRY_STATIC_DEPS_LDFLAGS)
list(APPEND TRY_STATIC_DEPS_LIBRARIES "${DEPS_STATIC_LDFLAGS_OTHER}")
list(REMOVE_DUPLICATES TRY_STATIC_DEPS_LIBRARIES)
endif()
endmacro()
69 changes: 69 additions & 0 deletions .github/workflows/build.linux.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build Linux

on:
push:
branches: [ master, feature/github-actions ]
pull_request:
branches: [ master, feature/github-actions ]
release:
types: [published]

jobs:
build:
name: "Build: ${{ matrix.os }} - ${{ matrix.deps_type }} deps"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
try_static_deps: ['OFF','ON']
include:
- try_static_deps: 'OFF'
deps_type: shared
- try_static_deps: 'ON'
deps_type: static

steps:
- name: Checkout Git Repo
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: workaround for default apt mirror connectivity issues
run: |
sudo sed -i 's/azure\.//' /etc/apt/sources.list

- name: Install dependencies
run: |
set -e
sudo add-apt-repository universe
sudo apt update
sudo apt install -y cmake ninja-build libarchive-dev libzstd-dev zlib1g-dev libusb-1.0-0-dev libglib2.0-dev gettext nettle-dev libacl1-dev liblzma-dev liblz4-dev libudev-dev libc6-dev

- name: Build tilibs
run: |
set -e
mkdir prefix
prefixpath="$(pwd)/prefix"
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DTRY_STATIC_LIBS=${{ matrix.try_static_deps }} -DCMAKE_INSTALL_PREFIX=${prefixpath} ..
cmake --build . --target all

- name: Test tilibs
run: |
cd build
cmake --build . --target check

- name: Install tilibs
run: |
cd build
cmake --build . --target install

- name: Prepare install folder for upload
run: mv prefix tilibs_linux_${{ matrix.deps_type }}Deps_${{ github.sha }}

- name: Upload install folder
uses: actions/upload-artifact@v3
with:
name: tilibs_linux_${{ matrix.deps_type }}Deps_${{ github.sha }}
path: tilibs_linux_${{ matrix.deps_type }}Deps_${{ github.sha }}/
70 changes: 70 additions & 0 deletions .github/workflows/build.mac.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build macOS

on:
push:
branches: [ master, feature/github-actions ]
pull_request:
branches: [ master, feature/github-actions ]
release:
types: [published]

jobs:
build:
name: "Build: ${{ matrix.os }} - ${{ matrix.deps_type }} deps"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macOS-latest]
try_static_deps: ['OFF','ON']
include:
- try_static_deps: 'OFF'
deps_type: shared
- try_static_deps: 'ON'
deps_type: static

steps:
- name: Checkout Git Repo
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install dependencies
run: |
set -e
brew install cmake ninja gettext libarchive glib libusb libiconv intltool expat bzip2 zlib

# Workaround!
# libarchive.pc now has (lib)iconv in Requires.private, which doesn't work here
# See https://github.com/libarchive/libarchive/pull/1813 and other issues
- name: Fix libarchive pkg-config file
run: |
sudo sed -i '' -E '/^Requires.private: (lib)?iconv/d' /usr/local/opt/libarchive/lib/pkgconfig/libarchive.pc

- name: Build tilibs
run: |
set -e
mkdir prefix
prefixpath="$(pwd)/prefix"
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DTRY_STATIC_LIBS=${{ matrix.try_static_deps }} -DCMAKE_INSTALL_PREFIX=${prefixpath} ..
cmake --build . --target all

- name: Test tilibs
run: |
cd build
cmake --build . --target check

- name: Install tilibs
run: |
cd build
cmake --build . --target install

- name: Prepare install folder for upload
run: mv prefix tilibs_mac_${{ matrix.deps_type }}Deps_${{ github.sha }}

- name: Upload install folder
uses: actions/upload-artifact@v3
with:
name: tilibs_mac_${{ matrix.deps_type }}Deps_${{ github.sha }}
path: tilibs_mac_${{ matrix.deps_type }}Deps_${{ github.sha }}/
Loading