@@ -16,6 +16,7 @@ import '../utils/run_process.dart';
1616import 'compiler_resolver.dart' ;
1717import 'language.dart' ;
1818import 'linker_options.dart' ;
19+ import 'optimization_level.dart' ;
1920
2021class RunCBuilder {
2122 /// The options are for linking only, so this will be non-null iff a linker
@@ -45,6 +46,7 @@ class RunCBuilder {
4546 final String ? std;
4647 final Language language;
4748 final String ? cppLinkStdLib;
49+ final OptimizationLevel optimizationLevel;
4850
4951 RunCBuilder ({
5052 required this .config,
@@ -64,6 +66,7 @@ class RunCBuilder {
6466 this .std,
6567 this .language = Language .c,
6668 this .cppLinkStdLib,
69+ required this .optimizationLevel,
6770 }) : outDir = config.outputDirectory,
6871 assert ([executable, dynamicLibrary, staticLibrary]
6972 .whereType <Uri >()
@@ -275,6 +278,8 @@ class RunCBuilder {
275278 '-l' ,
276279 cppLinkStdLib ?? defaultCppLinkStdLib[config.targetOS]!
277280 ],
281+ if (optimizationLevel != OptimizationLevel .unspecified)
282+ optimizationLevel.clangFlag (),
278283 ...linkerOptions? .preSourcesFlags (toolInstance.tool, sourceFiles) ?? [],
279284 // Support Android 15 page size by default, can be overridden by
280285 // passing [flags].
@@ -327,6 +332,8 @@ class RunCBuilder {
327332 final result = await runProcess (
328333 executable: tool.uri,
329334 arguments: [
335+ if (optimizationLevel != OptimizationLevel .unspecified)
336+ optimizationLevel.msvcFlag (),
330337 if (std != null ) '/std:$std ' ,
331338 if (language == Language .cpp) '/TP' ,
332339 ...flags,
0 commit comments