Skip to content

Commit 3caa4a5

Browse files
committed
cmake: fix build for Alpine
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][3] 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 [3]: https://www.freedesktop.org/software/systemd/man/latest/os-release.html Reviewed-by: Maxim Kokryashkin <[email protected]> Reviewed-by: Sergey Bronnikov <[email protected]> Signed-off-by: Sergey Kaplun <[email protected]> (cherry picked from commit 3f4f46a)
1 parent b910b50 commit 3caa4a5

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ separate_arguments(LUAJIT_TEST_COMMAND)
7474
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
7575
include(AddTestLib)
7676
include(GetLibCVersion)
77+
include(GetLinuxDistro)
7778
include(LibRealPath)
7879

7980
# CTEST_FLAGS is used by CMake targets in test suites.

test/LuaJIT-tests/CMakeLists.txt

+11-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ if(CMAKE_C_FLAGS MATCHES "-march=skylake-avx512")
6262
list(APPEND LUAJIT_TEST_TAGS_EXTRA +avx512)
6363
endif()
6464

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

7478
if(LUAJIT_ENABLE_TABLE_BUMP)

test/cmake/GetLinuxDistro.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Determine the Linux distro id and return it in the `output`
2+
# variable. See https://www.linux.org/docs/man5/os-release.html
3+
# for details.
4+
macro(GetLinuxDistro output)
5+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
6+
message(FATAL_ERROR "GetLinuxDistro macro must be used only on Linux")
7+
endif()
8+
set(OS_RELEASE_FILE /etc/os-release)
9+
if(NOT EXISTS ${OS_RELEASE_FILE})
10+
set(OS_RELEASE_FILE /usr/lib/os-release)
11+
endif()
12+
file(READ ${OS_RELEASE_FILE} OS_RELEASE)
13+
string(REGEX MATCH "ID=([0-9a-z._-]+)" MATCH ${OS_RELEASE})
14+
if(MATCH)
15+
set(${output} ${CMAKE_MATCH_1})
16+
else()
17+
set(${output} linux)
18+
endif()
19+
unset(OS_RELEASE_FILE)
20+
unset(OS_RELEASE)
21+
unset(MATCH)
22+
unset(CMAKE_MATCH_1)
23+
endmacro()

0 commit comments

Comments
 (0)