@@ -6,6 +6,7 @@ import 'dart:io';
6
6
7
7
import 'package:code_assets/code_assets.dart' ;
8
8
9
+ import '../native_toolchain/msvc.dart' ;
9
10
import '../native_toolchain/tool_likeness.dart' ;
10
11
import '../tool/tool.dart' ;
11
12
@@ -94,15 +95,35 @@ extension LinkerOptionsExt on LinkerOptions {
94
95
Tool tool,
95
96
Iterable <String > sourceFiles,
96
97
OS targetOS,
98
+ Architecture targetArchitecture,
97
99
) {
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
+ }
99
113
114
+ bool get _includeAllSymbols => _symbolsToKeep == null ;
115
+
116
+ Iterable <String > _sourceFilesToFlagsForClangLike (
117
+ Tool tool,
118
+ Iterable <String > sourceFiles,
119
+ OS targetOS,
120
+ ) {
100
121
switch (targetOS) {
101
122
case OS .macOS || OS .iOS:
102
123
return [
103
- if (! includeAllSymbols ) ...sourceFiles,
124
+ if (! _includeAllSymbols ) ...sourceFiles,
104
125
..._toLinkerSyntax (tool, [
105
- if (includeAllSymbols ) ...sourceFiles.map ((e) => '-force_load,$e ' ),
126
+ if (_includeAllSymbols ) ...sourceFiles.map ((e) => '-force_load,$e ' ),
106
127
..._linkerFlags,
107
128
..._symbolsToKeep? .map ((symbol) => '-u,_$symbol ' ) ?? [],
108
129
if (stripDebug) '-S' ,
@@ -113,7 +134,7 @@ extension LinkerOptionsExt on LinkerOptions {
113
134
case OS .android || OS .linux:
114
135
final wholeArchiveSandwich =
115
136
sourceFiles.any ((source) => source.endsWith ('.a' )) ||
116
- includeAllSymbols ;
137
+ _includeAllSymbols ;
117
138
return [
118
139
if (wholeArchiveSandwich)
119
140
..._toLinkerSyntax (tool, ['--whole-archive' ]),
@@ -132,4 +153,23 @@ extension LinkerOptionsExt on LinkerOptions {
132
153
throw UnimplementedError ();
133
154
}
134
155
}
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
+ ];
135
175
}
0 commit comments