Skip to content
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
64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Build and test palloc on Linux and Windows
name: Build

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
linux:
name: Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Configure
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build -j
- name: Test
run: ctest --test-dir build --output-on-failure

windows-msvc:
name: Windows (MSVC)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Configure
run: >
cmake -B build
-G "Visual Studio 17 2022" -A x64
-DPA_WIN_REDIRECT=OFF
shell: bash
- name: Build Release
run: cmake --build build --config Release
shell: bash
- name: Test
run: ctest --test-dir build -C Release --output-on-failure
shell: bash

windows-mingw:
name: Windows (MinGW)
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4

- name: Setup MinGW
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
pacboy: toolchain:p cmake:p ninja:p

- name: Configure
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DPA_WIN_REDIRECT=OFF
- name: Build
run: cmake --build build -j
- name: Test
run: ctest --test-dir build --output-on-failure
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ dist/
.env
.env.local
*.local
bin/

# bin/: keep source (BUILD.md, readme.md, CMakeLists.txt, palloc-redirect.c); do not commit prebuilt binaries
bin/*.dll
bin/*.lib
bin/*.exe
30 changes: 23 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(pa_sources
src/alloc-aligned.c
src/alloc-posix.c
src/arena.c
src/arena_pomai.c
src/bitmap.c
src/heap.c
src/init.c
Expand Down Expand Up @@ -402,7 +403,8 @@ endif()

# Check /proc/cpuinfo for an SV39 MMU and limit the virtual address bits.
# (this will skip the aligned hinting in that case. Issue #939, #949)
if (EXISTS /proc/cpuinfo)
# Only on Linux: /proc/cpuinfo does not exist on Windows/macOS.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND EXISTS "/proc/cpuinfo")
file(STRINGS /proc/cpuinfo pa_sv39_mmu REGEX "^mmu[ \t]+:[ \t]+sv39$")
if (pa_sv39_mmu)
MESSAGE( STATUS "Set virtual address bits to 39 (SV39 MMU detected)" )
Expand Down Expand Up @@ -629,11 +631,23 @@ if(PA_BUILD_SHARED)
set(PALLOC_REDIRECT_SUFFIX "-${PA_ARCH}") # -arm64 etc.
endif()

target_link_libraries(palloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.lib) # the DLL import library
add_custom_command(TARGET palloc POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll" $<TARGET_FILE_DIR:palloc>
COMMENT "Copy palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll to output directory")
install(FILES "$<TARGET_FILE_DIR:palloc>/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR})
# Build redirect DLL from bin/ (or use prebuilt .lib/.dll in bin/ if present)
set(PA_REDIRECT_PREBUILT_LIB "${CMAKE_CURRENT_SOURCE_DIR}/bin/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.lib")
set(PA_REDIRECT_PREBUILT_DLL "${CMAKE_CURRENT_SOURCE_DIR}/bin/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll")
if(EXISTS "${PA_REDIRECT_PREBUILT_LIB}" AND EXISTS "${PA_REDIRECT_PREBUILT_DLL}")
target_link_libraries(palloc PRIVATE "${PA_REDIRECT_PREBUILT_LIB}")
add_custom_command(TARGET palloc POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${PA_REDIRECT_PREBUILT_DLL}" $<TARGET_FILE_DIR:palloc>
COMMENT "Copy palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll to output directory")
install(FILES "$<TARGET_FILE_DIR:palloc>/palloc-redirect${PALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
add_subdirectory(bin)
target_link_libraries(palloc PRIVATE palloc-redirect)
add_custom_command(TARGET palloc POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:palloc-redirect> $<TARGET_FILE_DIR:palloc>
COMMENT "Copy palloc-redirect DLL to output directory")
install(FILES $<TARGET_FILE:palloc-redirect> DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
endif()

Expand All @@ -659,6 +673,8 @@ install(FILES include/palloc.h DESTINATION ${pa_install_incdir})
install(FILES include/palloc-override.h DESTINATION ${pa_install_incdir})
install(FILES include/palloc-new-delete.h DESTINATION ${pa_install_incdir})
install(FILES include/palloc-stats.h DESTINATION ${pa_install_incdir})
install(FILES include/palloc_cxx_arena.h DESTINATION ${pa_install_incdir})
install(FILES include/palloc/arena_pomai.h DESTINATION ${pa_install_incdir}/palloc)
install(FILES cmake/palloc-config.cmake DESTINATION ${pa_install_cmakedir})
install(FILES cmake/palloc-config-version.cmake DESTINATION ${pa_install_cmakedir})

Expand Down Expand Up @@ -724,7 +740,7 @@ if (PA_BUILD_TESTS)
enable_testing()

# static link tests
foreach(TEST_NAME api api-fill stress)
foreach(TEST_NAME api api-fill stress arena-pomai basic)
add_executable(palloc-test-${TEST_NAME} test/test-${TEST_NAME}.c)
target_compile_definitions(palloc-test-${TEST_NAME} PRIVATE ${pa_defines})
target_compile_options(palloc-test-${TEST_NAME} PRIVATE ${pa_cflags})
Expand Down
26 changes: 26 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 3,
"cmakeMinimumRequired": { "major": 3, "minor": 18 },
"configurePresets": [
{
"name": "release-maxperf",
"displayName": "Release (max throughput for benchmarks)",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"PA_OPT_ARCH": "ON",
"PA_PADDING": "OFF",
"PA_SECURE": "OFF",
"PA_DEBUG": "OFF",
"PA_DEBUG_INTERNAL": "OFF",
"PA_DEBUG_FULL": "OFF"
}
}
],
"buildPresets": [
{
"name": "release-maxperf",
"configurePreset": "release-maxperf"
}
]
}
Loading
Loading