Skip to content

Commit beac9d7

Browse files
committed
Fixing windows side compilation problems with the Visual C standard library used by the windows side clang/llvm
1 parent 2e87d33 commit beac9d7

File tree

9 files changed

+60
-47
lines changed

9 files changed

+60
-47
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [ dev, main ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ dev, main ]
88

99
permissions:
1010
contents: read
@@ -16,17 +16,21 @@ concurrency:
1616

1717
jobs:
1818
build-test:
19-
name: Build & Test (${{ matrix.os }} / ${{ matrix.compiler }})
19+
name: Build & Test (${{ matrix.os }} / ${{ matrix.compiler }} / ${{ matrix.platform }})
2020
runs-on: ${{ matrix.os }}
2121
strategy:
22-
fail-fast: true
22+
fail-fast: false # We want to test on all compilers, so stopping jobs when other job fails is not good.
2323
matrix:
2424
os: [ubuntu-latest, windows-latest]
25-
compiler: [gcc, clang]
25+
compiler: [g++, clang]
26+
platform: [x86, x64]
2627

2728
env:
28-
CXX: ${{ matrix.compiler == 'clang' && 'clang++' || 'g++' }}
29-
CC: ${{ matrix.compiler == 'clang' && 'clang' || 'gcc' }}
29+
CXX: ${{ matrix.compiler == 'clang' && 'clang++-14' || 'g++-13' }}
30+
CC: ${{ matrix.compiler == 'clang' && 'clang-14' || 'gcc-13' }}
31+
CFLAGS: ${{ matrix.platform == 'x86' && '-m32' || '-m64' }}
32+
CXXFLAGS: ${{ matrix.platform == 'x86' && '-m32' || '-m64' }}
33+
LDFLAGS: ${{ matrix.platform == 'x86' && '-m32' || '-m64' }}
3034

3135
steps:
3236
- name: Checkout
@@ -36,9 +40,14 @@ jobs:
3640
if: matrix.os == 'ubuntu-latest'
3741
run: |
3842
sudo apt-get update
39-
sudo apt-get install -y build-essential python3 python3-pip ninja-build meson valgrind
43+
sudo apt-get install -y build-essential python3 python3-pip ninja-build meson
44+
if [ "${{ matrix.platform }}" = "x86" ]; then
45+
sudo apt-get install -y gcc-13-multilib g++-13-multilib
46+
fi
4047
if [ "${{ matrix.compiler }}" = "clang" ]; then
41-
sudo apt-get install -y clang
48+
sudo apt-get install -y clang-14
49+
else
50+
sudo apt-get install -y gcc-13 g++-13
4251
fi
4352
4453
- name: Install dependencies (Windows)
@@ -59,14 +68,6 @@ jobs:
5968
if: matrix.os == 'windows-latest'
6069
run: .\bin\init.bat
6170

62-
- name: Compile Ubuntu
63-
if: matrix.os == 'ubuntu-latest'
64-
run: ./bin/build.sh
65-
66-
- name: Compile Windows
67-
if: matrix.os == 'windows-latest'
68-
run: .\bin\build.bat
69-
7071
- name: Run tests Ubuntu
7172
if: matrix.os == 'ubuntu-latest'
7273
run: ./bin/test.sh

src/core/renderer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
#include <exception>
1717
#include <csignal>
1818
#include <atomic>
19+
#include <iomanip>
1920

