Skip to content

Commit

Permalink
Merge pull request #22 from denismakogon/arch
Browse files Browse the repository at this point in the history
Сross-compiling for macOS aarch 64, x86_64 and Linux x86_64
  • Loading branch information
denismakogon authored Oct 15, 2023
2 parents 3cf11ac + 05dd68d commit 0d20dc0
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 34 deletions.
126 changes: 99 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@ on:
branches: [ main ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
include:
- os: ubuntu-latest
TARGET: linux
PLATFORM: x64
- os: macos-latest
TARGET: macos
PLATFORM: x64
build-on-macos:
runs-on: macos-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: caching
uses: actions/cache@v3
id: cmakelists
with:
path: CMakeLists.txt
path: |
CMakeLists.txt
key: ${{ github.sha }}-${{ github.run_id }}

- name: Set up Homebrew
Expand All @@ -42,35 +33,107 @@ jobs:
shell: bash
run: |
brew install gcc
brew install conan
pip3 install conan
- name: conan-profile
shell: bash
run: |
conan profile detect
conan version
cp .github/conan2/${{ matrix.TARGET }}_default ~/.conan2/profiles/default
cp .github/conan2/macos_default ~/.conan2/profiles/default
conan profile show
mkdir -p libs
mkdir -p build
- name: conan-install
- name: compile x86_64
shell: bash
run: |
conan install . --output-folder=build --build=missing
cd build
cp ../toolchains/macos-x86_64.cmake conan_toolchain.cmake
LIB_SUFFIX="-macos-x86_64" cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
file lib*
cp libjudy* ../libs/
rm -fr *
- name: compile aarch64
shell: bash
run: |
conan install . --output-folder=build --build=missing
cd build
cp ../toolchains/macos-aarch64.cmake conan_toolchain.cmake
LIB_SUFFIX="-macos-aarch64" cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
file lib*
cp libjudy* ../libs/
rm -fr *
- name: artifacts
uses: actions/upload-artifact@v3
with:
name: libjudy-macos
path: libs/libjudy*
retention-days: 1

build-on-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: caching
uses: actions/cache@v3
id: cmakelists
with:
path: |
CMakeLists.txt
/home/linuxbrew/.linuxbrew/Cellar
key: ${{ github.sha }}-${{ github.run_id }}

- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
test-bot: false

- name: install prerequisites
shell: bash
run: |
brew install gcc
brew install conan
- name: conan-profile
shell: bash
run: |
conan profile detect
conan version
cp .github/conan2/linux_default ~/.conan2/profiles/default
conan profile show
mkdir -p libs
mkdir -p build
- name: compile x86_64
shell: bash
run: |
conan install . --output-folder=build --build=missing
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
LIB_SUFFIX="-linux-x86_64" cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
file lib*
cp libjudy* ../libs/
rm -fr CMakeFiles/
- name: artifacts
uses: actions/upload-artifact@v3
with:
name: libjudy.${{ matrix.TARGET }}
path: build/libjudy*
name: libjudy-linux
path: libs/libjudy*
retention-days: 1

package:
needs:
- build
needs: [ build-on-macos, build-on-linux ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -81,10 +144,19 @@ jobs:
PLATFORM: x64
steps:
- name: 'Check out repository'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: caching
uses: actions/cache@v3
id: cmakelists
with:
path: |
CMakeLists.txt
/usr/local/Cellar
key: ${{ github.sha }}-${{ github.run_id }}

- name: 'Download jextract'
id: jextract
uses: oracle-actions/setup-java@v1
Expand Down Expand Up @@ -154,16 +226,16 @@ jobs:
make java-sources
mkdir src/main/resources
- name: libjudy.so
- name: libjudy-linux
uses: actions/download-artifact@v3
with:
name: libjudy.linux
name: libjudy-linux
path: build/src/main/resources/lib

- name: libjudy.dylib
- name: libjudy-macos
uses: actions/download-artifact@v3
with:
name: libjudy.macos
name: libjudy-macos
path: build/src/main/resources/lib

- name: Display structure of downloaded files
Expand Down
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.24)

project(judy LANGUAGES C CXX VERSION 0.0.1 DESCRIPTION "Multithreaded CPP UDP server consumable through the C ABI consumption")

set(CMAKE_OSX_ARCHITECTURES "x86_64")
project(judy LANGUAGES C CXX VERSION 0.0.1 DESCRIPTION "Multithreaded C++ UDP server consumable through the C ABI consumption")

execute_process(COMMAND date +'%Y.%m.%d' OUTPUT_VARIABLE JAR_VERSION)
execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(STDLIB_INCLUDE /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include)
Expand All @@ -26,11 +23,11 @@ message(STATUS "Found boost includes at " ${Boost_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(src SOURCES)

add_executable(${PROJECT_NAME}-main ${SOURCES} ${HEADERS})
add_library(${PROJECT_NAME}-${ARCHITECTURE} SHARED ${SOURCES} ${HEADERS})
add_library(${PROJECT_NAME}$ENV{LIB_SUFFIX} SHARED ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME}-main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME}-${ARCHITECTURE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME}$ENV{LIB_SUFFIX} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME}-main ${Boost_LIBRARIES} )
target_link_libraries(${PROJECT_NAME}-${ARCHITECTURE} PRIVATE Threads::Threads)
target_link_libraries(${PROJECT_NAME}$ENV{LIB_SUFFIX} PRIVATE Threads::Threads)

