Skip to content

Commit e54144c

Browse files
committed
Ci Windows: llvm toolchain
1 parent 5c1180b commit e54144c

12 files changed

Lines changed: 210 additions & 187 deletions

File tree

.github/workflows/ci-cpp-windows.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,37 @@ jobs:
1111
matrix:
1212
compiler:
1313
- {
14-
name: "cl",
15-
cc: "cl",
16-
cxx: "cl"
14+
name: "Clang",
15+
cc: "clang",
16+
cxx: "clang++",
17+
xmake-toolchain: "--toolchain=llvm --sdk=\"$env:LLVM_PATH\""
1718
}
1819
steps:
1920
- uses: actions/checkout@v4
2021
- uses: xmake-io/github-action-setup-xmake@v1
2122
with:
2223
xmake-version: branch@master
23-
- uses: ilammy/msvc-dev-cmd@v1
24+
25+
- name: Install LLVM
26+
uses: KyleMayes/install-llvm-action@master
2427
with:
25-
toolset: "14.39"
26-
- name: Compile
28+
version: "21.1.3"
29+
30+
- name: Configure & Install dependencies
31+
shell: pwsh
2732
env:
2833
CC: ${{ matrix.compiler.cc }}
2934
CXX: ${{ matrix.compiler.cxx }}
3035
run: |
31-
xmake f --enable_tests=y --yes
32-
xmake build -vD
36+
xmake f ${{ matrix.compiler.xmake-toolchain }} --runtimes="c++_shared" --enable_tests=y -v --yes
37+
38+
- name: Build
39+
shell: pwsh
40+
run: |
41+
xmake build -v
3342
3443
- name: Run tests
44+
shell: pwsh
3545
run: |
3646
xmake run
47+

