Skip to content

Commit

Permalink
[native_toolchain_c] Support MSVC arm64 toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
pbo-linaro committed Oct 27, 2023
1 parent 18bff8c commit 9769bff
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class CompilerResolver {
switch (targetArch) {
case Architecture.ia32:
return clIA32;
case Architecture.arm64:
return clArm64;
case Architecture.x64:
return cl;
}
Expand Down Expand Up @@ -172,6 +174,8 @@ class CompilerResolver {
switch (targetArchitecture) {
case Architecture.ia32:
return libIA32;
case Architecture.arm64:
return libArm64;
case Architecture.x64:
return lib;
}
Expand Down
50 changes: 47 additions & 3 deletions pkgs/native_toolchain_c/lib/src/native_toolchain/msvc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ Tool vcvars(ToolInstance toolInstance) {
final tool = toolInstance.tool;
assert(tool == cl || tool == link || tool == lib);
final vcDir = toolInstance.uri.resolve('../../../../../../');
final fileName = toolInstance.uri.toFilePath().contains('x86')
? 'vcvars32.bat'
: 'vcvars64.bat';
var fileName = 'vcvars64.bat';
if (toolInstance.uri.toFilePath().contains('x86'))
{
fileName = 'vcvars32.bat';
} else if (toolInstance.uri.toFilePath().contains('arm64'))
{
// vcvarsarm64 only works on native windows-arm64. In case of cross
// compilation, it's better to stick to cross toolchain, which works under
// emulation on windows-arm64.
fileName = 'vcvarsamd64_arm64.bat';
}
final batchScript = vcDir.resolve('Auxiliary/Build/$fileName');
return Tool(
name: fileName,
Expand Down Expand Up @@ -96,6 +104,15 @@ final Tool vcvars32 = Tool(
),
);

final Tool vcvarsarm64 = Tool(
name: 'vcvarsarm64.bat',
defaultResolver: RelativeToolResolver(
toolName: 'vcvarsarm64.bat',
wrappedResolver: visualStudio.defaultResolver!,
relativePath: Uri(path: './VC/Auxiliary/Build/vcvarsarm64.bat'),
),
);

final Tool vcvarsall = Tool(
name: 'vcvarsall.bat',
defaultResolver: RelativeToolResolver(
Expand Down Expand Up @@ -134,6 +151,16 @@ final Tool clIA32 = _msvcTool(
hostArchitecture: Target.current.architecture,
);

/// The C/C++ Optimizing Compiler main executable.
///
/// For targeting arm64.
final Tool clArm64 = _msvcTool(
name: 'cl',
versionArguments: [],
targetArchitecture: Architecture.arm64,
hostArchitecture: Target.current.architecture,
);

final Tool lib = _msvcTool(
name: 'lib',
targetArchitecture: Architecture.x64,
Expand All @@ -150,6 +177,14 @@ final Tool libIA32 = _msvcTool(
resolveVersion: false,
);

final Tool libArm64 = _msvcTool(
name: 'lib',
targetArchitecture: Architecture.arm64,
hostArchitecture: Target.current.architecture,
// https://github.com/dart-lang/native/issues/18
resolveVersion: false,
);

final Tool link = _msvcTool(
name: 'link',
versionArguments: ['/help'],
Expand All @@ -166,6 +201,14 @@ final Tool linkIA32 = _msvcTool(
hostArchitecture: Target.current.architecture,
);

final Tool linkArm64 = _msvcTool(
name: 'link',
versionArguments: ['/help'],
versionExitCode: 1100,
targetArchitecture: Architecture.arm64,
hostArchitecture: Target.current.architecture,
);

final Tool dumpbin = _msvcTool(
name: 'dumpbin',
targetArchitecture: Architecture.x64,
Expand All @@ -175,6 +218,7 @@ final Tool dumpbin = _msvcTool(
const _msvcArchNames = {
Architecture.ia32: 'x86',
Architecture.x64: 'x64',
Architecture.arm64: 'arm64',
};

Tool _msvcTool({
Expand Down

0 comments on commit 9769bff

Please sign in to comment.