Skip to content

Commit

Permalink
Merge pull request #18 from cen1/feature/refresh
Browse files Browse the repository at this point in the history
Tooling refresh and CI improvements
  • Loading branch information
carlbennett committed Feb 24, 2024
2 parents 6e09fdf + d727968 commit cd4f2fc
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 123 deletions.
136 changes: 103 additions & 33 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,114 @@ name: CMake
on: [push]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
build-debian-system-reproducible:
if: true
runs-on: ubuntu-latest
container:
image: debian:bookworm

steps:
- uses: actions/checkout@v2

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- uses: actions/checkout@v4

- name: Install dependencies
run: apt-get -y update && apt-get install -y libgmp-dev build-essential cmake

- name: Cmake pass 1
run: cmake -G "Unix Makefiles" -B./build1 -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build pass 1
run: cmake --build ./build1

- name: Cmake pass 2
run: cmake -G "Unix Makefiles" -B./build2 -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build pass 2
run: cmake --build ./build2

- name: Check hashes
run: |
ls -la build1
hash1=$(sha256sum build1/libbncsutil.so | cut -d ' ' -f 1)
hash2=$(sha256sum build2/libbncsutil.so | cut -d ' ' -f 1)
echo "Hash 1: $hash1\n"
echo "Hash 2: $hash2\n"
[ "$hash1" = "$hash2" ] && exit 0 || exit 1
build-debian-conan:
if: true
runs-on: ubuntu-latest
container:
image: debian:bookworm

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: apt-get -y update && apt-get install -y python3 python3-pip build-essential cmake

- name: Install conan
run: pip install conan --break-system-packages

- name: Init conan
run: conan profile detect

- name: Install deps with conan
run: conan install . -of ./build -s build_type=Release --build=missing

- name: Cmake
working-directory: ./build
run: bash conanbuild.sh && cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSE_SYSTEM_LIBS=0

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
working-directory: ./build
run: cmake --build .

build-fedora-system:
if: true
runs-on: ubuntu-latest
container:
image: fedora:latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: dnf -y install gmp-devel make automake clang cmake

- name: Cmake
run: cmake -G "Unix Makefiles" -B./build -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
run: cmake --build ./build

build-windows-conan:
if: true
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main

- name: Init conan
run: conan profile detect

- name: Install dependencies
shell: cmd
run: conan install . -of build -s build_type=Release -o *:shared=False --build=missing

- name: Build
shell: cmd
working-directory: ./build
run: .\conanbuild.bat && cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1 && cmake --build . --config Release


93 changes: 93 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Release

on:
push:
tags:
- '*'

env:
BUILD_TYPE: Release

jobs:
deb:
runs-on: ubuntu-latest
container:
image: debian:bookworm

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: apt-get -y update && apt-get install -y libgmp-dev build-essential cmake

- name: Cmake
run: cmake -G "Unix Makefiles" -B./build -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
run: cmake --build ./build

- name: Package
id: package
working-directory: build
run: |
cpack -G "DEB" -D CPACK_PACKAGE_FILE_NAME=libbncsutil-${{ github.ref_name }}-devel
- uses: actions/upload-artifact@v4
with:
retention-days: 1
overwrite: true
name: libbncsutil-${{ github.ref_name }}-devel.deb
path: build/libbncsutil-${{ github.ref_name }}-devel.deb

rpm:
runs-on: ubuntu-latest
container:
image: fedora:latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: dnf -y install gmp-devel make automake clang cmake rpm-build

- name: Cmake
run: cmake -G "Unix Makefiles" -B./build -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
run: cmake --build ./build

- name: Package
working-directory: build
run: cpack -G "RPM" -D CPACK_PACKAGE_FILE_NAME=libbncsutil-${{ github.ref_name }}-devel

- uses: actions/upload-artifact@v4
with:
retention-days: 1
overwrite: true
name: libbncsutil-${{ github.ref_name }}-devel.rpm
path: build/libbncsutil-${{ github.ref_name }}-devel.rpm

release:
needs: [deb, rpm]
runs-on: ubuntu-latest

steps:
- name: Download deb
uses: actions/download-artifact@v4
with:
name: libbncsutil-${{ github.ref_name }}-devel.deb

- name: Download rpm
uses: actions/download-artifact@v4
with:
name: libbncsutil-${{ github.ref_name }}-devel.rpm

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
libbncsutil-${{ github.ref_name }}-devel.deb
libbncsutil-${{ github.ref_name }}-devel.rpm
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ conan.lock
conanbuildinfo.txt
conaninfo.txt
graph_info.json
CMakeUserPresets.json
80 changes: 51 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
cmake_minimum_required(VERSION 3.25)
project(bncsutil)
cmake_minimum_required(VERSION 3.2)