modules/Language/VirtualMachine.mpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ export namespace CppUtils::Language::VirtualMachine
232232
return std::unexpected{"No type defined"sv};
233233
else if (auto typeId = stack.template pop<std::size_t>(); not typeId) [[unlikely]]
234234
return std::unexpected{typeId.error()};
235+
else if (typeId.value() >= std::tuple_size_v<decltype(types)>) [[unlikely]]
236+
return std::unexpected{std::format("Instruction push: Type identifier {} out of range (max {})", typeId.value(), std::tuple_size_v<decltype(types)>)};
235237
else if (auto result = Type::Tuple::visitAt(types, typeId.value(), [&stack](const auto& value) {
236238
return stack.push(value);
237239
});
@@ -244,6 +246,8 @@ export namespace CppUtils::Language::VirtualMachine
244246
return std::unexpected{"No type defined"sv};
245247
else if (auto typeId = stack.template pop<std::size_t>(); not typeId) [[unlikely]]
246248
return std::unexpected{typeId.error()};
249+
else if (typeId.value() >= std::tuple_size_v<decltype(types)>) [[unlikely]]
250+
return std::unexpected{std::format("Instruction drop: Type identifier {} out of range (max {})", typeId.value(), std::tuple_size_v<decltype(types)>)};
247251
else if (auto result = Type::Tuple::visitAt(types, typeId.value(), [&stack](const auto& value) {
248252
return stack.drop(sizeof(std::remove_cvref_t<decltype(value)>));
249253
});

modules/Math/Random.mpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export namespace CppUtils::Math
99
{
1010
thread_local auto engine = [] {
1111
static auto randomDevice = std::random_device{};
12-
return std::mt19937{randomDevice() ^ std::hash<std::thread::id>{}(std::this_thread::get_id())};
12+
return std::mt19937{static_cast<std::mt19937::result_type>(randomDevice() ^ std::hash<std::thread::id>{}(std::this_thread::get_id()))};
1313
}();
1414
auto distribution = std::uniform_int_distribution<Integer>{min, max};
1515
auto randomNumber = distribution(engine);

modules/Network/Socket.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ export namespace CppUtils::Network
230230
FD_SET(m_socket, std::addressof(readSet));
231231

232232
auto timeValue = timeval{};
233-
timeValue.tv_sec = std::chrono::duration_cast<std::chrono::seconds>(timeout).count();
234-
timeValue.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(timeout % 1s).count();
233+
timeValue.tv_sec = static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>(timeout).count());
234+
timeValue.tv_usec = static_cast<long>(std::chrono::duration_cast<std::chrono::microseconds>(timeout % 1s).count());
235235

236236
#ifdef OS_WINDOWS
237237
auto result = ::select(0, std::addressof(readSet), nullptr, nullptr, std::addressof(timeValue));

modules/Terminal/BackgroundColor.mpp

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,87 +23,91 @@ export namespace CppUtils::Terminal::BackgroundColor
2323
White
2424
};
2525

26-
#if defined(OS_WINDOWS)
2726
// see https://learn.microsoft.com/en-us/windows/console/char-info-str
28-
namespace Attribute
27+
namespace WindowsNative
2928
{
30-
[[maybe_unused]] inline constexpr std::uint8_t Black = 0;
31-
[[maybe_unused]] inline constexpr std::uint8_t Red = 0x40;
32-
[[maybe_unused]] inline constexpr std::uint8_t Green = 0x20;
33-
[[maybe_unused]] inline constexpr std::uint8_t Intensity = 0x80;
34-
[[maybe_unused]] inline constexpr std::uint8_t Yellow = Red | Green | Intensity;
35-
[[maybe_unused]] inline constexpr std::uint8_t Blue = 0x10;
36-
[[maybe_unused]] inline constexpr std::uint8_t Magenta = 13;
37-
[[maybe_unused]] inline constexpr std::uint8_t Cyan = 11;
38-
[[maybe_unused]] inline constexpr std::uint8_t White = 15;
39-
[[maybe_unused]] inline constexpr std::uint8_t Default = 0;
40-
}
29+
namespace Attribute
30+
{
31+
[[maybe_unused]] inline constexpr std::uint8_t Black = 0;
32+
[[maybe_unused]] inline constexpr std::uint8_t Red = 0x40;
33+
[[maybe_unused]] inline constexpr std::uint8_t Green = 0x20;
34+
[[maybe_unused]] inline constexpr std::uint8_t Intensity = 0x80;
35+
[[maybe_unused]] inline constexpr std::uint8_t Yellow = Red | Green | Intensity;
36+
[[maybe_unused]] inline constexpr std::uint8_t Blue = 0x10;
37+
[[maybe_unused]] inline constexpr std::uint8_t Magenta = 13;
38+
[[maybe_unused]] inline constexpr std::uint8_t Cyan = 11;
39+
[[maybe_unused]] inline constexpr std::uint8_t White = 15;
40+
[[maybe_unused]] inline constexpr std::uint8_t Default = 0;
41+
}
4142

42-
[[nodiscard]] inline constexpr std::uint8_t getBackgroundColorCode(BackgroundColorEnum backgroundColor)
43-
{
44-
switch (backgroundColor)
43+
[[nodiscard]] inline constexpr std::uint8_t getBackgroundColorCode(BackgroundColorEnum backgroundColor)
4544
{
46-
case BackgroundColorEnum::Default:
47-
return Attribute::Default;
48-
case BackgroundColorEnum::Black:
49-
return Attribute::Black;
50-
case BackgroundColorEnum::Red:
51-
return Attribute::Red;
52-
case BackgroundColorEnum::Green:
53-
return Attribute::Green;
54-
case BackgroundColorEnum::Yellow:
55-
return Attribute::Yellow;
56-
case BackgroundColorEnum::Blue:
57-
return Attribute::Blue;
58-
case BackgroundColorEnum::Magenta:
59-
return Attribute::Magenta;
60-
case BackgroundColorEnum::Cyan:
61-
return Attribute::Cyan;
62-
case BackgroundColorEnum::White:
63-
return Attribute::White;
64-
default:
65-
return Attribute::Default;
45+
switch (backgroundColor)
46+
{
47+
case BackgroundColorEnum::Default:
48+
return Attribute::Default;
49+
case BackgroundColorEnum::Black:
50+
return Attribute::Black;
51+
case BackgroundColorEnum::Red:
52+
return Attribute::Red;
53+
case BackgroundColorEnum::Green:
54+
return Attribute::Green;
55+
case BackgroundColorEnum::Yellow:
56+
return Attribute::Yellow;
57+
case BackgroundColorEnum::Blue:
58+
return Attribute::Blue;
59+
case BackgroundColorEnum::Magenta:
60+
return Attribute::Magenta;
61+
case BackgroundColorEnum::Cyan:
62+
return Attribute::Cyan;
63+
case BackgroundColorEnum::White:
64+
return Attribute::White;
65+
default:
66+
return Attribute::Default;
67+
}
6668
}
6769
}
68-
#elif defined(OS_LINUX) or defined(OS_MACOS)
69-
namespace ANSIEscapeCode
70-
{
71-
[[maybe_unused]] inline constexpr auto Black = "\x1B[40m"sv;
72-
[[maybe_unused]] inline constexpr auto Red = "\x1B[41m"sv;
73-
[[maybe_unused]] inline constexpr auto Green = "\x1B[42m"sv;
74-
[[maybe_unused]] inline constexpr auto Yellow = "\x1B[43m"sv;
75-
[[maybe_unused]] inline constexpr auto Blue = "\x1B[44m"sv;
76-
[[maybe_unused]] inline constexpr auto Magenta = "\x1B[45m"sv;
77-
[[maybe_unused]] inline constexpr auto Cyan = "\x1B[46m"sv;
78-
[[maybe_unused]] inline constexpr auto White = "\x1B[47m"sv;
79-
[[maybe_unused]] inline constexpr auto Default = "\x1B[49m"sv;
80-
}
8170

82-
[[nodiscard]] inline constexpr std::string_view getBackgroundColorCode(BackgroundColorEnum backgroundColor)
71+
namespace Ansi
8372
{
84-
switch (backgroundColor)
73+
namespace EscapeCode
74+
{
75+
[[maybe_unused]] inline constexpr auto Black = "\x1B[40m"sv;
76+
[[maybe_unused]] inline constexpr auto Red = "\x1B[41m"sv;
77+
[[maybe_unused]] inline constexpr auto Green = "\x1B[42m"sv;
78+
[[maybe_unused]] inline constexpr auto Yellow = "\x1B[43m"sv;
79+
[[maybe_unused]] inline constexpr auto Blue = "\x1B[44m"sv;
80+
[[maybe_unused]] inline constexpr auto Magenta = "\x1B[45m"sv;
81+
[[maybe_unused]] inline constexpr auto Cyan = "\x1B[46m"sv;
82+
[[maybe_unused]] inline constexpr auto White = "\x1B[47m"sv;
83+
[[maybe_unused]] inline constexpr auto Default = "\x1B[49m"sv;
84+
}
85+
86+
[[nodiscard]] inline constexpr std::string_view getBackgroundColorCode(BackgroundColorEnum backgroundColor)
8587
{
86-
case BackgroundColorEnum::Default:
87-
return ANSIEscapeCode::Default;
88-
case BackgroundColorEnum::Black:
89-
return ANSIEscapeCode::Black;
90-
case BackgroundColorEnum::Red:
91-
return ANSIEscapeCode::Red;
92-
case BackgroundColorEnum::Green:
93-
return ANSIEscapeCode::Green;
94-
case BackgroundColorEnum::Yellow:
95-
return ANSIEscapeCode::Yellow;
96-
case BackgroundColorEnum::Blue:
97-
return ANSIEscapeCode::Blue;
98-
case BackgroundColorEnum::Magenta:
99-
return ANSIEscapeCode::Magenta;
100-
case BackgroundColorEnum::Cyan:
101-
return ANSIEscapeCode::Cyan;
102-
case BackgroundColorEnum::White:
103-
return ANSIEscapeCode::White;
104-
default:
105-
return ANSIEscapeCode::Default;
88+
switch (backgroundColor)
89+
{
90+
case BackgroundColorEnum::Default:
91+
return EscapeCode::Default;
92+
case BackgroundColorEnum::Black:
93+
return EscapeCode::Black;
94+
case BackgroundColorEnum::Red:
95+
return EscapeCode::Red;
96+
case BackgroundColorEnum::Green:
97+
return EscapeCode::Green;
98+
case BackgroundColorEnum::Yellow:
99+
return EscapeCode::Yellow;
100+
case BackgroundColorEnum::Blue:
101+
return EscapeCode::Blue;
102+
case BackgroundColorEnum::Magenta:
103+
return EscapeCode::Magenta;
104+
case BackgroundColorEnum::Cyan:
105+
return EscapeCode::Cyan;
106+
case BackgroundColorEnum::White:
107+
return EscapeCode::White;
108+
default:
109+
return EscapeCode::Default;
110+
}
106111
}
107112
}
108-
#endif
109113
}

