From 9337d8bc3cde964ba804274fd6d09173c416614f Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 28 Oct 2024 22:21:23 +0100 Subject: Some more work on cross-platform configuration --- asl/BUILD.bazel | 1 + asl/annotations.hpp | 9 ++++----- asl/assert.hpp | 11 +++++++++-- asl/config.hpp | 17 +++++++++++++++++ asl/integers.hpp | 16 ++++++++++++---- 5 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 asl/config.hpp (limited to 'asl') diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel index f7dddd1..ed26459 100644 --- a/asl/BUILD.bazel +++ b/asl/BUILD.bazel @@ -3,6 +3,7 @@ cc_library( hdrs = [ "annotations.hpp", "assert.hpp", + "config.hpp", "format.hpp", "integers.hpp", "io.hpp", diff --git a/asl/annotations.hpp b/asl/annotations.hpp index 90e603f..a398e13 100644 --- a/asl/annotations.hpp +++ b/asl/annotations.hpp @@ -1,11 +1,10 @@ #pragma once -#ifndef __clang__ - #error Not a valid environment -#endif +#include "asl/config.hpp" + -#ifdef _MSC_VER +#if ASL_COMPILER_CLANG_CL #define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#else +#elif ASL_COMPILER_CLANG #define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]] #endif diff --git a/asl/assert.hpp b/asl/assert.hpp index d419c24..2322a5b 100644 --- a/asl/assert.hpp +++ b/asl/assert.hpp @@ -1,6 +1,13 @@ #pragma once -// @Todo Make this portable-ish +#include "asl/config.hpp" + +#if ASL_COMPILER_CLANG_CL + #define ASL_DEBUG_BREAK() __debugbreak() +#elif ASL_COMPILER_CLANG + #define ASL_DEBUG_BREAK() __builtin_debug_trap() +#endif + #define ASL_ASSERT(...) \ if (__VA_ARGS__) {} \ - else { __builtin_debugtrap(); } + else { ASL_DEBUG_BREAK(); } diff --git a/asl/config.hpp b/asl/config.hpp new file mode 100644 index 0000000..1e28252 --- /dev/null +++ b/asl/config.hpp @@ -0,0 +1,17 @@ +#pragma once + +#if defined(_WIN32) + #define ASL_OS_WINDOWS 1 +#elif defined(__linux__) + #define ASL_OS_LINUX 1 +#else + #error Unknown OS +#endif + +#if defined(__clang__) && defined(_MSC_VER) + #define ASL_COMPILER_CLANG_CL 1 +#elif defined(__clang__) + #define ASL_COMPILER_CLANG 1 +#else + #error Unknown compiler +#endif diff --git a/asl/integers.hpp b/asl/integers.hpp index 716b981..8b7488f 100644 --- a/asl/integers.hpp +++ b/asl/integers.hpp @@ -1,16 +1,24 @@ #pragma once +#include "asl/config.hpp" + using int8_t = signed char; using int16_t = signed short; using int32_t = signed int; -using int64_t = signed long; - -// @Todo Proper type definition for Windows/Linux +#if ASL_OS_WINDOWS + using int64_t = signed long long; +#elif ASL_OS_LINUX + using int64_t = signed long; +#endif using uint8_t = unsigned char; using uint16_t = unsigned short; using uint32_t = unsigned int; -using uint64_t = unsigned long; +#if ASL_OS_WINDOWS + using uint64_t = unsigned long long; +#elif ASL_OS_LINUX + using uint64_t = unsigned long; +#endif using size_t = uint64_t; using isize_t = int64_t; -- cgit