From 152a973f7580e50d174413fe16fc8c79da023996 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Wed, 26 Jun 2024 14:20:40 -0400 Subject: [PATCH 1/3] Added GitHub Actions CI for Multi Platforms --- .github/CMakeLists.root | 61 +++++++++++++++++++++++++ .github/CMakeLists.test | 9 ++++ .github/workflows/ci.yml | 81 +++++++++++++++++++++++++++++++++ .github/workflows/ci_centos.yml | 32 +++++++++++++ .github/workflows/ci_cpu.yml | 53 +++++++++++++++++++++ .gitignore | 9 ++++ 6 files changed, 245 insertions(+) create mode 100644 .github/CMakeLists.root create mode 100644 .github/CMakeLists.test create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ci_centos.yml create mode 100644 .github/workflows/ci_cpu.yml diff --git a/.github/CMakeLists.root b/.github/CMakeLists.root new file mode 100644 index 00000000..3efaadd8 --- /dev/null +++ b/.github/CMakeLists.root @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 2.8...3.14) + +project( + rpmalloc + VERSION 1.4.5 + DESCRIPTION "General Purpose Memory Allocator" + HOMEPAGE_URL "https://github.com/mjansson/rpmalloc" + LANGUAGES C +) + +set(CMAKE_C_STANDARD 11) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + +include(CMakeDependentOption) +include(GNUInstallDirs) +include(CheckCCompilerFlag) +include(CMakePackageConfigHelpers) +include(CTest) + +message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}") +if(WIN32) + if($ENV{Platform} STREQUAL x86) + message("Building Windows x86-32bit") + add_definitions(-D_WIN32_PLATFORM_X86=1) + endif() +endif() + +set(CMAKE_CONFIGURATION_TYPES=Debug;Release) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/built") + +cmake_dependent_option(BUILD_TESTING + "Build the unit tests when BUILD_TESTING is enabled and we are the root project" OFF + "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) + +option(BUILD_SHARED_LIBS "Build the library as a shared (dynamically-linked) " OFF) + +if(UNIX) + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -D ENABLE_ASSERTS=1") +else() + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /D ENABLE_ASSERTS=1 ") +endif() + +set(rpmalloc_files rpmalloc/rpmalloc.c ) +add_definitions(-DENABLE_OVERRIDE=1) +if(BUILD_SHARED_LIBS) + add_library(rpmalloc SHARED ${rpmalloc_files}) +else() + add_library(rpmalloc STATIC ${rpmalloc_files}) +endif() +set_property(TARGET rpmalloc PROPERTY POSITION_INDEPENDENT_CODE True) + +find_package(Threads) +target_link_libraries(rpmalloc PUBLIC ${CMAKE_THREAD_LIBS_INIT}) + +if(BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif() diff --git a/.github/CMakeLists.test b/.github/CMakeLists.test new file mode 100644 index 00000000..e190ab77 --- /dev/null +++ b/.github/CMakeLists.test @@ -0,0 +1,9 @@ +include_directories(${CMAKE_SOURCE_DIR}/rpmalloc ${CMAKE_SOURCE_DIR}/test) + +add_executable(main_test thread.c main.c) +add_executable(storage_test thread.c storage.c) +target_link_libraries(main_test rpmalloc) +target_link_libraries(storage_test rpmalloc) + +add_test(NAME main_test COMMAND main_test) +add_test(NAME storage_test COMMAND storage_test) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..65488380 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: Windows & Ubuntu & Apple macOS +on: + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + build-ubuntu: + name: Linux ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: amd64 + flags: -m64 + - target: x86 + flags: -m32 + steps: + - uses: actions/checkout@v4 + - name: Prepare + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update -q -y + sudo apt-get install -y gcc-multilib g++-multilib valgrind libc6-dbg libc6-dbg:i386 + - name: Configure & build + run: | + cp -f .github/CMakeLists.root CMakeLists.txt + cp -f .github/CMakeLists.test test/CMakeLists.txt + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -DCMAKE_C_FLAGS=${{ matrix.flags }} .. + cmake --build . + - name: Run test + run: | + cd build + ./main_test + + build-windows: + name: Windows (${{ matrix.arch }}) + runs-on: windows-2019 + strategy: + fail-fast: false + matrix: + arch: [x64, Win32] + steps: + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + - uses: actions/checkout@v4 + - name: Configure & build + run: | + copy /Y .github\CMakeLists.root CMakeLists.txt + copy /Y .github\CMakeLists.test test\CMakeLists.txt + cd build + cmake .. -D BUILD_TESTING=ON -A ${{ matrix.arch }} + cmake --build . --config Debug + - name: Run test + shell: cmd + run: | + cd build\Debug + .\main_test.exe + + build-macos: + name: macOS + runs-on: macos-11 + steps: + - uses: actions/checkout@v4 + - name: Setup + run: | + brew install cmake + - name: Configure & build + run: | + cp -f .github/CMakeLists.root CMakeLists.txt + cp -f .github/CMakeLists.test test/CMakeLists.txt + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON .. + cmake --build . + - name: Run test examples + run: | + cd build + ./main_test diff --git a/.github/workflows/ci_centos.yml b/.github/workflows/ci_centos.yml new file mode 100644 index 00000000..c25f5851 --- /dev/null +++ b/.github/workflows/ci_centos.yml @@ -0,0 +1,32 @@ +name: CentOS Stream 9 + +on: + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + build-centos: + name: CentOS + runs-on: ubuntu-latest + strategy: + fail-fast: false + container: quay.io/centos/centos:stream9 + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Prepare + run: | + dnf install git make cmake gcc gcc-c++ binutils glibc-devel valgrind autoconf libtool bison automake libxml2-devel sudo which -y + - name: Configure & build + run: | + cp -f .github/CMakeLists.root CMakeLists.txt + cp -f .github/CMakeLists.test test/CMakeLists.txt + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON .. + cmake --build . + - name: Run tests + run: | + cd build + ./main_test diff --git a/.github/workflows/ci_cpu.yml b/.github/workflows/ci_cpu.yml new file mode 100644 index 00000000..3aba23a2 --- /dev/null +++ b/.github/workflows/ci_cpu.yml @@ -0,0 +1,53 @@ +name: riscv64, s390x, armv7, aarch64, ppc64le + +on: + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + build-qemu: + name: ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: arm + arch: armv7 + - target: aarch64 + arch: aarch64 + - target: ppc64v2 + arch: ppc64le + - target: riscv64 + arch: riscv64 + - target: s390x + arch: s390x + steps: + - uses: actions/checkout@v4 + - uses: uraimo/run-on-arch-action@v2 + with: + arch: ${{ matrix.arch }} + distro: ubuntu_latest + githubToken: ${{ github.token }} + setup: | + mkdir -p "${PWD}/artifacts" + install: | + apt-get update -q -y + apt-get install -q -y --no-install-recommends cmake build-essential + env: | + # Valgrind on arm will fail if the stack size is larger than 8MB. + # Set QEMUs stack size to 8MB since Github runners use 16MB default. + QEMU_STACK_SIZE: 8388608 + run: | + cp -f .github/CMakeLists.root CMakeLists.txt + cp -f .github/CMakeLists.test test/CMakeLists.txt + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON .. + cmake --build . + cd ../build + ./main_test + - name: Show the artifact + run: | + ls -al "${PWD}/artifacts" diff --git a/.gitignore b/.gitignore index fd145ba5..c9502720 100644 --- a/.gitignore +++ b/.gitignore @@ -231,3 +231,12 @@ coverallsreport.json codecov.json codecovreport.json benchmark-*.txt +build/CMakeFiles/ +build/test/ +build/cmake_install.cmake +build/CMakeCache.txt +build/compile_commands.json +build/CTestTestfile.cmake +build/DartConfiguration.tcl +build/Makefile +built/ From 1a7811d433c265f29a6b65de9562feaa12a276d4 Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Wed, 26 Jun 2024 14:24:32 -0400 Subject: [PATCH 2/3] Update CMakeLists.test --- .github/CMakeLists.test | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/CMakeLists.test b/.github/CMakeLists.test index e190ab77..bd9f9621 100644 --- a/.github/CMakeLists.test +++ b/.github/CMakeLists.test @@ -1,9 +1,7 @@ include_directories(${CMAKE_SOURCE_DIR}/rpmalloc ${CMAKE_SOURCE_DIR}/test) add_executable(main_test thread.c main.c) -add_executable(storage_test thread.c storage.c) + target_link_libraries(main_test rpmalloc) -target_link_libraries(storage_test rpmalloc) add_test(NAME main_test COMMAND main_test) -add_test(NAME storage_test COMMAND storage_test) From 39edd49031e245435e8af94b2fff02d81619375d Mon Sep 17 00:00:00 2001 From: Lawrence Stubbs Date: Wed, 26 Jun 2024 14:29:14 -0400 Subject: [PATCH 3/3] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65488380..b43edeee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: arch: ${{ matrix.arch }} - uses: actions/checkout@v4 - name: Configure & build + shell: cmd run: | copy /Y .github\CMakeLists.root CMakeLists.txt copy /Y .github\CMakeLists.test test\CMakeLists.txt