Skip to content

Commit b49194a

Browse files
authored
Merge pull request #77 from kaitai-io/gh-actions-macos
GH Actions: add macOS 14
2 parents 5ba1468 + e95f7d9 commit b49194a

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ jobs:
3939
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE='include-what-you-use;-Xiwyu;--verbose=3'
4040
- name: Run tests
4141
run: .build/run-unittest --valgrind
42+
macos:
43+
runs-on: macos-14
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
cpp-standard:
48+
- '98'
49+
- '11'
50+
- '20'
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Install GoogleTest
54+
env:
55+
CPP_STANDARD: ${{ matrix.cpp-standard }}
56+
run: .build/install-gtest "$CPP_STANDARD"
57+
- name: Build
58+
env:
59+
CPP_STANDARD: ${{ matrix.cpp-standard }}
60+
# This tells the C++ compiler to produce debugging info that Valgrind needs to report line numbers.
61+
# See also https://valgrind.org/docs/manual/manual-core.html#manual-core.started
62+
CMAKE_BUILD_TYPE: Debug
63+
run: |
64+
.build/build \
65+
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
66+
-DCMAKE_CXX_STANDARD="$CPP_STANDARD" -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF
67+
- name: Run tests
68+
run: .build/run-unittest
4269

4370
# Builds and runs tests on Ubuntu 7.10.
4471
# It ships with:

Common.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ target_compile_options(${PROJECT_NAME} PRIVATE
1515
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
1616
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
1717
-Wall -Wextra -Wpedantic -Werror
18+
19+
# We're using the `long long` type intentionally. Although it's not part of C++98, in
20+
# practice it is usually supported even by ancient compilers with very limited C++11
21+
# support. And we already unconditionally require `uint64_t`, so it would be strange if
22+
# the compiler supported `uint64_t` and not `long long`.
23+
-Wno-error=long-long
24+
1825
# See <https://gcc.gnu.org/onlinedocs/gcc-13.3.0/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn>:
1926
#
2027
# > Level 1: (...) it has very few false negatives. However, it has many false positives.

gcc4.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ OBJS := \
1313

1414
CXXFLAGS := -std=c++98 -Wall -Wextra -pedantic
1515

16+
# `-pedantic` enables `-Wlong-long`, which for some reason turns into
17+
# `error: ISO C++ does not support 'long long'`, even though we don't use `-Werror`. Since
18+
# we're using `long long` intentionally, we suppress this error using `-Wno-long-long`
19+
# (see https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Warning-Options.html#index-Wlong_002dlong-305).
20+
CXXFLAGS += -Wno-long-long
21+
1622
# NOTE: the meaning of `<n>` values in `-Wstrict-aliasing=<n>` is different in GCC 4.1.2
1723
# than in recent versions of GCC. According to
1824
# https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Warning-Options.html#index-Wstrict_002daliasing-246,

kaitai/kaitaistream.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <ios> // std::streamsize, forward declaration of std::istream // IWYU pragma: keep
1515
#include <cstddef> // std::size_t
16+
#include <climits> // LLONG_MAX, ULLONG_MAX
1617
#include <sstream> // std::istringstream // IWYU pragma: keep
1718
#include <string> // std::string
1819

@@ -252,8 +253,11 @@ class kstream {
252253
return to_string_signed(val);
253254
}
254255

255-
// The `long long` type is only available since C++11, so we use it only in C++11 mode.
256-
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
256+
// The `long long` type is technically available only since C++11. It is usually
257+
// supported even by ancient compilers that have very limited C++11 support, but we can
258+
// still check if the `LLONG_MAX` macro is defined (it seems very unlikely that it is not,
259+
// though).
260+
#ifdef LLONG_MAX
257261
/**
258262
* Converts given integer `val` to a decimal string representation.
259263
* Should be used in place of `std::to_string(long long)` (which is available only
@@ -282,8 +286,11 @@ class kstream {
282286
return to_string_unsigned(val);
283287
}
284288

285-
// The `unsigned long long` type is only available since C++11, so we use it only in C++11 mode.
286-
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
289+
// The `unsigned long long` type is technically available only since C++11. It is usually
290+
// supported even by ancient compilers that have very limited C++11 support, but we can
291+
// still check if the `LLONG_MAX` macro is defined (it seems very unlikely that it is not,
292+
// though).
293+
#ifdef ULLONG_MAX
287294
/**
288295
* Converts given integer `val` to a decimal string representation.
289296
* Should be used in place of `std::to_string(unsigned long long)` (which is available only

tests/unittest.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ TEST(KaitaiStreamTest, to_string_long)
154154
#pragma warning(pop)
155155
#endif
156156

157-
// The `long long` type is only available since C++11, so we use it only in C++11 mode.
158-
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
159157
TEST(KaitaiStreamTest, to_string_unsigned_long_long)
160158
{
161159
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<unsigned long long>::min()), "0");
@@ -167,20 +165,6 @@ TEST(KaitaiStreamTest, to_string_long_long)
167165
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<long long>::min()), "-9223372036854775808");
168166
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<long long>::max()), "9223372036854775807");
169167
}
170-
#else
171-
// Make sure we still support 64-bit integers.
172-
TEST(KaitaiStreamTest, to_string_uint64)
173-
{
174-
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<uint64_t>::min()), "0");
175-
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<uint64_t>::max()), "18446744073709551615");
176-
}
177-
178-
TEST(KaitaiStreamTest, to_string_int64)
179-
{
180-
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<int64_t>::min()), "-9223372036854775808");
181-
EXPECT_EQ(kaitai::kstream::to_string(std::numeric_limits<int64_t>::max()), "9223372036854775807");
182-
}
183-
#endif
184168

185169
TEST(KaitaiStreamTest, string_to_int)
186170
{
@@ -578,15 +562,17 @@ TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_too_short)
578562
}
579563
}
580564

581-
#if defined(__FreeBSD__) || defined(__NetBSD__)
565+
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
582566
TEST(KaitaiStreamTest, DISABLED_bytes_to_str_invalid_seq_gb2312_two_bytes)
583567
#else
584568
TEST(KaitaiStreamTest, bytes_to_str_invalid_seq_gb2312_two_bytes)
585569
#endif
586570
{
587-
// 0xB0 0x30 is illegal sequence in GB2312: 0xB0 must be followed by [0xA1..0xFE].
588-
// However, some iconv engines, namely CITRUS integrated with modern FreeBSD (10+) and NetBSD,
589-
// are not considering this as error and thus not returning EILSEQ.
571+
// 0xB0 0x30 is illegal sequence in GB2312: 0xB0 must be followed by [0xA1..0xFE]. However,
572+
// some iconv engines, namely CITRUS integrated with modern FreeBSD (10+) and NetBSD, are
573+
// not considering this an error and thus not returning EILSEQ. Iconv preinstalled in the
574+
// GitHub Actions `macos-14` runner image does not consider this an error either.
575+
//
590576
try {
591577
std::string res = kaitai::kstream::bytes_to_str("\xb0\x30", "GB2312");
592578
FAIL() << "Expected illegal_seq_in_encoding exception";

0 commit comments

Comments
 (0)