From 9769bff660e6dc4a4701edc6c60957af3100e5b9 Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Wed, 25 Oct 2023 14:35:10 +0200 Subject: [PATCH] [native_toolchain_c] Support MSVC arm64 toolchain --- .../lib/src/cbuilder/compiler_resolver.dart | 4 ++ .../lib/src/native_toolchain/msvc.dart | 50 +++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart index f724085a4..17ec90af1 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart @@ -85,6 +85,8 @@ class CompilerResolver { switch (targetArch) { case Architecture.ia32: return clIA32; + case Architecture.arm64: + return clArm64; case Architecture.x64: return cl; } @@ -172,6 +174,8 @@ class CompilerResolver { switch (targetArchitecture) { case Architecture.ia32: return libIA32; + case Architecture.arm64: + return libArm64; case Architecture.x64: return lib; } diff --git a/pkgs/native_toolchain_c/lib/src/native_toolchain/msvc.dart b/pkgs/native_toolchain_c/lib/src/native_toolchain/msvc.dart index 058cdac63..d053f6b4e 100644 --- a/pkgs/native_toolchain_c/lib/src/native_toolchain/msvc.dart +++ b/pkgs/native_toolchain_c/lib/src/native_toolchain/msvc.dart @@ -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, @@ -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( @@ -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, @@ -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'], @@ -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, @@ -175,6 +218,7 @@ final Tool dumpbin = _msvcTool( const _msvcArchNames = { Architecture.ia32: 'x86', Architecture.x64: 'x64', + Architecture.arm64: 'arm64', }; Tool _msvcTool({