Fix memory issues because of pointer to item in dynamic array, add clang-cl, add address sanitizer stuff

This commit is contained in:
Krzosa Karol
2024-08-05 10:44:00 +02:00
parent 10f0d7dca2
commit 55465ad6de
14 changed files with 141 additions and 104 deletions

View File

@@ -4,16 +4,27 @@ enum {
PROFILE_DEBUG,
PROFILE_RELEASE,
};
int Profile = PROFILE_DEBUG;
int Profile = PROFILE_DEBUG;
S8_String Compiler = "cl.exe";
void AddCommonFlags(Array<S8_String> *cmd) {
cmd->add("/MP /Zi /FC /nologo");
if (Compiler == "cl.exe") {
cmd->add("/MP");
}
cmd->add("/Zi /FC /nologo");
cmd->add("/WX /W3 /wd4200 /diagnostics:column");
if (Compiler == "clang-cl.exe") {
cmd->add("-fdiagnostics-absolute-paths");
cmd->add("-Wno-missing-braces");
cmd->add("-Wno-writable-strings");
cmd->add("-Wno-unused-function");
}
cmd->add("/Oi");
cmd->add("-D_CRT_SECURE_NO_WARNINGS");
if (Profile == PROFILE_DEBUG) {
cmd->add("-DDEBUG_BUILD=1");
cmd->add("-DRELEASE_BUILD=0");
cmd->add("-fsanitize=address");
// cmd->add("-D_DEBUG /MDd");
} else {
cmd->add("-DDEBUG_BUILD=0");
@@ -87,7 +98,8 @@ Library PrepareLua() {
if (!OS_FileExists(l.objects[0])) {
Array<S8_String> cmd = {};
cmd.add("cl.exe -c");
cmd.add(Compiler);
cmd.add("-c");
AddCommonFlags(&cmd);
For(l.include_paths) cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(it)));
cmd += l.sources;
@@ -103,7 +115,8 @@ Library PrepareGlad() {
l.objects.add("glad.obj");
if (!OS_FileExists(l.objects[0])) {
Array<S8_String> cmd = {};
cmd.add("cl.exe -c");
cmd.add(Compiler);
cmd.add("-c");
AddCommonFlags(&cmd);
For(l.include_paths) cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(it)));
cmd += l.sources;
@@ -121,7 +134,7 @@ int CompileTextEditor() {
libs.add(PrepareGlad());
Array<S8_String> cmd = {};
cmd.add("cl.exe");
cmd.add(Compiler);
cmd.add("-Fe:te.exe");
cmd.add("-Fd:te.pdb");
cmd.add("-I ../src");
@@ -147,39 +160,6 @@ int CompileTextEditor() {
return result;
}
int CompileNewPlatform() {
int result = 0;
Array<Library> libs = {};
libs.add(PrepareGlad());
libs.add(PrepareLua());
libs.add(PrepareSDLDynamic());
Array<S8_String> cmd = {};
cmd.add("cl.exe");
cmd.add("-Fe:te.exe");
cmd.add("-Fd:te.pdb");
cmd.add("-I ../src");
AddCommonFlags(&cmd);
For2(lib, libs) For(lib.defines) cmd.add(it);
cmd.add("../src/platform/platform.cpp");
cmd.add("../src/basic/win32.cpp");
For2(lib, libs) For(lib.include_paths) cmd.add(Fmt("-I %.*s", S8_Expand(it)));
cmd.add("/link");
cmd.add("/incremental:no");
For2(lib, libs) For(lib.link) cmd.add(it);
For(libs) For2(o, it.objects) cmd.add(o);
OS_DeleteFile("te.pdb");
// For(cmd) IO_Printf("%.*s\n", S8_Expand(it));
result += Run(cmd);
return result;
}
char *C(const char *value) {
if (value[0] == '0' && value[1] == 'x') {
S8_String f = Fmt("{0x%.*s, 0x%.*s, 0x%.*s, 0x%.*s}", 2, value + 2, 2, value + 4, 2, value + 6, 2, value + 8);