set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} "${PROJECT_SOURCE_DIR}/CMake/Modules")
message(${CMAKE_BINARY_DIR})

SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "4")
SET(VERSION_PATCH "1")

file(GLOB SOURCE
"src/bncsutil/*.cpp"
"src/bncsutil/*.c"
SET(VERSION_PATCH "2")

add_library(bncsutil SHARED)

set(HEADERS
"src/bncsutil/bncsutil.h"
"src/bncsutil/bsha1.h"
"src/bncsutil/buffer.h"
"src/bncsutil/cdkeydecoder.h"
"src/bncsutil/checkrevision.h"
"src/bncsutil/decodekey.h"
"src/bncsutil/file.h"
"src/bncsutil/keytables.h"
"src/bncsutil/libinfo.h"
"src/bncsutil/ms_stdint.h"
"src/bncsutil/mutil.h"
"src/bncsutil/mutil_types.h"
"src/bncsutil/nls.h"
"src/bncsutil/oldauth.h"
"src/bncsutil/pe.h"
"src/bncsutil/sha1.h"
"src/bncsutil/stack.h"
)
file(GLOB HEADERS
"src/bncsutil/*.h"

set(SOURCES
"src/bncsutil/bsha1.cpp"
"src/bncsutil/cdkeydecoder.cpp"
"src/bncsutil/checkrevision.cpp"
"src/bncsutil/decodekey.cpp"
"src/bncsutil/file.cpp"
"src/bncsutil/libinfo.cpp"
"src/bncsutil/oldauth.cpp"
"src/bncsutil/sha1.c"
)

add_library(${PROJECT_NAME} ${SOURCE} ${HEADERS})
target_sources(bncsutil PRIVATE ${SOURCES} ${HEADERS})

if (WIN32)
set(USE_GMP 0)
set(USE_SYSTEM_LIBS 0)
else()
set(USE_SYSTEM_LIBS 1)
endif()

if (CMAKE_GENERATOR_PLATFORM EQUAL "x86")
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
set_target_properties(bncsutil PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
MESSAGE(STATUS "Excluding 64bit library paths from search.")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS OFF)
set(ARCH_DEB i386)
set(ARCH_RPM i686)
elseif (CMAKE_GENERATOR_PLATFORM EQUAL "x64")
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64")
set_target_properties(bncsutil PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64")
set(ARCH_DEB amd64)
set(ARCH_RPM x86_64)
else()
Expand All @@ -38,27 +65,22 @@ else()
endif()

if (USE_SYSTEM_LIBS)
message("Using system dependencies")
find_package(GMP REQUIRED)
include_directories(src ${GMP_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${GMP_LIBRARIES})
target_include_directories(bncsutil PRIVATE src ${GMP_INCLUDE_DIR})
target_link_libraries(bncsutil ${GMP_LIBRARIES})
else()
if (USE_GMP)
find_package(gmp REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE src gmp:gmp)
target_link_libraries(${PROJECT_NAME} PRIVATE gmp:gmp)
else()
find_package(mpir REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE src mpir::mpir)
target_link_libraries(${PROJECT_NAME} PRIVATE mpir::mpir)
add_definitions(-DUSE_MPIR=1)
endif()
message("Using conan dependencies")
find_package(gmp REQUIRED)
target_include_directories(bncsutil PRIVATE src gmp::gmp)
target_link_libraries(bncsutil PRIVATE gmp::gmp)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME bncsutil)
set_target_properties(bncsutil PROPERTIES OUTPUT_NAME bncsutil)

if(UNIX)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1)
set_target_properties(bncsutil PROPERTIES VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set_target_properties(bncsutil PROPERTIES SOVERSION 1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -Wno-multichar -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -Wno-multichar -fPIC")
Expand All @@ -77,7 +99,7 @@ install(FILES ${HEADERS} DESTINATION include/bncsutil)

#CPack configurtion
SET(CPACK_GENERATOR "DEB" "RPM")
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
SET(CPACK_PACKAGE_NAME "bncsutil")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Battle.Net Chat Service Utility")
SET(CPACK_PACKAGE_VENDOR "bncsutil")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
Expand All @@ -96,7 +118,7 @@ SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libgmp10")
#RPM configuration
SET(CPACK_RPM_PACKAGE_RELEASE 1)
SET(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
SET(CPACK_RPM_PACKAGE_GROUP "${PROJECT_NAME}")
SET(CPACK_RPM_PACKAGE_GROUP "bncsutil")
SET(CPACK_RPM_PACKAGE_URL "https://github.com/BNETDocs/bncsutil")
SET(CPACK_RPM_PACKAGE_REQUIRES "gmp")
SET(CPACK_RPM_PACKAGE_ARCHITECTURE ${ARCH_RPM})
Expand Down
Loading

0 comments on commit cd4f2fc

Please sign in to comment.