277 lines
12 KiB
TOML
277 lines
12 KiB
TOML
# ================================================================================================
|
||
# FastLED Unit Test Build Flags Configuration
|
||
# ================================================================================================
|
||
#
|
||
# This file centralizes ALL compilation flags used by unit test compilation to ensure
|
||
# they remain synchronized and compatible across the entire build system.
|
||
#
|
||
# Unit tests require special flags like FASTLED_FORCE_NAMESPACE=1 to put all symbols
|
||
# in the fl:: namespace that the tests expect.
|
||
|
||
[tools]
|
||
# Build tool configuration - Full compiler command with arguments
|
||
# CRITICAL: Must use 'uv run python' for subprocess execution (subprocess doesn't inherit uv environment)
|
||
cpp_compiler = ["uv", "run", "python", "-m", "ziglang", "c++"]
|
||
linker = ["uv", "run", "python", "-m", "ziglang", "c++"] # Separate linker config for consistency
|
||
archiver = ["uv", "run", "python", "-m", "ziglang", "ar"] # Ziglang archiver for unified toolchain
|
||
c_compiler = ["uv", "run", "python", "-m", "ziglang", "cc"]
|
||
objcopy = ["uv", "run", "python", "-m", "ziglang", "objcopy"]
|
||
nm = ["uv", "run", "python", "-m", "ziglang", "nm"]
|
||
strip = ["uv", "run", "python", "-m", "ziglang", "strip"]
|
||
ranlib = ["uv", "run", "python", "-m", "ziglang", "ranlib"]
|
||
|
||
[all]
|
||
# Universal compilation flags (compiler command handled separately)
|
||
compiler_flags = [
|
||
"-std=gnu++17",
|
||
"-fpermissive",
|
||
"-Wall",
|
||
"-Wextra",
|
||
"-Wno-deprecated-register", # Suppress 'register' keyword warnings for C++17 compatibility
|
||
"-Wno-backslash-newline-escape", # Suppress backslash newline escape warnings
|
||
"-fno-exceptions",
|
||
"-fno-rtti",
|
||
]
|
||
|
||
defines = [
|
||
"STUB_PLATFORM",
|
||
"FASTLED_UNIT_TEST=1",
|
||
"FASTLED_FORCE_NAMESPACE=1", # CRITICAL: Required for unit tests to access fl:: namespace
|
||
"FASTLED_TESTING=1", # Enable test-specific functionality like MockTimeProvider
|
||
]
|
||
|
||
include_flags = [
|
||
"-I.",
|
||
"-Isrc",
|
||
"-Itests",
|
||
]
|
||
|
||
[windows]
|
||
# ================================================================================================
|
||
# WINDOWS-SPECIFIC BUILD FLAGS
|
||
# ================================================================================================
|
||
# Comprehensive Windows build configuration using Zig's bundled Clang with GNU target
|
||
|
||
# C compiler flags for Windows
|
||
cc_flags = [
|
||
"--target=x86_64-windows-gnu", # Explicit target for MSYS2/MinGW compatibility
|
||
"-fuse-ld=lld", # Use Zig's bundled LLD linker
|
||
"-std=c17", # C17 standard
|
||
"-Wall",
|
||
"-Wextra",
|
||
]
|
||
|
||
# C++ compiler flags for Windows
|
||
cpp_flags = [
|
||
"--target=x86_64-windows-gnu", # Explicit target for MSYS2/MinGW compatibility
|
||
"-fuse-ld=lld-link", # Use lld-link (Windows MSVC-compatible linker)
|
||
"-std=c++17", # C++17 standard
|
||
"-Wall",
|
||
"-Wextra",
|
||
"-fno-exceptions",
|
||
"-fno-rtti",
|
||
|
||
# Fix Arduino INPUT macro conflict with Windows headers
|
||
"-DNOMINMAX", # Prevent Windows min/max macros
|
||
"-DWIN32_LEAN_AND_MEAN", # Reduce Windows header conflicts
|
||
]
|
||
|
||
# Linker flags for Windows
|
||
link_flags = [
|
||
"-mconsole", # Console application
|
||
|
||
# Prevent automatic library inclusion to avoid CRT collisions
|
||
"-nodefaultlibs", # Don't automatically include default libraries
|
||
|
||
# Fix CRT collision between Zig/Clang and MSYS2/MinGW runtimes
|
||
# This prevents "atexit was replaced" errors from conflicting CRT implementations
|
||
# "-rtlib=compiler-rt", # Removed - was causing conflicts
|
||
"-unwindlib=libunwind", # Use Clang's libunwind (avoid MinGW unwind)
|
||
"-nostdlib++", # Don't auto-link standard C++ library
|
||
"-lc++", # Manually link libc++ (Clang's C++ standard library)
|
||
|
||
"-lkernel32", # Windows kernel functions
|
||
"-luser32", # Windows user interface
|
||
"-lgdi32", # Graphics device interface
|
||
"-ladvapi32", # Advanced Windows API
|
||
]
|
||
|
||
[linking.base]
|
||
# Base linking flags (Unix-like systems)
|
||
flags = [
|
||
"-pthread", # POSIX threads (not used on Windows)
|
||
]
|
||
|
||
[linux]
|
||
# Linux-specific build configuration – libunwind disabled (fallback to execinfo)
|
||
link_flags = [
|
||
]
|
||
|
||
defines = [
|
||
]
|
||
|
||
[build_modes.quick]
|
||
flags = [
|
||
"-O1",
|
||
"-fno-inline-functions",
|
||
"-fno-vectorize",
|
||
"-fno-unroll-loops",
|
||
"-fno-strict-aliasing",
|
||
"-fno-omit-frame-pointer", # Preserve stack frames for debugging
|
||
]
|
||
|
||
link_flags = []
|
||
|
||
[build_modes.debug_asan]
|
||
# AddressSanitizer and UndefinedBehaviorSanitizer for debugging memory issues
|
||
flags = [
|
||
"-fsanitize=address", # AddressSanitizer for memory error detection
|
||
"-fsanitize=undefined", # UndefinedBehaviorSanitizer for undefined behavior
|
||
"-O1", # Light optimization for performance
|
||
"-fno-omit-frame-pointer", # Preserve stack frames for better debugging
|
||
"-fno-optimize-sibling-calls", # Better stack traces
|
||
]
|
||
|
||
link_flags = [
|
||
"-fsanitize=address",
|
||
"-fsanitize=undefined",
|
||
]
|
||
|
||
[strict_mode]
|
||
flags = [
|
||
"-Werror",
|
||
"-Wextra",
|
||
"-Wconversion",
|
||
"-Wsign-conversion",
|
||
"-Werror=unused-variable", # Force error on unused variables
|
||
"-Werror=unused-parameter", # Force error on unused parameters
|
||
"-Werror=unused-function", # Force error on unused functions
|
||
"-Werror=unused-but-set-variable", # Force error on variables that are set but never used
|
||
"-Wuninitialized",
|
||
"-Wdouble-promotion",
|
||
"-Wformat=2",
|
||
"-Wcast-align",
|
||
"-Wcast-qual",
|
||
"-Werror=return-type",
|
||
]
|
||
|
||
[test]
|
||
# Test-specific preprocessor defines
|
||
defines = [
|
||
# FastLED Test Configuration
|
||
"-DFASTLED_UNIT_TEST=1", # Identify as unit test build
|
||
"-DFASTLED_FORCE_NAMESPACE=1", # Force namespace usage to avoid conflicts
|
||
"-DFASTLED_USE_PROGMEM=0", # Disable PROGMEM usage in tests
|
||
"-DSTUB_PLATFORM", # Use stub platform for testing
|
||
"-DARDUINO=10808", # Arduino version compatibility
|
||
"-DFASTLED_USE_STUB_ARDUINO", # Use stub Arduino implementation
|
||
"-DSKETCH_HAS_LOTS_OF_MEMORY=1", # Assume lots of memory available
|
||
"-DFASTLED_STUB_IMPL", # Use stub implementations
|
||
"-DFASTLED_USE_JSON_UI=1", # Enable JSON UI features
|
||
"-DFASTLED_TESTING", # Enable testing features
|
||
"-DFASTLED_NO_AUTO_NAMESPACE", # Disable automatic namespace
|
||
"-DFASTLED_NO_PINMAP", # Disable pin mapping
|
||
"-DHAS_HARDWARE_PIN_SUPPORT", # Enable hardware pin support
|
||
"-DFASTLED_DEBUG_LEVEL=1", # Set debug level
|
||
"-DFASTLED_NO_ATEXIT=1", # Disable atexit to fix Windows lld-link errors
|
||
"-DDOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS", # Doctest configuration
|
||
"-DENABLE_CRASH_HANDLER", # Enable global crash handler in tests
|
||
]
|
||
|
||
# Test-specific compiler flags
|
||
compiler_flags = [
|
||
# Language Standard and Compatibility
|
||
"-std=c++17", # Base C++17 standard
|
||
"-std=gnu++17", # Use GNU C++17 standard with extensions
|
||
"-fpermissive", # Allow some non-conforming code patterns
|
||
|
||
# Warning Configuration
|
||
"-Wall", # Enable all warnings
|
||
"-Wextra", # Enable extra warnings
|
||
"-Werror=return-type", # Error on missing return statements
|
||
|
||
# Debug and Crash Handling
|
||
"-fno-omit-frame-pointer", # Preserve stack frames for debugging
|
||
|
||
# AddressSanitizer and Memory Debugging
|
||
"-fsanitize=address", # AddressSanitizer for memory error detection
|
||
"-fsanitize=undefined", # UndefinedBehaviorSanitizer for undefined behavior
|
||
|
||
# Thread Safety and Runtime Behavior
|
||
"-fno-threadsafe-statics", # Disable thread-safe static initialization
|
||
"-fno-exceptions", # Disable C++ exceptions
|
||
"-fno-rtti", # Disable RTTI
|
||
|
||
# PCH Support
|
||
"-fpch-instantiate-templates", # Required for proper PCH template handling
|
||
]
|
||
|
||
# Test-specific include flags
|
||
include_flags = [
|
||
"-I.", # Current directory
|
||
"-Isrc", # FastLED source directory
|
||
"-Itests", # Test directory
|
||
]
|
||
|
||
# Test-specific linking flags for AddressSanitizer and libunwind
|
||
link_flags = [
|
||
"-fsanitize=address", # Link AddressSanitizer runtime
|
||
"-fsanitize=undefined", # Link UndefinedBehaviorSanitizer runtime
|
||
"-lunwind", # Link libunwind for stack traces
|
||
"-lunwind-x86_64", # Platform-specific libunwind functions
|
||
]
|
||
|
||
[archive]
|
||
# ================================================================================================
|
||
# ARCHIVE CREATION FLAGS
|
||
# ================================================================================================
|
||
# Flags for creating static libraries (.a files) with deterministic builds.
|
||
# Using Zig's unified toolchain (ziglang ar) which supports deterministic builds on all platforms.
|
||
|
||
flags = "rcsD" # r=insert, c=create if needed, s=write symbol table, D=deterministic (zero timestamps)
|
||
|
||
[stub_platform]
|
||
# ================================================================================================
|
||
# STUB PLATFORM DEFINES FOR UNIT TEST COMPILATION
|
||
# ================================================================================================
|
||
# These defines are used when unit tests need to compile example code on the STUB platform
|
||
# which provides Arduino-compatible functionality without hardware dependencies.
|
||
|
||
defines = [
|
||
"STUB_PLATFORM", # Enable STUB platform
|
||
"ARDUINO=10808", # Arduino version compatibility
|
||
"FASTLED_USE_STUB_ARDUINO", # Use stub Arduino implementation
|
||
"FASTLED_STUB_IMPL", # Enable STUB platform Arduino function implementations
|
||
"SKETCH_HAS_LOTS_OF_MEMORY=1", # Enable memory-intensive features for STUB platform
|
||
"FASTLED_HAS_ENGINE_EVENTS=1", # Enable EngineEvents for UI components
|
||
"FASTLED_UNIT_TEST=1", # Identify as unit test build
|
||
"FASTLED_FORCE_NAMESPACE=1", # Force namespace usage for unit tests
|
||
"FASTLED_TESTING=1", # Enable testing features
|
||
]
|
||
|
||
# Include paths required for stub platform compilation in unit tests
|
||
include_paths = [
|
||
"src/platforms/stub", # Arduino.h stub for examples
|
||
]
|
||
|
||
# Additional compiler arguments for stub platform
|
||
compiler_args = [
|
||
# No additional args currently needed - all flags come from [all] and other sections
|
||
]
|
||
|
||
[linking.unix]
|
||
# ================================================================================================
|
||
# UNIX-SPECIFIC LINKING FLAGS
|
||
# ================================================================================================
|
||
# Linking flags specific to Unix-like systems (Linux, macOS).
|
||
|
||
flags = [
|
||
# Core Libraries
|
||
"-pthread", # POSIX threads support
|
||
"-lm", # Math library
|
||
"-ldl", # Dynamic loading library
|
||
|
||
# Platform-specific libraries (added as needed)
|
||
# Note: Additional platform-specific flags can be added here
|
||
]
|