Skip to content

[native_toolchain_c] Support Clang on Windows 2 #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -218,7 +218,11 @@ class CompilerResolver {
}

final compilerTool = compiler.tool;
assert(compilerTool == cl);
if (compilerTool != cl) {
// If Clang is used on Windows, and we could discover the MSVC
// installation, then Clang should be able to discover it as well.
return {};
}
final vcvarsScript =
(await vcvars(compiler).defaultResolver!.resolve(logger: logger)).first;
return await environmentFromBatchFile(
8 changes: 8 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart
Original file line number Diff line number Diff line change
@@ -131,6 +131,9 @@ class RunCBuilder {
}

Future<void> runClangLike({required ToolInstance tool}) async {
// Clang for Windows requires the MSVC Developer Environment.
final environment = await _resolver.resolveEnvironment(tool);

final isStaticLib = staticLibrary != null;
Uri? archiver_;
if (isStaticLib) {
@@ -176,6 +179,7 @@ class RunCBuilder {
targetMacOSVersion,
[sourceFiles[i]],
objectFile,
environment,
);
objectFiles.add(objectFile);
}
@@ -189,6 +193,7 @@ class RunCBuilder {
logger: logger,
captureOutput: false,
throwOnUnexpectedExitCode: true,
environment: environment,
);
} else {
await _compile(
@@ -200,6 +205,7 @@ class RunCBuilder {
targetMacOSVersion,
sourceFiles,
dynamicLibrary != null ? outDir.resolveUri(dynamicLibrary!) : null,
environment,
);
}
}
@@ -214,9 +220,11 @@ class RunCBuilder {
int? targetMacOSVersion,
Iterable<String> sourceFiles,
Uri? outFile,
Map<String, String> environment,
) async {
await runProcess(
executable: toolInstance.uri,
environment: environment,
arguments: [
if (codeConfig.targetOS == OS.android) ...[
'--target='
Loading