modules/Terminal/Canvas.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ export namespace CppUtils::Terminal
139139
}
140140
if (needUpdateTextColor)
141141
{
142-
stringBuffer += TextColor::getTextColorCode(currentChar.textColor);
142+
stringBuffer += TextColor::Ansi::getTextColorCode(currentChar.textColor);
143143
lastAttributes.textColor = currentChar.textColor;
144144
}
145145
if (needUpdateBackgroundColor)
146146
{
147-
stringBuffer += BackgroundColor::getBackgroundColorCode(currentChar.backgroundColor);
147+
stringBuffer += BackgroundColor::Ansi::getBackgroundColorCode(currentChar.backgroundColor);
148148
lastAttributes.backgroundColor = currentChar.backgroundColor;
149149
}
150150
stringBuffer += currentChar.character;

modules/Terminal/Cursor.mpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export module CppUtils.Terminal.Cursor;
99
import std;
1010
import CppUtils.Container.Size;
1111
import CppUtils.Terminal.RawTerminal;
12+
import CppUtils.Terminal.TextModifier;
1213

1314
export namespace CppUtils::Terminal
1415
{
@@ -27,7 +28,7 @@ export namespace CppUtils::Terminal
2728
using namespace std::literals;
2829

2930
auto rawTerminal = RawTerminal{};
30-
std::print("\x1b[6n");
31+
std::print("{}", Ansi::EscapeCode::GetCursorPosition);
3132
std::fflush(stdout);
3233

3334
const auto response = rawTerminal.read('R');
@@ -46,7 +47,7 @@ export namespace CppUtils::Terminal
4647
#elif defined(OS_LINUX) or defined(OS_MACOS)
4748
inline auto setCursorPosition([[maybe_unused]] Container::Size2 position) -> void
4849
{
49-
std::print("\x1b[{};{}H", position.y(), position.x());
50+
std::print(Ansi::EscapeCode::SetCursorPosition, position.y(), position.x());
5051
}
5152
#endif
5253
}

0 commit comments

Comments
 (0)