diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index b714d6e25..65aab140c 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -79,6 +79,7 @@ class CBuilder extends CTool implements Builder { super.linkModePreference, super.optimizationLevel = OptimizationLevel.o3, this.buildMode = BuildMode.release, + super.runInShell, }) : super(type: OutputType.library); CBuilder.executable({ @@ -105,6 +106,7 @@ class CBuilder extends CTool implements Builder { super.cppLinkStdLib, super.optimizationLevel = OptimizationLevel.o3, this.buildMode = BuildMode.release, + super.runInShell, }) : super( type: OutputType.executable, assetName: null, @@ -203,6 +205,7 @@ class CBuilder extends CTool implements Builder { language: language, cppLinkStdLib: cppLinkStdLib, optimizationLevel: optimizationLevel, + runInShell: runInShell, ); await task.run(); diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart index 7c33d8121..0f3e85745 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart @@ -41,6 +41,7 @@ class CLinker extends CTool implements Linker { super.cppLinkStdLib, super.linkModePreference, super.optimizationLevel = OptimizationLevel.o3, + super.runInShell, }) : super(type: OutputType.library); /// Runs the C Linker with on this C build spec. @@ -94,6 +95,7 @@ class CLinker extends CTool implements Linker { language: language, cppLinkStdLib: cppLinkStdLib, optimizationLevel: optimizationLevel, + runInShell: runInShell, ); await task.run(); diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart index 064ff5846..6ff2a8f4f 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart @@ -166,6 +166,12 @@ abstract class CTool { /// What optimization level should be used for compiling. final OptimizationLevel optimizationLevel; + /// Whether to run the process in a shell. + /// + /// If the path to cl.exe contains spaces, this option needs to be set to + /// false. + final bool? runInShell; + CTool({ required this.name, required this.packageName, @@ -186,5 +192,6 @@ abstract class CTool { required this.linkModePreference, required this.type, required this.optimizationLevel, + this.runInShell, }); } diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index 8b904805f..2a570a095 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -50,6 +50,7 @@ class RunCBuilder { final Language language; final String? cppLinkStdLib; final OptimizationLevel optimizationLevel; + final bool? runInShell; RunCBuilder({ required this.input, @@ -73,6 +74,7 @@ class RunCBuilder { this.language = Language.c, this.cppLinkStdLib, required this.optimizationLevel, + this.runInShell, }) : outDir = input.outputDirectory, assert( [executable, dynamicLibrary, staticLibrary].whereType().length == @@ -196,6 +198,7 @@ class RunCBuilder { captureOutput: false, throwOnUnexpectedExitCode: true, environment: environment, + runInShell: runInShell, ); } else { await _compile( @@ -343,6 +346,7 @@ class RunCBuilder { logger: logger, captureOutput: false, throwOnUnexpectedExitCode: true, + runInShell: runInShell, ); } @@ -401,6 +405,7 @@ class RunCBuilder { captureOutput: false, stdoutLogLevel: Level.INFO, throwOnUnexpectedExitCode: true, + runInShell: runInShell, ); if (staticLibrary != null) { diff --git a/pkgs/native_toolchain_c/lib/src/utils/run_process.dart b/pkgs/native_toolchain_c/lib/src/utils/run_process.dart index 22285b1ae..8cc0854e0 100644 --- a/pkgs/native_toolchain_c/lib/src/utils/run_process.dart +++ b/pkgs/native_toolchain_c/lib/src/utils/run_process.dart @@ -22,6 +22,7 @@ Future runProcess({ Level stdoutLogLevel = Level.FINE, int expectedExitCode = 0, bool throwOnUnexpectedExitCode = false, + bool? runInShell, }) async { final printWorkingDir = workingDirectory != null && workingDirectory != Directory.current.uri; @@ -41,7 +42,7 @@ Future runProcess({ arguments, workingDirectory: workingDirectory?.toFilePath(), environment: environment, - runInShell: Platform.isWindows && workingDirectory != null, + runInShell: runInShell ?? Platform.isWindows && workingDirectory != null, ); final stdoutSub = process.stdout.listen((List data) {