add_custom_target(
java-sources
Expand Down
89 changes: 89 additions & 0 deletions toolchains/linux-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Avoid including toolchain file several times (bad if appending to variables like
# CMAKE_CXX_FLAGS. See https://github.com/android/ndk/issues/323
include_guard()

MACRO(SUBDIRLIST result curdir)
FILE(GLOB children ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${child})
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()

message(STATUS "Using Conan toolchain: ${CMAKE_CURRENT_LIST_FILE}")

if(${CMAKE_VERSION} VERSION_LESS "3.15")
message(FATAL_ERROR "The 'CMakeToolchain' generator only works with CMake >= 3.15")
endif()










message(STATUS "Conan toolchain: C++ Standard 17 with extensions ON")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Extra c, cxx, linkflags and defines


if(DEFINED CONAN_CXX_FLAGS)
string(APPEND CMAKE_CXX_FLAGS_INIT " ${CONAN_CXX_FLAGS}")
endif()
if(DEFINED CONAN_C_FLAGS)
string(APPEND CMAKE_C_FLAGS_INIT " ${CONAN_C_FLAGS}")
endif()
if(DEFINED CONAN_SHARED_LINKER_FLAGS)
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${CONAN_SHARED_LINKER_FLAGS}")
endif()
if(DEFINED CONAN_EXE_LINKER_FLAGS)
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${CONAN_EXE_LINKER_FLAGS}")
endif()

get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
if(_CMAKE_IN_TRY_COMPILE)
message(STATUS "Running toolchain IN_TRY_COMPILE")
return()
endif()

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

# Definition of CMAKE_MODULE_PATH
# the generators folder (where conan generates files, like this toolchain)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

# Definition of CMAKE_PREFIX_PATH, CMAKE_XXXXX_PATH
# The Conan local "generators" folder, where this toolchain is saved.
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR} )
SUBDIRLIST(SUBDIRS "$ENV{HOME}/.conan2/p/b/")
FOREACH(subdir ${SUBDIRS})
list(PREPEND CMAKE_LIBRARY_PATH "${subdir}/p/lib")
list(PREPEND CMAKE_INCLUDE_PATH "${subdir}/p/include")
ENDFOREACH()


if (DEFINED ENV{PKG_CONFIG_PATH})
set(ENV{PKG_CONFIG_PATH} "${CMAKE_CURRENT_LIST_DIR}:$ENV{PKG_CONFIG_PATH}")
else()
set(ENV{PKG_CONFIG_PATH} "${CMAKE_CURRENT_LIST_DIR}:")
endif()




# Variables
# Variables per configuration
Loading

0 comments on commit 0d20dc0

Please sign in to comment.