Skip to content

Commit

Permalink
cmake: fix build for Alpine
Browse files Browse the repository at this point in the history
Since Alpine uses musl [1] as its C standard library, the build for it
failed after the commit af0f59d ("test:
fix LuaJIT-tests for old libc version"), since `GetLibCVersion()` raises
an error. This patch adds the check of the ID in the /etc/os-release [2]
of the Linux distribution and avoids setting the GLibC version if the
distro is "alpine".

[1]: https://wiki.alpinelinux.org/wiki/Musl
[2]: https://www.linux.org/docs/man5/os-release.html
  • Loading branch information
Buristan committed Dec 13, 2024
1 parent 3cd5078 commit 7b04462
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ separate_arguments(LUAJIT_TEST_COMMAND)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AddTestLib)
include(GetLibCVersion)
include(GetLinuxDistro)
include(LibRealPath)

# CTEST_FLAGS is used by CMake targets in test suites.
Expand Down
18 changes: 11 additions & 7 deletions test/LuaJIT-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ if(CMAKE_C_FLAGS MATCHES "-march=skylake-avx512")
list(APPEND LUAJIT_TEST_TAGS_EXTRA +avx512)
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
GetLibCVersion(LIBC_VERSION)
# XXX: <tonumber_scan.lua> uses `strtod()`, old versions of
# which have the bug [1] for "0x1p-2075" parsing. Add the skip
# check for it.
# [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=16151
list(APPEND LUAJIT_TEST_TAGS_EXTRA +libc=${LIBC_VERSION})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
GetLinuxDistro(LINUX_DISTRO)
# Alpine uses musl instead of GLibC.
if(NOT LINUX_DISTRO MATCHES "alpine")
GetLibCVersion(LIBC_VERSION)
# XXX: <tonumber_scan.lua> uses `strtod()`, old versions of
# which have the bug [1] for "0x1p-2075" parsing. Add the skip
# check for it.
# [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=16151
list(APPEND LUAJIT_TEST_TAGS_EXTRA +libc=${LIBC_VERSION})
endif()
endif()

if(LUAJIT_ENABLE_TABLE_BUMP)
Expand Down
18 changes: 18 additions & 0 deletions test/cmake/GetLinuxDistro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Determine the Linux distro id and return it in the `output`
# variable. See https://www.linux.org/docs/man5/os-release.html
# for details.
macro(GetLinuxDistro output)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(FATAL_ERROR "GetLinuxDistro macro must be used only on Linux")
endif()
file(READ /etc/os-release OS_RELEASE)
string(REGEX MATCH "ID=([0-9a-z._-]+)" MATCH ${OS_RELEASE})
if(MATCH)
set(${output} ${CMAKE_MATCH_1})
else()
set(${output} linux)
endif()
unset(OS_RELEASE)
unset(MATCH)
unset(CMAKE_MATCH_1)
endmacro()

0 comments on commit 7b04462

Please sign in to comment.