Skip to content

Commit 99a5f9e

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

10 files changed

Lines changed: 203 additions & 198 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/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/Terminal/BackgroundColor.mpp

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,84 +25,90 @@ export namespace CppUtils::Terminal::BackgroundColor
2525

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

42-
[[nodiscard]] inline constexpr std::uint8_t getBackgroundColorCode(BackgroundColorEnum backgroundColor)
43-
{
44-
switch (backgroundColor)
44+
[[nodiscard]] inline constexpr std::uint8_t getBackgroundColorCode(BackgroundColorEnum backgroundColor)
4545
{
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;
46+
switch (backgroundColor)
47+
{
48+
case BackgroundColorEnum::Default:
49+
return Attribute::Default;
50+
case BackgroundColorEnum::Black:
51+
return Attribute::Black;
52+
case BackgroundColorEnum::Red:
53+
return Attribute::Red;
54+
case BackgroundColorEnum::Green:
55+
return Attribute::Green;
56+
case BackgroundColorEnum::Yellow:
57+
return Attribute::Yellow;
58+
case BackgroundColorEnum::Blue:
59+
return Attribute::Blue;
60+
case BackgroundColorEnum::Magenta:
61+
return Attribute::Magenta;
62+
case BackgroundColorEnum::Cyan:
63+
return Attribute::Cyan;
64+
case BackgroundColorEnum::White:
65+
return Attribute::White;
66+
default:
67+
return Attribute::Default;
68+
}
6669
}
6770
}
6871
#elif defined(OS_LINUX) or defined(OS_MACOS)
69-
namespace ANSIEscapeCode
72+
namespace Ansi
7073
{
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-
}
74+
namespace EscapeCode
75+
{
76+
[[maybe_unused]] inline constexpr auto Black = "\x1B[40m"sv;
77+
[[maybe_unused]] inline constexpr auto Red = "\x1B[41m"sv;
78+
[[maybe_unused]] inline constexpr auto Green = "\x1B[42m"sv;
79+
[[maybe_unused]] inline constexpr auto Yellow = "\x1B[43m"sv;
80+
[[maybe_unused]] inline constexpr auto Blue = "\x1B[44m"sv;
81+
[[maybe_unused]] inline constexpr auto Magenta = "\x1B[45m"sv;
82+
[[maybe_unused]] inline constexpr auto Cyan = "\x1B[46m"sv;
83+
[[maybe_unused]] inline constexpr auto White = "\x1B[47m"sv;
84+
[[maybe_unused]] inline constexpr auto Default = "\x1B[49m"sv;
85+
}
8186

82-
[[nodiscard]] inline constexpr std::string_view getBackgroundColorCode(BackgroundColorEnum backgroundColor)
83-
{
84-
switch (backgroundColor)
87+
[[nodiscard]] inline constexpr std::string_view getBackgroundColorCode(BackgroundColorEnum backgroundColor)
8588
{
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;
89+
switch (backgroundColor)
90+
{
91+
case BackgroundColorEnum::Default:
92+
return EscapeCode::Default;
93+
case BackgroundColorEnum::Black:
94+
return EscapeCode::Black;
95+
case BackgroundColorEnum::Red:
96+
return EscapeCode::Red;
97+
case BackgroundColorEnum::Green:
98+
return EscapeCode::Green;
99+
case BackgroundColorEnum::Yellow:
100+
return EscapeCode::Yellow;
101+
case BackgroundColorEnum::Blue:
102+
return EscapeCode::Blue;
103+
case BackgroundColorEnum::Magenta:
104+
return EscapeCode::Magenta;
105+
case BackgroundColorEnum::Cyan:
106+
return EscapeCode::Cyan;
107+
case BackgroundColorEnum::White:
108+
return EscapeCode::White;
109+
default:
110+
return EscapeCode::Default;
111+
}
106112
}
107113
}
108114
#endif

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)