Add compile-time configuration for build settings
This commit is contained in:
17
asl/BUILD.bazel
Normal file
17
asl/BUILD.bazel
Normal 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",
|
||||||
|
},
|
||||||
|
)
|
@ -24,6 +24,13 @@ cc_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"assert.cpp",
|
"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"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,15 +24,17 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l
|
|||||||
#define ASL_DEBUG_BREAK() __builtin_debugtrap()
|
#define ASL_DEBUG_BREAK() __builtin_debugtrap()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @Todo Configure asserts at build time
|
#if !ASL_OPTIMIZED
|
||||||
|
#define ASL_ASSERT(...) \
|
||||||
#define ASL_ASSERT(...) \
|
|
||||||
if (__VA_ARGS__) {} \
|
if (__VA_ARGS__) {} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
::asl::report_assert_failure(#__VA_ARGS__); \
|
::asl::report_assert_failure(#__VA_ARGS__); \
|
||||||
ASL_DEBUG_BREAK(); \
|
ASL_DEBUG_BREAK(); \
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define ASL_ASSERT(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ASL_ASSERT_RELEASE(...) \
|
#define ASL_ASSERT_RELEASE(...) \
|
||||||
if (__VA_ARGS__) {} \
|
if (__VA_ARGS__) {} \
|
||||||
|
@ -114,7 +114,7 @@ constexpr T rotl(T v, int s) // NOLINT(*-no-recursion)
|
|||||||
{
|
{
|
||||||
static constexpr int N = sizeof(decltype(v)) * 8;
|
static constexpr int N = sizeof(decltype(v)) * 8;
|
||||||
s = s % N;
|
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>
|
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;
|
static constexpr int N = sizeof(decltype(v)) * 8;
|
||||||
s = s % N;
|
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)
|
constexpr uint16_t byteswap(uint16_t v)
|
||||||
|
@ -22,5 +22,15 @@
|
|||||||
#error Unknown compiler
|
#error Unknown compiler
|
||||||
#endif
|
#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)
|
// NOLINTEND(*-macro-to-enum)
|
||||||
|
|
||||||
|
@ -87,9 +87,26 @@ void log(level l, const source_location& sl, string_view fmt, const Args&... arg
|
|||||||
|
|
||||||
} // namespace asl::log
|
} // 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
|
||||||
|
|
||||||
#define ASL_LOG_DEBUG(...) ::asl::log::log(::asl::log::kDebug, ::asl::source_location{}, __VA_ARGS__)
|
#if !defined(ASL_LOG_LEVEL) || ASL_LOG_LEVEL >= 3
|
||||||
#define ASL_LOG_INFO(...) ::asl::log::log(::asl::log::kInfo, ::asl::source_location{}, __VA_ARGS__)
|
#define ASL_LOG_INFO(...) ::asl::log::log(::asl::log::kInfo, ::asl::source_location{}, __VA_ARGS__)
|
||||||
#define ASL_LOG_WARNING(...) ::asl::log::log(::asl::log::kWarning, ::asl::source_location{}, __VA_ARGS__)
|
#else
|
||||||
#define ASL_LOG_ERROR(...) ::asl::log::log(::asl::log::kError, ::asl::source_location{}, __VA_ARGS__)
|
#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
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
, m_size{size}
|
, m_size{size}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
constexpr explicit span(T* data, isize_t size)
|
constexpr explicit span(T* data, [[maybe_unused]] isize_t size)
|
||||||
requires (!kIsDynamic)
|
requires (!kIsDynamic)
|
||||||
: m_data{data}
|
: m_data{data}
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user