2021
#if _WIN32
2122
#include <windows.h>
2223
#include <dbghelp.h>
24+
#undef min
25+
#undef max
26+
#undef small
2327
#else
2428
#include <sys/ioctl.h>
2529
#include <signal.h>
@@ -112,13 +116,14 @@ namespace GGUI{
112116
*/
113117
std::string now(){
114118
// This function takes the current time and returns a string of the time.
115-
// Format: DD.MM.YYYY: SS.MM.HH
116119
std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
120+
std::tm* tm_ptr = std::localtime(&now);
121+
122+
std::ostringstream oss;
123+
// Format: DD.MM.YYYY: SS.MM.HH
124+
oss << std::put_time(tm_ptr, "%d.%m.%Y: %S.%M.%H");
117125

118-
std::string Result = std::ctime(&now);
119-
120-
// Remove the newline at the end of the string
121-
return Result.substr(0, Result.size() - 1);
126+
return oss.str();
122127
}
123128

124129
/**

src/core/utils/conveyorAllocator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace GGUI {
1616
*/
1717
template<typename T>
1818
class conveyorAllocator {
19-
unsigned char* rawBuffer = nullptr;
19+
T* rawBuffer = nullptr;
2020
std::size_t capacity = 0;
2121
std::size_t size = 0;
2222
public:
@@ -28,7 +28,7 @@ namespace GGUI {
2828
* The memory is uninitialized (raw bytes) and the logical size is set to 0.
2929
*/
3030
conveyorAllocator(std::size_t initialSize) {
31-
rawBuffer = new unsigned char[sizeof(T) * initialSize];
31+
rawBuffer = new T[initialSize];
3232
capacity = initialSize;
3333
clear();
3434
}
@@ -52,7 +52,7 @@ namespace GGUI {
5252
void resize(std::size_t newCapacity) {
5353
if (newCapacity > capacity) {
5454
// Allocate new mem
55-
unsigned char* newBuffer = new unsigned char[sizeof(T) * newCapacity];
55+
T* newBuffer = new T[newCapacity];
5656
// Copy existing contents (based on current logical size)
5757
if (rawBuffer && size > 0) {
5858
std::memcpy(newBuffer, rawBuffer, sizeof(T) * size);
@@ -91,7 +91,7 @@ namespace GGUI {
9191
resize(size + mapSize);
9292
}
9393

94-
compactString* view = reinterpret_cast<compactString*>(rawBuffer + size * sizeof(T));
94+
compactString* view = reinterpret_cast<compactString*>(rawBuffer + size);
9595

9696
result.remap(
9797
view,
@@ -117,7 +117,7 @@ namespace GGUI {
117117
* @brief Obtain a mutable pointer to the contiguous element data.
118118
* @return Pointer to first element (reinterpret_cast from raw bytes).
119119
*/
120-
T* getData() { return (T*)rawBuffer; }
120+
T* getData() { return rawBuffer; }
121121
};
122122

123123
}

src/core/utils/fileStreamer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#if _WIN32
77
#include <windows.h>
8+
#undef min
9+
#undef max
10+
#undef small
811
#else
912
#include <sys/types.h>
1013
#include <sys/wait.h>

src/core/utils/fileStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace GGUI{
177177
* @return True if synchronization was successful, false otherwise.
178178
*/
179179
bool sync(bufferCapture* Informer);
180+
using std::streambuf::sync; // Keep the base class virtual function. (Maybe we should add this as an proper override in bufferCapture?...)
180181

181182
/**
182183
* @brief Gets the name of this BUFFER_CAPTURE.

src/core/utils/logger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#if _WIN32
1515
#include <windows.h>
1616
#include <dbghelp.h>
17+
#undef min
18+
#undef max
19+
#undef small
1720
#else
1821
#if !defined(__ANDROID__) // Currently Termux does not support execinfo libraries as part of cpplib.
1922
#include <execinfo.h> // For stacktrace

src/core/utils/style.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ namespace GGUI{
18901890

18911891
inline ~node() override { styleBase::~styleBase(); }
18921892

1893-
inline styleBase* copy() const override;
1893+
styleBase* copy() const override;
18941894

18951895
constexpr node& operator=(const node& other){
18961896
// Only copy the information if the other is enabled.
@@ -1924,7 +1924,7 @@ namespace GGUI{
19241924

19251925
inline ~childs() override { styleBase::~styleBase(); }
19261926

1927-
inline styleBase* copy() const override;
1927+
styleBase* copy() const override;
19281928

19291929
constexpr childs& operator=(const childs& other){
19301930
// Only copy the information if the other is enabled.

src/core/utils/utils.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ namespace GGUI{
1313
extern void* Stack_Start_Address;
1414
extern void* Heap_Start_Address;
1515

16-
/**
17-
* @brief Initializes the Stack_Start_Address and Heap_Start_Address variables
18-
*
19-
* This function captures the nearest stack address and the nearest heap address
20-
* and assigns them to the Stack_Start_Address and Heap_Start_Address variables
21-
* respectively. This only happens if the variables are not already set.
22-
*/
23-
#if _WIN32
16+
#if _WIN32
2417
#include <windows.h>
2518
#include <winternl.h>
19+
#undef min
20+
#undef max
21+
#undef small
2622

2723
/**
2824
* @typedef NtQueryInformationThread_t
@@ -118,7 +114,8 @@ namespace GGUI{
118114
Heap_Start_Address = new int;
119115
}
120116
}
121-
#else
117+
#else
118+
122119
/**
123120
* @brief Reads the start addresses of the stack and heap memory areas.
124121
*
@@ -184,9 +181,9 @@ namespace GGUI{
184181
Heap_Start_Address = new int;
185182
}
186183
}
187-
#endif
184+
#endif
188185

189-
/**
186+
/**
190187
* @brief Extracts the directory path from a full executable path.
191188
*
192189
* This function takes a full path to an executable and returns the directory
@@ -210,8 +207,11 @@ namespace GGUI{
210207
return ""; // Fallback if separator not found
211208
}
212209

213-
#if defined(_WIN32) || defined(_WIN64)
210+
#if defined(_WIN32) || defined(_WIN64)
214211
#include <windows.h>
212+
#undef min
213+
#undef max
214+
#undef small
215215

216216
/**
217217
* @brief Retrieves the path of the executable file of the current process.
@@ -231,7 +231,7 @@ namespace GGUI{
231231
return path;
232232
}
233233

234-
#elif defined(__linux__) || defined(__unix__) || defined(__APPLE__)
234+
#elif defined(__linux__) || defined(__unix__) || defined(__APPLE__)
235235
#include <unistd.h>
236236
#include <limits.h>
237237

@@ -256,7 +256,7 @@ namespace GGUI{
256256
return path;
257257
}
258258

259-
#else
259+
#else
260260
/**
261261
* @brief Retrieves the path of the executable.
262262
*
@@ -265,7 +265,7 @@ namespace GGUI{
265265
const char* Get_Executable_Path() {
266266
return "";
267267
}
268-
#endif
268+
#endif
269269

270270
/**
271271
* @brief Constructs the file name for the logger.

src/elements/listView.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void GGUI::listView::addChild(element* e) {
9393
// Determine the flow direction for the list view.
9494
if (Style->Flow_Priority.value == DIRECTION::ROW) {
9595
// Adjust for minimum width needed when borders are present.
96-
signed int Width_Modifier = e->hasBorder() & Last_Child->hasBorder();
96+
signed int Width_Modifier = e->hasBorder() && Last_Child->hasBorder();
9797
if (isDynamicSizeAllowed()){
9898
unsigned long long Proposed_Height = INTERNAL::Max(Child_Needs_Minimum_Height_Of, getHeight());
9999
unsigned long long Proposed_Width = INTERNAL::Max(Last_Child->getPosition().x + Child_Needs_Minimum_Width_Of - Width_Modifier, getWidth());
@@ -110,7 +110,7 @@ void GGUI::listView::addChild(element* e) {
110110
Last_Child->setDimensions(e->getWidth(), e->getHeight());
111111
} else {
112112
// Adjust for minimum height needed when borders are present.
113-
signed int Height_Modifier = e->hasBorder() & Last_Child->hasBorder();
113+
signed int Height_Modifier = e->hasBorder() && Last_Child->hasBorder();
114114
if (isDynamicSizeAllowed()){
115115
unsigned long long Proposed_Width = INTERNAL::Max(Child_Needs_Minimum_Width_Of, getWidth());
116116
unsigned long long Proposed_Height = INTERNAL::Max(Last_Child->getPosition().y + Child_Needs_Minimum_Height_Of - Height_Modifier, getHeight());
@@ -166,7 +166,7 @@ void GGUI::listView::calculateChildsHitboxes(size_t Starting_Offset){
166166
element* Next = Style->Childs[i];
167167

168168
// Affect minimum width needed, when current child has borders as well as the previous one.
169-
int Width_Modifier = Next->hasBorder() & Current->hasBorder();
169+
int Width_Modifier = Next->hasBorder() && Current->hasBorder();
170170

171171
Next->setPosition({Current->getPosition().x + Current->getWidth() - Width_Modifier, Next->getPosition().y, Next->getPosition().z});
172172

@@ -181,7 +181,7 @@ void GGUI::listView::calculateChildsHitboxes(size_t Starting_Offset){
181181
element* Next = Style->Childs[i];
182182

183183
// Affect minimum height needed, when current child has borders as well as the previous one.
184-
int Height_Modifier = Next->hasBorder() & Current->hasBorder();
184+
int Height_Modifier = Next->hasBorder() && Current->hasBorder();
185185

186186
Next->setPosition({Next->getPosition().x, Current->getPosition().y + Current->getHeight() - Height_Modifier, Next->getPosition().z});
187187

0 commit comments

Comments
 (0)