Add compile-time configuration for build settings

This commit is contained in:
2025-05-26 22:38:04 +02:00
parent a1db1cd9e2
commit b8a87223bb
7 changed files with 70 additions and 17 deletions

17
asl/BUILD.bazel Normal file
View File

@ -0,0 +1,17 @@
# Copyright 2025 Steven Le Rouzic
#
# SPDX-License-Identifier: BSD-3-Clause
config_setting(
name = "debug",
values = {
"compilation_mode": "dbg",
},
)
config_setting(
name = "optimized",
values = {
"compilation_mode": "opt",
},
)

View File

@ -24,6 +24,13 @@ cc_library(
srcs = [
"assert.cpp",
],
defines = select({
"//asl:debug": ["ASL_DEBUG=1"],
"//conditions:default": ["ASL_DEBUG=0"],
}) + select({
"//asl:optimized": ["ASL_OPTIMIZED=1"],
"//conditions:default": ["ASL_OPTIMIZED=0"],
}),
visibility = ["//visibility:public"],
)

View File

@ -24,8 +24,7 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l
#define ASL_DEBUG_BREAK() __builtin_debugtrap()
#endif
// @Todo Configure asserts at build time
#if !ASL_OPTIMIZED
#define ASL_ASSERT(...) \
if (__VA_ARGS__) {} \
else \
@ -33,6 +32,9 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l
::asl::report_assert_failure(#__VA_ARGS__); \
ASL_DEBUG_BREAK(); \
}
#else
#define ASL_ASSERT(...)
#endif
#define ASL_ASSERT_RELEASE(...) \
if (__VA_ARGS__) {} \

View File

@ -114,7 +114,7 @@ constexpr T rotl(T v, int s) // NOLINT(*-no-recursion)
{
static constexpr int N = sizeof(decltype(v)) * 8;
s = s % N;
return (s >= 0) ? (v << s) | (v >> (N - s)) : rotr(v, -s);
return (s >= 0) ? (v << s) | (v >> ((N - s) % N)) : rotr(v, -s);
}
template<is_unsigned_integer T>
@ -122,7 +122,7 @@ constexpr T rotr(T v, int s) // NOLINT(*-no-recursion)
{
static constexpr int N = sizeof(decltype(v)) * 8;
s = s % N;
return (s >= 0) ? (v >> s) | (v << (N - s)) : rotl(v, -s);
return (s >= 0) ? (v >> s) | (v << ((N - s) % N)) : rotl(v, -s);
}
constexpr uint16_t byteswap(uint16_t v)

View File

@ -22,5 +22,15 @@
#error Unknown compiler
#endif
// ASL_DEBUG=1 for slow builds, with extra validation logic and such.
#if !defined(ASL_DEBUG)
#error ASL_DEBUG should be defined to 0 or 1
#endif
// ASL_OPTIMIZED=1 for fast builds, with minimal validation logic.
#if !defined(ASL_OPTIMIZED)
#error ASL_OPTIMIZED should be defined to 0 or 1
#endif
// NOLINTEND(*-macro-to-enum)

View File

@ -87,9 +87,26 @@ void log(level l, const source_location& sl, string_view fmt, const Args&... arg
} // namespace asl::log
// @Todo Compile-time configuration of logging
#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 4
#define ASL_LOG_DEBUG(...) ::asl::log::log(::asl::log::kDebug, ::asl::source_location{}, __VA_ARGS__)
#else
#define ASL_LOG_DEBUG(...)
#endif
#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 3
#define ASL_LOG_INFO(...) ::asl::log::log(::asl::log::kInfo, ::asl::source_location{}, __VA_ARGS__)
#else
#define ASL_LOG_DEBUG(...)
#endif
#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 2
#define ASL_LOG_WARNING(...) ::asl::log::log(::asl::log::kWarning, ::asl::source_location{}, __VA_ARGS__)
#else
#define ASL_LOG_DEBUG(...)
#endif
#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 1
#define ASL_LOG_ERROR(...) ::asl::log::log(::asl::log::kError, ::asl::source_location{}, __VA_ARGS__)
#else
#define ASL_LOG_DEBUG(...)
#endif

View File

@ -68,7 +68,7 @@ public:
, m_size{size}
{}
constexpr explicit span(T* data, isize_t size)
constexpr explicit span(T* data, [[maybe_unused]] isize_t size)
requires (!kIsDynamic)
: m_data{data}
{