1616#include " logger.hpp"
1717#include " muuk.hpp"
1818#include " muuk_parser.hpp"
19+ #include " opt_level.hpp"
1920#include " rustify.hpp"
2021#include " util.hpp"
2122
@@ -41,7 +42,7 @@ namespace muuk {
4142 if (!profile_table.contains (profile))
4243 return Err (" Profile '{}' does not exist in the configuration." , profile);
4344
44- auto profile_entry = profile_table.at (profile). as_table () ;
45+ auto profile_entry = profile_table.at (profile);
4546
4647 BuildProfile build_profile;
4748 build_profile.cflags = muuk::parse_array_as_vec (profile_entry, " cflags" );
@@ -54,6 +55,87 @@ namespace muuk {
5455 muuk::normalize_flags_inplace (build_profile.lflags , compiler);
5556 muuk::normalize_flags_inplace (build_profile.defines , compiler);
5657
58+ // --- Link Type Optimization ---
59+ if (profile_entry.at (" lto" ).as_boolean ()) {
60+ muuk::logger::info (" LTO enabled for profile '{}'" , profile);
61+ switch (compiler.getType ()) {
62+ case Compiler::Type::GCC:
63+ case Compiler::Type::Clang:
64+ build_profile.cflags .push_back (" -flto" );
65+ build_profile.lflags .push_back (" -flto" );
66+ case Compiler::Type::MSVC:
67+ build_profile.cflags .push_back (" /GL" );
68+ build_profile.lflags .push_back (" /LTCG" );
69+ }
70+ }
71+
72+ // --- Debug ---
73+ if (profile_entry.at (" debug" ).as_boolean ()) {
74+ muuk::logger::info (" LTO enabled for profile '{}'" , profile);
75+ switch (compiler.getType ()) {
76+ case Compiler::Type::GCC:
77+ case Compiler::Type::Clang:
78+ build_profile.cflags .push_back (" -g" );
79+ case Compiler::Type::MSVC:
80+ build_profile.cflags .push_back (" /Zi" );
81+ build_profile.lflags .push_back (" /DEBUG" );
82+ }
83+ }
84+
85+ // --- Debug Assertions ---
86+ if (!profile_entry.at (" debug-assertions" ).as_boolean ()) {
87+ muuk::logger::info (" LTO enabled for profile '{}'" , profile);
88+ switch (compiler.getType ()) {
89+ case Compiler::Type::GCC:
90+ case Compiler::Type::Clang:
91+ build_profile.cflags .push_back (" -DNDEBUG" );
92+ case Compiler::Type::MSVC:
93+ build_profile.cflags .push_back (" /DNDEBUG" );
94+ }
95+ }
96+
97+ // --- Optimization Level ---
98+ build_profile.cflags .push_back (to_flag (
99+ opt_lvl_from_string (profile_entry.at (" opt-level" ).as_string ()),
100+ compiler.getType ()));
101+
102+ // --- Sanitizers ---
103+ if (profile_entry.contains (" sanitizers" ) && profile_entry.at (" sanitizers" ).is_array ()) {
104+ for (const auto & item : profile_entry.at (" sanitizers" ).as_array ()) {
105+ if (!item.is_string ())
106+ continue ;
107+
108+ const std::string name = item.as_string ();
109+
110+ switch (compiler.getType ()) {
111+ case Compiler::Type::GCC:
112+ case Compiler::Type::Clang:
113+ if (name == " address" )
114+ build_profile.cflags .push_back (" -fsanitize=address" );
115+ else if (name == " thread" )
116+ build_profile.cflags .push_back (" -fsanitize=thread" );
117+ else if (name == " undefined" )
118+ build_profile.cflags .push_back (" -fsanitize=undefined" );
119+ else if (name == " memory" )
120+ build_profile.cflags .push_back (" -fsanitize=memory" );
121+ else if (compiler.getType () == Compiler::Type::Clang && name == " leak" )
122+ build_profile.cflags .push_back (" -fsanitize=leak" );
123+ break ;
124+
125+ case Compiler::Type::MSVC:
126+ if (name == " address" )
127+ build_profile.cflags .push_back (" /fsanitize=address" );
128+ else if (name == " undefined" ) {
129+ build_profile.cflags .push_back (" /RTC1" );
130+ build_profile.cflags .push_back (" /RTCc" );
131+ build_profile.cflags .push_back (" /RTCs" );
132+ }
133+ // No leak, memory, or thread sanitizers in MSVC
134+ break ;
135+ }
136+ }
137+ }
138+
57139 muuk::logger::trace (" Profile '{}' CFLAGS: {}" , profile, fmt::join (build_profile.cflags , " " ));
58140 muuk::logger::trace (" Profile '{}' AFLAGS: {}" , profile, fmt::join (build_profile.cflags , " " ));
59141 muuk::logger::trace (" Profile '{}' LFLAGS: {}" , profile, fmt::join (build_profile.lflags , " " ));
0 commit comments