5 Commits

Author SHA1 Message Date
abdelrahman c0d901d7e9 Build and run C++ tests on MSVC 2025-12-15 23:40:30 +00:00
abdelrahman 31727dd6e7 Update va_arg_count C++ utility to support MSVC 2025-12-15 23:40:03 +00:00
abdelrahman af56a5be3f Reformat 2025-12-15 21:51:46 +00:00
abdelrahman e16abc2459 Fix MSVC errors 2025-12-15 21:48:30 +00:00
abdelrahman 05b7cfbbea Confirm WAPP_PLATFORM_C is defined before checking version 2025-12-15 21:17:10 +00:00
7 changed files with 43 additions and 38 deletions
+28 -16
View File
@@ -3,9 +3,12 @@ Param(
)
$Compiler = "cl.exe"
$Linker = "lib.exe"
$GeneralFlags = "/Wall /WX /wd4996 /wd4464 /wd5105 /std:c11"
$LibraryFlags = "/LD"
$GeneralFlags = "/Wall /WX /wd4996 /wd4464 /wd5105 /EHs"
$CStd = "/std:c11"
$CppStd = "/std:c++14"
$LibraryFlags = "/c"
$Kernel = (Get-ChildItem Env:OS).Value
$Machine = (Get-ChildItem Env:PROCESSOR_ARCHITECTURE).Value
@@ -15,14 +18,15 @@ $IncludeDirs = "/I src"
$SrcFiles = "src/wapp.c"
$TestIncludeDirs = Get-ChildItem -Path tests -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
$TestSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
$TestCSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.c -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
$TestCppSrcFiles = Get-ChildItem -Path tests -Recurse -Filter *.cc -ErrorAction SilentlyContinue -Force | %{$('"' + $_.FullName + '"')}
If ($Release -eq $True) {
$GeneralFlags += " /O2 /Og"
$BuildType = "release"
$BuildType = "Release"
} Else {
$GeneralFlags += " /Zi /Od /fsanitize=address"
$BuildType = "debug"
$BuildType = "Debug"
}
$BuildDir = "./libwapp-build/${Platform}-${BuildType}"
@@ -30,12 +34,15 @@ $ObjDir = "$BuildDir/objects"
$OutDir = "$BuildDir/output"
$TestsDir = "$BuildDir/tests"
$OutBasename = "libwapp"
$LibOutput = "$OutDir/libwapp.lib"
$Objects = "/Fo:$ObjDir/"
$Outputs = "/Fd:$OutDir/$OutBasename /Fe:$OutDir/$OutBasename"
$LibOutputFlags = "/OUT:$LibOutput"
$TestOutBasename = "wapptest"
$TestOutputs = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestOutBasename"
$TestCOutputBasename = "wapptest"
$TestCOutputFlags = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestCOutputBasename"
$TestCppOutputBasename = "wapptestcc"
$TestCppOutputFlags = "/Fo:$TestsDir/ /Fe:$TestsDir/$TestCppOutputBasename"
If (Test-Path $BuildDir) {
Remove-Item $BuildDir -Recurse -Force
@@ -48,18 +55,23 @@ mkdir -p $TestsDir > $null
# Run code generation
Invoke-Expression "python -m codegen"
# Build and run tests
Invoke-Expression "$Compiler $GeneralFlags $IncludeDirs $TestIncludeDirs $SrcFiles $TestSrcFiles $TestOutputs" -ErrorAction Stop
# Build and run C tests
Invoke-Expression "$Compiler $GeneralFlags $CStd $IncludeDirs $TestIncludeDirs $SrcFiles $TestCSrcFiles $TestCOutputFlags" -ErrorAction Stop
Invoke-Expression "$TestsDir/$TestCOutputBasename.exe"
Invoke-Expression "$TestsDir/$TestOutBasename.exe"
$Status = $LASTEXITCODE
Remove-Item $TestsDir -Recurse -Force
If ($Status -ne 0) {
Remove-Item $TestsDir -Recurse -Force
Write-Error "Tests failed"
Exit 1
}
# Build library
Invoke-Expression "$Compiler $GeneralFlags $LibraryFlags $SrcFiles $Objects $Outputs"
Invoke-Expression "$Compiler $GeneralFlags $CStd $LibraryFlags $SrcFiles $Objects"
Invoke-Expression "$Linker $ObjDir/*.obj $LibOutputFlags"
# Build and run C++ tests
Invoke-Expression "$Compiler $GeneralFlags $CppStd $IncludeDirs $TestIncludeDirs $LibOutput $TestCppSrcFiles $TestCppOutputFlags" -ErrorAction Stop
Invoke-Expression "$TestsDir/$TestCppOutputBasename.exe"
Remove-Item $TestsDir -Recurse -Force
+2 -2
View File
@@ -6,7 +6,7 @@
#include "../platform/platform.h"
#include <stdint.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE)
#if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE)
#include <uchar.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION
@@ -21,7 +21,7 @@
#define c8 uint8_t
#define c16 uint16_t
#define c32 uint32_t
#endif // !WAPP_PLATFORM_C11_VERSION
#endif // !WAPP_PLATFORM_C
#define u8 uint8_t
#define u16 uint16_t
+5 -10
View File
@@ -39,18 +39,13 @@ BEGIN_C_LINKAGE
)
#ifdef WAPP_PLATFORM_CPP
#define wapp_misc_utils_va_args_count(T, ...) va_args_count<T>(__VA_ARGS__)
END_C_LINKAGE
#include <tuple>
#define wapp_misc_utils_va_args_count(T, ...) (std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value)
#else
#define wapp_misc_utils_va_args_count(T, ...) (sizeof((T[]){__VA_ARGS__})/sizeof(T))
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
template <typename T, typename... Args>
constexpr u64 va_args_count(Args&&...) {
return sizeof...(Args);
}
#endif // !WAPP_PLATFORM_CPP
#endif // !MISC_UTILS_H
+1 -3
View File
@@ -9,9 +9,7 @@
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_CPP
#define wapp_tester_result(PASSED) (TestFuncResult{wapp_str8_lit_ro(__func__), PASSED})
#else
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
@@ -21,7 +19,7 @@ BEGIN_C_LINKAGE
typedef struct test_func_result TestFuncResult;
struct test_func_result {
Str8RO name;
Str8 name;
b8 passed;
#ifdef WAPP_PLATFORM_WINDOWS
+1 -1
View File
@@ -173,7 +173,7 @@ TestFuncResult test_i32_array_append_alloc(void) {
u64 index = 0;
b8 running = true;
while (running) {
i32 num = (i32)index;
num = (i32)index;
arr_ptr = wapp_array_append_alloc(i32, I32Array, &allocator, &array2, &num);
++index;
+4 -4
View File
@@ -19,11 +19,11 @@ TestFuncResult test_str8_array(void) {
u64 index = 0;
b8 running = true;
while (running) {
item = wapp_array_get(Str8, &array, index);
result = result && item && (wapp_str8_equal(item, &expected[index]));
item = wapp_array_get(Str8, &array, index);
result = result && item && (wapp_str8_equal(item, &expected[index]));
++index;
running = index < count;
++index;
running = index < count;
}
return wapp_tester_result(result);
+2 -2
View File
@@ -262,8 +262,8 @@ TestFuncResult test_str8_equal(void) {
Str8RO s4 = wapp_str8_lit_ro("goodbye");
result = wapp_str8_equal(&s1, &s2) == false;
result = result && wapp_str8_equal(&s1, &s3) == true;
result = result && wapp_str8_equal(&s1, &s4) == false;
result = result && wapp_str8_equal(&s1, &s3) == (b8)true;
result = result && wapp_str8_equal(&s1, &s4) == (b8)false;
return wapp_tester_result(result);
}