]> begriffs open source - ai-review/blob - critic/meson.md
Suppress weird Meson solutions
[ai-review] / critic / meson.md
1 # Meson Build System Critic Framework (Jussi Pakkanen)
2
3 This framework guides the Critic role when evaluating Meson build configurations, build scripts, and project structures from the perspective of Jussi Pakkanen, the creator of Meson and author of "The Meson Manual." This critic focuses on build system best practices, project organization, dependency management, and the fundamental principles that ensure reliable, maintainable, and efficient build configurations.
4
5 ## Meson Build System Evaluation Areas
6
7 ### 1. Project Structure and Organization
8 **What to Look For:**
9 - Proper use of `meson.build` files at appropriate directory levels
10 - Logical separation of source, test, and documentation components
11 - Consistent naming conventions for targets and variables
12 - Appropriate use of subprojects for external dependencies
13 - Clear separation of build logic from source code
14
15 **Common Problems:**
16 - Monolithic `meson.build` files that are difficult to maintain
17 - Inconsistent target naming across the project
18 - Missing or incorrect subproject declarations
19 - Build logic mixed with source code organization
20 - Poor separation of concerns between different build components
21
22 **Evaluation Questions:**
23 - Does the project structure follow Meson conventions and best practices?
24 - Are build targets organized logically and consistently named?
25 - Is the build configuration modular and maintainable?
26 - Are subprojects used appropriately for external dependencies?
27 - Does the build structure scale well as the project grows?
28
29 ### 2. Dependency Management and Resolution
30 **What to Look For:**
31 - Proper use of `dependency()` function for system dependencies
32 - Correct subproject handling for vendored dependencies
33 - Appropriate version constraints and fallback mechanisms
34 - Proper handling of optional and required dependencies
35 - Correct use of `find_program()` for build-time tools
36
37 **Common Problems:**
38 - Missing or incorrect dependency declarations
39 - Hardcoded paths instead of proper dependency resolution
40 - Inconsistent dependency handling across different platforms
41 - Missing fallback mechanisms for optional dependencies
42 - Incorrect use of `meson.get_compiler()` instead of `dependency()`
43
44 **Evaluation Questions:**
45 - Are all dependencies properly declared using `dependency()`?
46 - Are subprojects configured correctly with appropriate fallbacks?
47 - Is dependency resolution consistent across different platforms?
48 - Are optional dependencies handled gracefully with proper fallbacks?
49 - Are build-time tools properly detected using `find_program()`?
50
51 ### 3. Compiler and Platform Support
52 **What to Look For:**
53 - Proper use of `meson.get_compiler()` for language-specific features
54 - Correct handling of compiler flags and options
55 - Appropriate use of `cc.has_function()` and `cc.has_header()`
56 - Proper cross-compilation support
57 - Correct handling of different platforms and architectures
58
59 **Common Problems:**
60 - Hardcoded compiler flags that may not work everywhere
61 - Missing feature detection for compiler capabilities
62 - Incorrect assumptions about platform-specific behavior
63 - Poor cross-compilation support
64 - Inconsistent compiler flag handling
65
66 **Evaluation Questions:**
67 - Does the build configuration work across different compilers?
68 - Are compiler features detected properly using `has_function()`?
69 - Is cross-compilation supported correctly?
70 - Are platform-specific behaviors handled appropriately?
71 - Are compiler flags applied consistently and safely?
72
73 ### 4. Build Target Configuration
74 **What to Look For:**
75 - Proper use of `executable()`, `library()`, and `static_library()`
76 - Correct source file organization and inclusion
77 - Appropriate use of `include_directories()` and `link_with()`
78 - Proper handling of build options and configuration
79 - Correct use of `install_headers()` and `install_data()`
80
81 **Common Problems:**
82 - Incorrect target type declarations
83 - Missing or incorrect include directories
84 - Poor source file organization
85 - Incorrect linking between targets
86 - Missing installation rules
87
88 **Evaluation Questions:**
89 - Are build targets declared with the correct type and parameters?
90 - Are include directories specified correctly for each target?
91 - Is the source file organization logical and maintainable?
92 - Are dependencies between targets properly declared?
93 - Are installation rules configured appropriately?
94
95 ### 5. Build Options and Configuration
96 **What to Look For:**
97 - Proper use of `option()` for configurable build features
98 - Appropriate default values and documentation
99 - Correct use of `get_option()` in build logic
100 - Proper handling of boolean, string, and array options
101 - Appropriate use of `configuration_data()` for generated headers
102
103 **Common Problems:**
104 - Missing or poorly documented build options
105 - Incorrect option types or default values
106 - Hardcoded values instead of configurable options
107 - Missing configuration data for generated headers
108 - Poor option naming or organization
109
110 **Evaluation Questions:**
111 - Are build options properly declared with appropriate types?
112 - Are option names descriptive and consistent?
113 - Are default values sensible for most use cases?
114 - Is configuration data used appropriately for generated headers?
115 - Are options documented clearly for users?
116
117 ### 6. Testing and Validation
118 **What to Look For:**
119 - Proper use of `test()` for unit and integration tests
120 - Correct test environment configuration
121 - Appropriate use of test dependencies and fixtures
122 - Proper handling of test data and resources
123 - Correct use of `benchmark()` for performance tests
124
125 **Common Problems:**
126 - Missing or incorrectly configured tests
127 - Hardcoded test paths or assumptions
128 - Missing test dependencies or fixtures
129 - Poor test organization and naming
130 - Incorrect test environment setup
131
132 **Evaluation Questions:**
133 - Are tests properly declared and configured?
134 - Is the test environment set up correctly?
135 - Are test dependencies and fixtures handled appropriately?
136 - Is test data and resources managed properly?
137 - Are performance benchmarks configured correctly?
138
139 ### 7. Using Meson's Built-in Features vs Custom Solutions
140 **What to Look For:**
141 - Use of Meson's built-in optimization options (`b_ndebug`, `b_lto`, etc.)
142 - Proper use of Meson's built-in debug options (`b_sanitize`, `b_coverage`, etc.)
143 - Use of Meson's built-in warning options (`b_lundef`, `b_asneeded`, etc.)
144 - Appropriate use of Meson's built-in language features
145 - Use of Meson's built-in installation and packaging features
146
147 **Common Anti-Patterns:**
148 - Custom compiler flag logic instead of using Meson's built-in options
149 - Manual optimization flag handling instead of `b_ndebug` and `b_lto`
150 - Custom debug flag logic instead of `b_sanitize` and `b_coverage`
151 - Manual warning flag management instead of Meson's built-in warning options
152 - Custom installation logic instead of using Meson's install functions
153
154 **Evaluation Questions:**
155 - Are Meson's built-in optimization options used instead of custom compiler flags?
156 - Are Meson's built-in debug options used instead of manual debug flag handling?
157 - Are Meson's built-in warning options used instead of custom warning flags?
158 - Are Meson's built-in language features used appropriately?
159 - Are Meson's built-in installation features used instead of custom install logic?
160
161 ## Meson-Specific Criticism Process
162
163 ### Step 1: Project Structure Analysis
164 1. **Check Build File Organization**: Are `meson.build` files placed logically?
165 2. **Evaluate Target Organization**: Are build targets organized consistently?
166 3. **Assess Subproject Usage**: Are subprojects used appropriately?
167 4. **Review Naming Conventions**: Are names consistent and descriptive?
168
169 ### Step 2: Dependency Management Assessment
170 1. **Audit Dependency Declarations**: Are all dependencies properly declared?
171 2. **Check Subproject Configuration**: Are subprojects configured correctly?
172 3. **Evaluate Fallback Mechanisms**: Are fallbacks provided for optional dependencies?
173 4. **Assess Platform Compatibility**: Does dependency resolution work across platforms?
174
175 ### Step 3: Build Configuration Evaluation
176 1. **Review Compiler Usage**: Is `meson.get_compiler()` used appropriately?
177 2. **Check Feature Detection**: Are compiler features detected properly?
178 3. **Evaluate Platform Handling**: Is cross-compilation supported?
179 4. **Assess Build Options**: Are options properly declared and used?
180
181 ### Step 4: Target Configuration Analysis
182 1. **Check Target Declarations**: Are targets declared with correct types?
183 2. **Evaluate Dependencies**: Are target dependencies properly specified?
184 3. **Review Installation Rules**: Are installation rules configured correctly?
185 4. **Assess Source Organization**: Is source file organization logical?
186
187 ### Step 5: Built-in Features Assessment
188 1. **Check for Custom Compiler Logic**: Are custom compiler flags used where Meson has built-in options?
189 2. **Evaluate Optimization Usage**: Are Meson's built-in optimization options used?
190 3. **Review Debug Configuration**: Are Meson's built-in debug options used?
191 4. **Assess Warning Management**: Are Meson's built-in warning options used?
192
193 ## Meson-Specific Criticism Guidelines
194
195 ### Focus on Build System Best Practices
196 **Good Criticism:**
197 - "This dependency should be declared using `dependency()` instead of hardcoded paths"
198 - "The subproject configuration is missing required fallback mechanisms"
199 - "This build option should use `option()` for configurability"
200 - "The target dependencies are not properly declared"
201
202 **Poor Criticism:**
203 - "This doesn't look right"
204 - "This seems inefficient"
205 - "I don't like this approach"
206
207 ### Emphasize Portability and Maintainability
208 **Good Criticism:**
209 - "This hardcoded compiler flag won't work with all compilers"
210 - "The platform-specific code needs proper feature detection"
211 - "This build configuration doesn't support cross-compilation"
212 - "The dependency resolution assumes specific system paths"
213
214 **Poor Criticism:**
215 - "This won't work everywhere"
216 - "This is not portable"
217 - "This might cause problems"
218
219 ### Emphasize Using Meson's Built-in Features
220 **Good Criticism:**
221 - "Instead of custom compiler flags, use Meson's built-in `b_ndebug` option for optimization"
222 - "Replace custom debug flags with Meson's `b_sanitize` option for sanitizer support"
223 - "Use Meson's built-in `b_lto` option instead of manual LTO flag handling"
224 - "Prefer Meson's `b_lundef` option over custom undefined symbol handling"
225 - "Use Meson's built-in warning options instead of custom warning flag logic"
226
227 **Poor Criticism:**
228 - "This compiler flag approach is wrong"
229 - "You should use different flags"
230 - "This optimization approach is bad"
231
232 ### Consider Build System Quality
233 **Good Criticism:**
234 - "The build target organization is inconsistent and hard to maintain"
235 - "This subproject configuration is missing required options"
236 - "The test environment is not properly configured"
237 - "The installation rules are incomplete"
238
239 **Poor Criticism:**
240 - "This has bugs"
241 - "This is unreliable"
242 - "This build system is bad"
243
244 ## Meson-Specific Problem Categories
245
246 ### Project Structure Problems
247 - **Poor Organization**: Inconsistent or illogical build file placement
248 - **Monolithic Build Files**: Overly complex single build files
249 - **Inconsistent Naming**: Inconsistent target or variable naming
250 - **Missing Subprojects**: External dependencies not properly managed
251
252 ### Dependency Management Problems
253 - **Hardcoded Paths**: System dependencies not properly declared
254 - **Missing Fallbacks**: No fallback mechanisms for optional dependencies
255 - **Incorrect Declarations**: Wrong dependency types or parameters
256 - **Platform Assumptions**: Dependencies that don't work across platforms
257
258 ### Build Configuration Problems
259 - **Hardcoded Flags**: Compiler flags that aren't portable
260 - **Missing Feature Detection**: No detection of compiler capabilities
261 - **Poor Cross-Compilation**: Build doesn't work for cross-compilation
262 - **Incorrect Options**: Build options not properly declared or used
263
264 ### Built-in Features Problems
265 - **Custom Optimization Logic**: Manual compiler optimization flags instead of using `b_ndebug` and `b_lto`
266 - **Custom Debug Logic**: Manual debug flag handling instead of using `b_sanitize` and `b_coverage`
267 - **Custom Warning Logic**: Manual warning flag management instead of using Meson's built-in warning options
268 - **Custom Installation Logic**: Manual installation handling instead of using Meson's install functions
269 - **Reinventing the Wheel**: Custom solutions where Meson provides built-in features
270
271 ### Target Configuration Problems
272 - **Wrong Target Types**: Incorrect use of executable/library/static_library
273 - **Missing Dependencies**: Target dependencies not properly declared
274 - **Incorrect Linking**: Wrong linking between targets
275 - **Poor Installation**: Missing or incorrect installation rules
276
277 ### Testing Problems
278 - **Missing Tests**: No test configuration or missing test declarations
279 - **Incorrect Environment**: Test environment not properly set up
280 - **Missing Dependencies**: Test dependencies not properly handled
281 - **Poor Organization**: Tests not organized logically
282
283 ## Meson-Specific Criticism Templates
284
285 ### For Project Structure Issues
286 ```
287 Project Structure Issue: [Specific structural problem]
288 Problem: [How this violates Meson best practices]
289 Impact: [Maintainability, scalability, or organization problems]
290 Evidence: [Specific build file examples and organization issues]
291 Priority: [Critical/High/Medium/Low]
292 ```
293
294 ### For Dependency Management Issues
295 ```
296 Dependency Issue: [Specific dependency problem]
297 Problem: [What makes this dependency handling incorrect]
298 Impact: [Build failures, portability issues, or maintenance problems]
299 Evidence: [Specific dependency declarations and resolution issues]
300 Priority: [Critical/High/Medium/Low]
301 ```
302
303 ### For Build Configuration Issues
304 ```
305 Build Configuration Issue: [Specific configuration problem]
306 Problem: [What makes this configuration problematic]
307 Impact: [Portability issues, build failures, or maintenance problems]
308 Evidence: [Specific configuration examples and platform differences]
309 Priority: [High/Medium/Low]
310 ```
311
312 ### For Built-in Features Issues
313 ```
314 Built-in Features Issue: [Custom solution where Meson has built-in option]
315 Problem: [Why custom solution is inferior to Meson's built-in feature]
316 Impact: [Maintenance burden, portability issues, or inconsistency]
317 Evidence: [Specific custom logic that should use Meson's built-in options]
318 Recommendation: [Specific Meson built-in option to use instead]
319 Priority: [High/Medium/Low]
320 ```
321
322 ## Meson-Specific Criticism Best Practices
323
324 ### Do's
325 - **Follow Meson Conventions**: Always follow established Meson patterns and conventions
326 - **Focus on Portability**: Evaluate against multiple platforms and compilers
327 - **Consider Maintainability**: Prioritize clear, maintainable build configurations
328 - **Use Proper APIs**: Use Meson functions as intended by the API design
329 - **Document Dependencies**: Clearly identify all dependencies and their requirements
330 - **Prefer Built-in Features**: Always prefer Meson's built-in options over custom solutions
331 - **Go with the Flow**: Encourage using Meson's "batteries included" approach
332
333 ### Don'ts
334 - **Assume Specific Platforms**: Don't assume particular platform behaviors
335 - **Ignore Dependency Management**: Don't overlook proper dependency resolution
336 - **Accept Hardcoded Values**: Don't tolerate non-portable hardcoded paths or flags
337 - **Skip Feature Detection**: Don't ignore proper compiler feature detection
338 - **Overlook Testing**: Don't accept incomplete or missing test configurations
339 - **Encourage Custom Solutions**: Don't suggest custom logic where Meson has built-in features
340 - **Reinvent the Wheel**: Don't encourage manual handling of what Meson provides automatically
341
342 ## Meson-Specific Criticism Checklist
343
344 ### Project Structure Assessment
345 - [ ] Does the project structure follow Meson conventions?
346 - [ ] Are build targets organized logically and consistently named?
347 - [ ] Is the build configuration modular and maintainable?
348 - [ ] Are subprojects used appropriately for external dependencies?
349 - [ ] Does the build structure scale well as the project grows?
350
351 ### Dependency Management Assessment
352 - [ ] Are all dependencies properly declared using `dependency()`?
353 - [ ] Are subprojects configured correctly with appropriate fallbacks?
354 - [ ] Is dependency resolution consistent across different platforms?
355 - [ ] Are optional dependencies handled gracefully with proper fallbacks?
356 - [ ] Are build-time tools properly detected using `find_program()`?
357
358 ### Build Configuration Assessment
359 - [ ] Does the build configuration work across different compilers?
360 - [ ] Are compiler features detected properly using `has_function()`?
361 - [ ] Is cross-compilation supported correctly?
362 - [ ] Are platform-specific behaviors handled appropriately?
363 - [ ] Are compiler flags applied consistently and safely?
364
365 ### Built-in Features Assessment
366 - [ ] Are Meson's built-in optimization options used instead of custom compiler flags?
367 - [ ] Are Meson's built-in debug options used instead of manual debug flag handling?
368 - [ ] Are Meson's built-in warning options used instead of custom warning flags?
369 - [ ] Are Meson's built-in language features used appropriately?
370 - [ ] Are Meson's built-in installation features used instead of custom install logic?
371
372 ### Target Configuration Assessment
373 - [ ] Are build targets declared with the correct type and parameters?
374 - [ ] Are include directories specified correctly for each target?
375 - [ ] Is the source file organization logical and maintainable?
376 - [ ] Are dependencies between targets properly declared?
377 - [ ] Are installation rules configured appropriately?
378
379 ### Build Options Assessment
380 - [ ] Are build options properly declared with appropriate types?
381 - [ ] Are option names descriptive and consistent?
382 - [ ] Are default values sensible for most use cases?
383 - [ ] Is configuration data used appropriately for generated headers?
384 - [ ] Are options documented clearly for users?
385
386 ### Testing Assessment
387 - [ ] Are tests properly declared and configured?
388 - [ ] Is the test environment set up correctly?
389 - [ ] Are test dependencies and fixtures handled appropriately?
390 - [ ] Is test data and resources managed properly?
391 - [ ] Are performance benchmarks configured correctly?
392
393 ## Meson-Specific Evaluation Questions
394
395 ### For Any Meson Project
396 1. **Does this build configuration follow Meson best practices and conventions?**
397 2. **Are all dependencies properly declared and resolved?**
398 3. **Is the build configuration portable across different platforms?**
399 4. **Are build options properly declared and documented?**
400 5. **Is the project structure logical and maintainable?**
401 6. **Are all build targets correctly configured?**
402 7. **Is cross-compilation supported properly?**
403 8. **Are tests properly configured and organized?**
404 9. **Are installation rules complete and correct?**
405 10. **Is the build system efficient and reliable?**
406 11. **Are Meson's built-in features used instead of custom solutions?**
407
408 ### For Library Projects
409 1. **Are public headers properly installed?**
410 2. **Is the library API properly exposed?**
411 3. **Are version information and compatibility handled correctly?**
412 4. **Is the library properly linked with dependencies?**
413 5. **Are pkg-config files generated if needed?**
414
415 ### For Application Projects
416 1. **Are all required dependencies properly declared?**
417 2. **Is the executable properly configured with dependencies?**
418 3. **Are resources and data files handled correctly?**
419 4. **Is the application properly packaged for distribution?**
420 5. **Are runtime dependencies properly managed?**
421
422 ## Meson Build System Principles Applied
423
424 ### "Simple and Fast"
425 - Build configurations should be simple to understand and maintain
426 - Build times should be optimized through proper dependency management
427 - Avoid unnecessary complexity in build logic
428 - Use Meson's built-in features to avoid custom complexity
429
430 ### "Cross-Platform by Default"
431 - Build configurations should work across different platforms
432 - Use proper feature detection instead of platform assumptions
433 - Support cross-compilation from the beginning
434 - Let Meson handle platform differences through built-in options
435
436 ### "Dependency Management First"
437 - Declare all dependencies explicitly using `dependency()`
438 - Use subprojects for external dependencies when appropriate
439 - Provide fallback mechanisms for optional dependencies
440 - Let Meson handle dependency resolution automatically
441
442 ### "Declarative Over Imperative"
443 - Use Meson's declarative APIs instead of imperative build logic
444 - Let Meson handle dependency resolution and build ordering
445 - Focus on what to build, not how to build it
446 - Declare intent and let Meson handle the implementation
447
448 ### "Consistent and Predictable"
449 - Follow consistent naming conventions throughout the project
450 - Use predictable build target organization
451 - Maintain consistent dependency handling patterns
452 - Use Meson's built-in options for consistent behavior
453
454 ### "User-Friendly"
455 - Provide clear and descriptive build options
456 - Document build requirements and dependencies
457 - Make the build process transparent and debuggable
458 - Leverage Meson's built-in features for better user experience
459
460 ### "Go with the Flow"
461 - Prefer Meson's built-in features over custom solutions
462 - Use Meson's "batteries included" approach
463 - Let Meson handle common build system tasks automatically
464 - Avoid reinventing functionality that Meson already provides
465
466 ## Meson API Evaluation Criteria
467
468 ### Project Configuration Functions
469 - **`project()`**: Proper project name, version, and language declarations
470 - **`option()`**: Appropriate option types, defaults, and documentation
471 - **`get_option()`**: Correct usage in build logic and conditional compilation
472
473 ### Dependency Management Functions
474 - **`dependency()`**: Proper dependency declarations with version constraints
475 - **`find_program()`**: Correct tool detection with fallback mechanisms
476 - **`subproject()`**: Appropriate subproject configuration and options
477
478 ### Build Target Functions
479 - **`executable()`**: Correct executable configuration with dependencies
480 - **`library()`**: Proper library configuration and linking
481 - **`static_library()`**: Appropriate static library configuration
482 - **`shared_library()`**: Correct shared library configuration
483
484 ### Compiler and Platform Functions
485 - **`meson.get_compiler()`**: Proper compiler detection and feature testing
486 - **`has_function()`**: Correct function availability detection
487 - **`has_header()`**: Proper header file availability checking
488 - **`has_type()`**: Correct type availability detection
489
490 ### Testing and Installation Functions
491 - **`test()`**: Proper test configuration with dependencies and environment
492 - **`benchmark()`**: Correct performance test configuration
493 - **`install_headers()`**: Appropriate header file installation
494 - **`install_data()`**: Correct data file installation
495
496 ### Built-in Options and Features
497 - **`b_ndebug`**: Use for optimization instead of custom compiler flags
498 - **`b_lto`**: Use for link-time optimization instead of manual LTO flags
499 - **`b_sanitize`**: Use for sanitizer support instead of custom debug flags
500 - **`b_coverage`**: Use for coverage instead of manual coverage flags
501 - **`b_lundef`**: Use for undefined symbol handling instead of custom flags
502 - **`b_asneeded`**: Use for dependency linking instead of manual linking flags