@@ -6,6 +6,7 @@ import 'dart:io';
66
77import  'package:code_assets/code_assets.dart' ;
88
9+ import  '../native_toolchain/msvc.dart' ;
910import  '../native_toolchain/tool_likeness.dart' ;
1011import  '../tool/tool.dart' ;
1112
@@ -94,15 +95,35 @@ extension LinkerOptionsExt on LinkerOptions {
9495    Tool  tool,
9596    Iterable <String > sourceFiles,
9697    OS  targetOS,
98+     Architecture  targetArchitecture,
9799  ) {
98-     final  includeAllSymbols =  _symbolsToKeep ==  null ;
100+     if  (tool.isClangLike ||  tool.isLdLike) {
101+       return  _sourceFilesToFlagsForClangLike (tool, sourceFiles, targetOS);
102+     } else  if  (tool ==  cl) {
103+       return  _sourceFilesToFlagsForCl (
104+         tool,
105+         sourceFiles,
106+         targetOS,
107+         targetArchitecture,
108+       );
109+     } else  {
110+       throw  UnimplementedError ('This package does not know how to run $tool .' );
111+     }
112+   }
99113
114+   bool  get  _includeAllSymbols =>  _symbolsToKeep ==  null ;
115+ 
116+   Iterable <String > _sourceFilesToFlagsForClangLike (
117+     Tool  tool,
118+     Iterable <String > sourceFiles,
119+     OS  targetOS,
120+   ) {
100121    switch  (targetOS) {
101122      case  OS .macOS ||  OS .iOS: 
102123        return  [
103-           if  (! includeAllSymbols ) ...sourceFiles,
124+           if  (! _includeAllSymbols ) ...sourceFiles,
104125          ..._toLinkerSyntax (tool, [
105-             if  (includeAllSymbols ) ...sourceFiles.map ((e) =>  '-force_load,$e ' ),
126+             if  (_includeAllSymbols ) ...sourceFiles.map ((e) =>  '-force_load,$e ' ),
106127            ..._linkerFlags,
107128            ..._symbolsToKeep? .map ((symbol) =>  '-u,_$symbol ' ) ??  [],
108129            if  (stripDebug) '-S' ,
@@ -113,7 +134,7 @@ extension LinkerOptionsExt on LinkerOptions {
113134      case  OS .android ||  OS .linux: 
114135        final  wholeArchiveSandwich = 
115136            sourceFiles.any ((source) =>  source.endsWith ('.a' )) || 
116-             includeAllSymbols ;
137+             _includeAllSymbols ;
117138        return  [
118139          if  (wholeArchiveSandwich)
119140            ..._toLinkerSyntax (tool, ['--whole-archive' ]),
@@ -132,4 +153,23 @@ extension LinkerOptionsExt on LinkerOptions {
132153        throw  UnimplementedError ();
133154    }
134155  }
156+ 
157+   Iterable <String > _sourceFilesToFlagsForCl (
158+     Tool  tool,
159+     Iterable <String > sourceFiles,
160+     OS  targetOS,
161+     Architecture  targetArch,
162+   ) =>  [
163+     ...sourceFiles,
164+     '/link' ,
165+     if  (_includeAllSymbols) ...sourceFiles.map ((e) =>  '/WHOLEARCHIVE:$e ' ),
166+     ..._linkerFlags,
167+     ..._symbolsToKeep? .map (
168+           (symbol) => 
169+               '/INCLUDE:${targetArch  == Architecture .ia32  ? '_'  : '' }$symbol ' ,
170+         ) ?? 
171+         [],
172+     if  (stripDebug) '/PDBSTRIPPED' ,
173+     if  (gcSections) '/OPT:REF' ,
174+   ];
135175}
0 commit comments