forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWasiApp.Native.targets
593 lines (488 loc) · 34.6 KB
/
WasiApp.Native.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<Project>
<!-- not really meant to be used w/o WasmApp.targets -->
<UsingTask TaskName="Microsoft.WebAssembly.Build.Tasks.WasmResolveAssemblyDependencies" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="ManagedToNativeGenerator" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<PropertyGroup>
<_WasiBuildNativeCoreDependsOn>
_SetupWasiSdk;
_SetWasmBuildNativeDefaults;
_PrepareForWasiBuildNative;
_GetNativeFilesForLinking;
_GenerateManagedToNative;
_GenerateAssemblyObjectFiles;
_WasiLink;
</_WasiBuildNativeCoreDependsOn>
<!--<_BeforeWasmBuildAppDependsOn>-->
<!--$(_BeforeWasmBuildAppDependsOn);-->
<!--_SetupEmscripten;-->
<!--_SetWasmBuildNativeDefaults-->
<!--</_BeforeWasmBuildAppDependsOn>-->
<_ExeExt Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">.exe</_ExeExt>
<!--<WasmUseEMSDK_PATH Condition="'$(WasmUseEMSDK_PATH)' == '' and '$(EMSDK_PATH)' != '' and Exists('$(MSBuildThisFileDirectory)WasmApp.InTree.targets')">true</WasmUseEMSDK_PATH>-->
</PropertyGroup>
<ItemGroup>
<UpToDateCheckInput Include="@(NativeFileReference)" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug' and '@(_MonoComponent->Count())' == 0">
<_MonoComponent Include="hot_reload;debugger" />
</ItemGroup>
<ItemGroup>
<_MonoComponent Include="marshal-ilgen" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)WasiSdk.Defaults.props" />
<Target Name="_SetupWasiSdk">
<PropertyGroup>
<_ToolchainMissingPaths Condition="'$(_ToolchainMissingPaths)' == '' and ('$(WasiClang)' == '' or !Exists('$(WasiClang)'))">%24(WasiClang)=$(WasiClang) </_ToolchainMissingPaths>
</PropertyGroup>
<PropertyGroup>
<_ToolchainMissingErrorMessage Condition="'$(WASI_SDK_PATH)' == '' and '$(WasiSdkRoot)' == ''">Could not find wasi-sdk. Either set %24(WASI_SDK_PATH), or use workloads to get the sdk.</_ToolchainMissingErrorMessage>
<_IsToolchainMissing Condition="'$(_ToolchainMissingErrorMessage)' != ''">true</_IsToolchainMissing>
</PropertyGroup>
</Target>
<Target Name="_SetWasmBuildNativeDefaults">
<!-- if already set, maybe by a user projects, then a missing emsdk is an error -->
<Error Condition="'$(WasmBuildNative)' == 'true' and '$(_IsToolchainMissing)' == 'true'"
Text="$(_ToolchainMissingErrorMessage) SDK is required for building native files." />
<Error Condition="'$(WasmBuildNative)' == 'true' and '$(_IsToolchainMissing)' == 'true'"
Text="$(_ToolchainMissingErrorMessage) SDK is required for AOT'ing assemblies." />
<!-- When Building -->
<PropertyGroup Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
<!-- build AOT, only if explicitly requested -->
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true' and '$(RunAOTCompilationAfterBuild)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableSIMD)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
</PropertyGroup>
<!-- When Publishing -->
<PropertyGroup Condition="'$(WasmBuildingForNestedPublish)' == 'true'">
<!-- AOT==true overrides WasmBuildNative -->
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableSIMD)' == 'true'">true</WasmBuildNative>
<!-- not aot, not trimmed app, no reason to relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(PublishTrimmed)' != 'true'">false</WasmBuildNative>
<!-- default to relinking in Release config -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(Configuration)' == 'Release'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
</PropertyGroup>
<!-- If we want to default to true, and sdk is missing, then just warn, and set it to false -->
<Warning Condition="'$(WasmBuildNative)' == 'true' and '$(_IsToolchainMissing)' == 'true'"
Text="$(_ToolchainMissingErrorMessage) SDK is required for building native files." />
<PropertyGroup>
<WasmBuildNative Condition="'$(WasmBuildNative)' == 'true' and '$(_IsToolchainMissing)' == 'true'">false</WasmBuildNative>
</PropertyGroup>
</Target>
<Target Name="_WasiBuildNativeCore" DependsOnTargets="$(_WasiBuildNativeCoreDependsOn)" Condition="'$(WasmBuildNative)' == 'true'" />
<Target Name="_PrepareForWasiBuildNative">
<Error Condition="'$(_IsToolchainMissing)' == 'true'"
Text="$(_ToolchainMissingErrorMessage) Emscripten SDK is required for building native files." />
<PropertyGroup>
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
<_WasiClangDefaultFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-default.rsp'))</_WasiClangDefaultFlagsRsp>
<_WasiClangDefaultLinkFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-link.rsp'))</_WasiClangDefaultLinkFlagsRsp>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>
<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
<!--<_WasmRuntimeICallTablePath>$(_WasmIntermediateOutputPath)runtime-icall-table.h</_WasmRuntimeICallTablePath>-->
<_WasmPInvokeTablePath>$(_WasmIntermediateOutputPath)pinvoke-table.h</_WasmPInvokeTablePath>
<_WasmInterpToNativeTablePath>$(_WasmIntermediateOutputPath)wasm_m2n_invoke.g.h</_WasmInterpToNativeTablePath>
<_WasmPInvokeHPath>$(_WasmRuntimePackIncludeDir)wasm\pinvoke.h</_WasmPInvokeHPath>
<_DriverGenCPath>$(_WasmIntermediateOutputPath)driver-gen.c</_DriverGenCPath>
<DisableParallelAot Condition="'$(DisableParallelAot)' == ''">false</DisableParallelAot>
<DisableParallelEmccCompile Condition="'$(DisableParallelEmccCompile)' == ''">$(DisableParallelAot)</DisableParallelEmccCompile>
<_DriverGenCNeeded Condition="'$(_DriverGenCNeeded)' == '' and '$(_WasmShouldAOT)' == 'true'">true</_DriverGenCNeeded>
<_WasmDevel Condition="'$(_WasmDevel)' == '' and '$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug'">true</_WasmDevel>
<!--<_EmccAssertionLevelDefault Condition="'$(_EmccAssertionLevelDefault)' == ''">0</_EmccAssertionLevelDefault>-->
<!--<_EmccOptimizationFlagDefault Condition="'$(_WasmDevel)' == 'true'">-O0</_EmccOptimizationFlagDefault>-->
<!--<_EmccOptimizationFlagDefault Condition="'$(_EmccOptimizationFlagDefault)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">-O1</_EmccOptimizationFlagDefault>-->
<!--<_EmccOptimizationFlagDefault Condition="'$(_EmccOptimizationFlagDefault)' == ''">-Oz</_EmccOptimizationFlagDefault>-->
<!--<EmccCompileOptimizationFlag Condition="'$(EmccCompileOptimizationFlag)' == ''">$(_EmccOptimizationFlagDefault)</EmccCompileOptimizationFlag>-->
<!--<EmccLinkOptimizationFlag Condition="'$(EmccLinkOptimizationFlag)' == '' and '$(Configuration)' == 'Release'">-O2</EmccLinkOptimizationFlag>-->
<!--<EmccLinkOptimizationFlag Condition="'$(EmccLinkOptimizationFlag)' == ''" >$(EmccCompileOptimizationFlag)</EmccLinkOptimizationFlag>-->
<!--<_EmccCompileRsp>$(_WasmIntermediateOutputPath)emcc-compile.rsp</_EmccCompileRsp>-->
<!--<_EmccCompileOutputMessageImportance Condition="'$(EmccVerbose)' == 'true'">Normal</_EmccCompileOutputMessageImportance>-->
<!--<_EmccCompileOutputMessageImportance Condition="'$(EmccVerbose)' != 'true'">Low</_EmccCompileOutputMessageImportance>-->
<!--<_EmccCompileBitcodeRsp>$(_WasmIntermediateOutputPath)emcc-compile-bc.rsp</_EmccCompileBitcodeRsp>-->
<!--<_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp</_EmccLinkRsp>-->
<!-- TODOWASI this needs similar AOT logic as EMCC in https://github.com/dotnet/runtime/pull/80507 -->
<WasmInitialHeapSize Condition="'$(WasmInitialHeapSize)' == ''">52428800</WasmInitialHeapSize>
</PropertyGroup>
<ItemGroup>
<_WasmLinkDependencies Remove="@(_WasmLinkDependencies)" />
<!--<_EmccCommonFlags Include="$(_DefaultEmccFlags)" />-->
<!--<_EmccCommonFlags Include="$(EmccFlags)" />-->
<!--<_EmccCommonFlags Include="-s EXPORT_ES6=1" />-->
<!--<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeStrip)' == 'false'" />-->
<!--<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' != 'false'" />-->
<!--<_EmccCommonFlags Include="-s DISABLE_EXCEPTION_CATCHING=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />-->
<!--<_EmccCommonFlags Include="-fwasm-exceptions" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />-->
<!--<_EmccCommonFlags Include="-msimd128" Condition="'$(WasmEnableSIMD)' == 'true'" />-->
<_WasmCommonIncludePaths Include="$(_WasmIntermediateOutputPath.TrimEnd('\/'))" />
<_WasmCommonIncludePaths Include="$(_WasmRuntimePackIncludeDir)mono-2.0" />
<_WasmCommonIncludePaths Include="$(_WasmRuntimePackIncludeDir)wasm" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<!-- Fixup on windows -->
<_WasmCommonIncludePathsFixedUp Include="$([System.String]::new(%(_WasmCommonIncludePaths.Identity)).Replace('\', '/'))" />
<_WasmCommonIncludePaths Remove="@(_WasmCommonIncludePaths)" />
<_WasmCommonIncludePaths Include="@(_WasmCommonIncludePathsFixedUp)" />
</ItemGroup>
<ItemGroup>
<_WasmCommonCFlags Include="-DGEN_PINVOKE=1" />
<_WasmCommonCFlags Condition="'$(WasmSingleFileBundle)' == 'true'" Include="-DBUNDLED_ASSEMBLIES=1" />
<!-- Adding optimization flag at the top, so it gets precedence -->
<!--<_EmccCFlags Include="$(EmccCompileOptimizationFlag)" />-->
<!--<_EmccCFlags Include="-s ASSERTIONS=$(_EmccAssertionLevelDefault)" Condition="'$(_WasmDevel)' == 'true'" />-->
<!--<_EmccCFlags Include="@(_EmccCommonFlags)" />-->
<!--<_EmccCFlags Include="-DDISABLE_PERFTRACING_LISTEN_PORTS=1" />-->
<!--<_EmccCFlags Include="-DENABLE_AOT=1" Condition="'$(_WasmShouldAOT)' == 'true'" />-->
<!--<_EmccCFlags Include="-DDRIVER_GEN=1" Condition="'$(_WasmShouldAOT)' == 'true'" />-->
<!--<_EmccCFlags Include="-DINVARIANT_GLOBALIZATION=1" Condition="'$(InvariantGlobalization)' == 'true'" />-->
<!--<_EmccCFlags Include="-DLINK_ICALLS=1" Condition="'$(WasmLinkIcalls)' == 'true'" />-->
<!--<_EmccCFlags Include="-DENABLE_AOT_PROFILER=1" Condition="$(WasmProfilers.Contains('aot'))" />-->
<!--<_EmccCFlags Include="-DENABLE_BROWSER_PROFILER=1" Condition="$(WasmProfilers.Contains('browser'))" />-->
<!--<_EmccCFlags Include="-DGEN_PINVOKE=1" />-->
<!--<_EmccCFlags Include="-emit-llvm" />-->
<!--<_EmccCFlags Include="-g" Condition="'$(WasmNativeDebugSymbols)' == 'true'" />-->
<!-- Adding optimization flag at the top, so it gets precedence -->
<!--<_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" />-->
<!--<_EmccLDFlags Include="@(_EmccCommonFlags)" />-->
<!-- ILLinker should have removed unused imports, so error for Publish -->
<!--<_EmccLDSFlags Include="-s ERROR_ON_UNDEFINED_SYMBOLS=0" Condition="'$(WasmBuildingForNestedPublish)' != 'true'" />-->
<!--<_DriverCDependencies Include="$(_WasmPInvokeHPath);$(_WasmICallTablePath)" />-->
<!--<_DriverCDependencies Include="$(_DriverGenCPath)" Condition="'$(_DriverGenCNeeded)' == 'true'" />-->
<!--<_WasmRuntimePackSrcFile Include="$(_WasmRuntimePackSrcDir)pinvoke.c"-->
<!--Dependencies="$(_WasmPInvokeHPath);$(_WasmPInvokeTablePath)" />-->
<!--<_WasmRuntimePackSrcFile Include="$(_WasmRuntimePackSrcDir)driver.c"-->
<!--Dependencies="@(_DriverCDependencies)" />-->
<!--<_WasmRuntimePackSrcFile Include="$(_WasmRuntimePackSrcDir)corebindings.c" />-->
<!--<_WasmRuntimePackSrcFile ObjectFile="$(_WasmIntermediateOutputPath)%(FileName).o" />-->
<!-- See src\mono\wasm\runtime\modularize-dotnet.md -->
<!--<_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" />-->
<!--<_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\es6\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" />-->
<!--<_WasmNativeFileForLinking Include="@(NativeFileReference)" />-->
<!--<EmscriptenEnvVars Include="EMSDK_PYTHON=$(EmscriptenPythonToolsPath)python.exe" Condition="'$(OS)' == 'Windows_NT'" />-->
<!--<EmscriptenEnvVars Include="PYTHONPATH=$(EmscriptenPythonToolsPath)" Condition="'$(OS)' == 'Windows_NT'" />-->
<!--<EmscriptenEnvVars Include="PYTHONHOME=" Condition="'$(OS)' == 'Windows_NT'" />-->
<!--<EmscriptenEnvVars Include="EM_CACHE=$(WasmCachePath)" Condition="'$(WasmCachePath)' != ''" />-->
</ItemGroup>
<Error Text="Could not find NativeFileReference %(NativeFileReference.Identity)" Condition="'%(NativeFileReference.Identity)' != '' and !Exists(%(NativeFileReference.Identity))" />
</Target>
<Target Name="_GenerateManagedToNative">
<ItemGroup>
<_WasmPInvokeModules Include="%(_WasmNativeFileForLinking.FileName)" Condition="'%(_WasmNativeFileForLinking.ScanForPInvokes)' != 'false'" />
<_WasmPInvokeModules Include="libSystem.Native" />
<_WasmPInvokeModules Include="libSystem.Globalization.Native" />
<!-- FIXME: wasi -->
<!--<_WasmPInvokeModules Include="libSystem.IO.Compression.Native" />-->
</ItemGroup>
<PropertyGroup>
<_HasMscorlib Condition="'%(_WasmAssembliesInternal.FileName)%(_WasmAssembliesInternal.Extension)' == 'mscorlib.dll'">true</_HasMscorlib>
<_MscorlibPath Condition="'$(_HasMscorlib)' != 'true'">$(MicrosoftNetCoreAppRuntimePackRidDir)lib\net8.0\mscorlib.dll</_MscorlibPath>
</PropertyGroup>
<!--<Error Condition="'$(_MonoAotCrossCompilerPath)' == '' or !Exists('$(_MonoAotCrossCompilerPath)')"-->
<!--Text="Could not find AOT cross compiler at %24(_MonoAotCrossCompilerPath)=$(_MonoAotCrossCompilerPath)" />-->
<!--<Exec Command='"$(_MonoAotCrossCompilerPath)" print-icall-table > "$(_WasmRuntimeICallTablePath)"' />-->
<!--<ItemGroup>-->
<!--<FileWrites Include="$(_WasmRuntimeICallTablePath)" />-->
<!--</ItemGroup>-->
<MakeDir Directories="$(_WasmIntermediateOutputPath)" Condition="!Exists('$(_WasmIntermediateOutputPath)')" />
<ManagedToNativeGenerator
Assemblies="@(_WasmAssembliesInternal);$(_MscorlibPath)"
RuntimeIcallTableFile="$(_WasmRuntimeICallTablePath)"
IcallOutputPath="$(_WasmICallTablePath)"
PInvokeModules="@(_WasmPInvokeModules)"
PInvokeOutputPath="$(_WasmPInvokeTablePath)"
InterpToNativeOutputPath="$(_WasmInterpToNativeTablePath)">
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</ManagedToNativeGenerator>
</Target>
<Target Name="_WasmSelectRuntimeComponentsForLinking" DependsOnTargets="_MonoSelectRuntimeComponents" />
<Target Name="_GetNativeFilesForLinking" Returns="@(_WasmNativeFileForLinking)">
<Message Text="MicrosoftNetCoreAppRuntimePackRidNativeDir: $(MicrosoftNetCoreAppRuntimePackRidNativeDir)" Importance="High" />
<PropertyGroup>
<!-- FIXME: eh case -->
<_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-wasm.a</_WasmEHLib>
<!--<_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-js.a</_WasmEHLib>-->
<!--<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-js.a</_WasmEHLibToExclude>-->
<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-wasm.a</_WasmEHLibToExclude>
</PropertyGroup>
<ItemGroup>
<!-- order matters -->
<!--<_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" />-->
<!--<_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" />-->
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" />
<_WasmNativeFileForLinking
Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a"
Exclude="@(_MonoRuntimeComponentDontLink->'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)%(Identity)')" />
<_WasmNativeFileForLinking Condition="'$(_WasmEHLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLib)" />
<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" />
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++.a" />
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++abi.a" />
</ItemGroup>
</Target>
<!--<Target Name="_WasmWriteRspFilesForLinking" DependsOnTargets="_CheckEmccIsExpectedVersion">-->
<!--<PropertyGroup>-->
<!--<_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-wasm.a</_WasmEHLib>-->
<!--<_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-js.a</_WasmEHLib>-->
<!--<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-js.a</_WasmEHLibToExclude>-->
<!--<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-wasm.a</_WasmEHLibToExclude>-->
<!--</PropertyGroup>-->
<!--<ItemGroup>-->
<!--[> order matters <]-->
<!--<_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" />-->
<!--<_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" />-->
<!--<_WasmNativeFileForLinking-->
<!--Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a"-->
<!--Exclude="@(_MonoRuntimeComponentDontLink->'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)%(Identity)')" />-->
<!--<_WasmNativeFileForLinking Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLib)" />-->
<!--<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" />-->
<!--<_WasmExtraJSFile Include="@(Content)" Condition="'%(Content.Extension)' == '.js'" />-->
<!--</ItemGroup>-->
<!--<WriteLinesToFile Lines="@(_EmccLinkStepArgs)" File="$(_EmccLinkRsp)" Overwrite="true" WriteOnlyWhenDifferent="true" />-->
<!--<ItemGroup>-->
<!--<FileWrites Include="$(_EmccLinkRsp)" />-->
<!--</ItemGroup>-->
<!--</Target>-->
<!--<Target Name="_WasmLinkDotNet"-->
<!--Inputs="@(_WasmLinkDependencies);$(_WasiClangDefaultFlagsRsp);$(_WasiClangDefaultLinkFlagsRsp);$(_EmccLinkRsp)"-->
<!--Outputs="$(_WasmIntermediateOutputPath)dotnet.js;$(_WasmIntermediateOutputPath)dotnet.wasm"-->
<!--DependsOnTargets="_CheckEmccIsExpectedVersion;_WasmSelectRuntimeComponentsForLinking;_WasmCompileAssemblyBitCodeFilesForAOT;_WasmWriteRspFilesForLinking"-->
<!--Returns="@(FileWrites)" >-->
<!--<Message Text="Linking for initial memory %24(EmccInitialHeapSize)=$(EmccInitialHeapSize) bytes. Set this msbuild property to change the value." Importance="High" />-->
<!--<Message Text="Linking with emcc with $(EmccLinkOptimizationFlag). This may take a while ..." Importance="High" />-->
<!--<Message Text="Running emcc with @(_EmccLinkStepArgs->'%(Identity)', ' ')" Importance="Low" />-->
<!--<Exec Command='emcc "@$(_WasiClangDefaultFlagsRsp)" "@$(_WasiClangDefaultLinkFlagsRsp)" "@$(_EmccLinkRsp)"' EnvironmentVariables="@(EmscriptenEnvVars)" />-->
<!--<ItemGroup>-->
<!--<FileWrites Include="$(_WasmIntermediateOutputPath)dotnet.wasm" />-->
<!--<FileWrites Include="$(_WasmIntermediateOutputPath)dotnet.js" />-->
<!--<FileWrites Include="$(_WasmIntermediateOutputPath)dotnet.js.symbols" Condition="'$(WasmEmitSymbolMap)' == 'true'" />-->
<!--</ItemGroup>-->
<!--<ItemGroup>-->
<!--[> WasmOptConfigurationFlags property is set by reading from emcc-props.json <]-->
<!--<WasmOptConfigurationFlags Condition="'$(WasmOptConfigurationFlags)' != ''" Include="$(WasmOptConfigurationFlags)" />-->
<!--</ItemGroup>-->
<!--<Message Text="Stripping symbols from dotnet.wasm ..." Importance="High" Condition="'$(WasmNativeStrip)' == 'true'" />-->
<!--<Exec Command="wasm-opt$(_ExeExt) -enable-simd -enable-exception-handling @(WasmOptConfigurationFlags, ' ') -strip-dwarf "$(_WasmIntermediateOutputPath)dotnet.wasm" -o "$(_WasmIntermediateOutputPath)dotnet.wasm""-->
<!--Condition="'$(WasmNativeStrip)' == 'true'"-->
<!--IgnoreStandardErrorWarningFormat="true"-->
<!--EnvironmentVariables="@(EmscriptenEnvVars)" />-->
<!--</Target>-->
<UsingTask TaskName="EmitBundleObjectFiles" AssemblyFile="$(EmitBundleTasksAssemblyPath)" />
<Target Name="_GenerateAssemblyObjectFiles" Returns="@(_WasiObjectFilesForBundle)">
<!-- Get the file hashes of everything in @(_WasmBundleFiles), then pass it all to EmitBundleObjectFiles. This
will emit corresponding .o files for anything we don't already have on disk. -->
<PropertyGroup>
<_WasmAssembliesBundleObjectFile>$(_WasmIntermediateOutputPath)wasi_bundled_assemblies.o</_WasmAssembliesBundleObjectFile>
</PropertyGroup>
<GetFileHash Files="@(_WasmAssembliesInternal)">
<Output TaskParameter="Items" ItemName="WasmBundleAssembliesWithHashes" />
</GetFileHash>
<ItemGroup>
<WasmBundleAssembliesWithHashes Update="@(WasmBundleAssembliesWithHashes)">
<DestinationFile>$(_WasmIntermediateOutputPath)%(WasmBundleAssembliesWithHashes.Filename)%(WasmBundleAssembliesWithHashes.Extension).$([System.String]::Copy(%(WasmBundleAssembliesWithHashes.FileHash)).Substring(0, 8)).o</DestinationFile>
</WasmBundleAssembliesWithHashes>
</ItemGroup>
<!-- TODO make this incremental compilation -->
<EmitBundleObjectFiles
FilesToBundle="@(WasmBundleAssembliesWithHashes)"
ClangExecutable="$(WasiClang)"
BundleName="assemblies"
BundleFile="$(_WasmAssembliesBundleObjectFile)"
RegistrationCallbackFunctionName="mono_wasm_add_assembly"
/>
<ItemGroup>
<_WasiObjectFilesForBundle Include="$(_WasmAssembliesBundleObjectFile)" />
<_WasiObjectFilesForBundle Include="%(WasmBundleAssembliesWithHashes.DestinationFile)" />
</ItemGroup>
<!-- Clean up the bundle-objects dir - remove anything we no longer need -->
<ItemGroup>
<WasmBundleFileToDelete Include="$(_WasmIntermediateOutputPath)*.o" />
<WasmBundleFileToDelete Remove="$(_WasmAssembliesBundleObjectFile)" />
<WasmBundleFileToDelete Remove="%(WasmBundleAssembliesWithHashes.DestinationFile)" />
</ItemGroup>
<Delete Files="@(WasmBundleFileToDelete)" />
</Target>
<Target Name="_WasiLink">
<!--Inputs="@(_WasmNativeFileForLinking);@(_WasmAssembliesInternal);@(IntermediateAssembly)"-->
<!--Outputs="$(_WasmOutputFileName)">-->
<!-- Generate a file entrypoint_YourAssemblyName.c containing the dotnet_wasi_getentrypointassemblyname symbol.
This means we don't have to hardcode the assembly name in main.c -->
<PropertyGroup>
<_WasiGetEntrypointCFile>$(_WasmIntermediateOutputPath)entrypoint_$(WasmMainAssemblyFileName).c</_WasiGetEntrypointCFile>
</PropertyGroup>
<WriteLinesToFile File="$(_WasiGetEntrypointCFile)"
Overwrite="true"
Lines="const char* dotnet_wasi_getentrypointassemblyname() { return "$(WasmMainAssemblyFileName)"%3B }"
WriteOnlyWhenDifferent="true" />
<ItemGroup>
<!--<_WasmNativeFileForLinking Include="$(_WasiObjectFilesForBundle)" />-->
<!--<_WasmNativeFileForLinking Include="$(_WasiGetEntrypointCFile)" />-->
<FileWrites Include="$(_WasiGetEntrypointCFile)" />
<WasiAfterRuntimeLoadedDeclarations Include="@(WasiAfterRuntimeLoaded->'void %(Identity)();')" />
<WasiAfterRuntimeLoadedCalls Include="@(WasiAfterRuntimeLoaded->'%(Identity)();')" />
<_WasmRuntimePackSrcFile Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)src/*.c" />
</ItemGroup>
<!-- Invoke the WASI SDK clang binary to build the .wasm file -->
<ItemGroup>
<_WasiSdkLinkerFlags Include="--initial-memory=$(WasmInitialHeapSize)" />
<_WasiFilePathForFixup Include="$(_WasiGetEntrypointCFile)" />
<_WasiFilePathForFixup Include="@(_WasiObjectFilesForBundle)" />
<_WasiFilePathForFixup Include="@(_WasmNativeFileForLinking)" />
<_WasiFilePathForFixup Include="@(_WasmRuntimePackSrcFile)" />
<_WasiSdkClangArgs Condition="'$(OS)' == 'Windows_NT'" Include="$([System.String]::new(%(_WasiFilePathForFixup.Identity)).Replace('\', '/'))" />
<_WasiSdkClangArgs Condition="'$(OS)' != 'Windows_NT'" Include="@(_WasiFilePathForFixup)" />
<_WasiSdkClangArgs Include="@(_WasmCommonCFlags)" />
<_WasiSdkClangArgs Include=""-I%(_WasmCommonIncludePaths.Identity)"" />
<_WasiSdkClangArgs Include="--sysroot="$(WasiSdkRoot.Replace('\', '/'))/share/wasi-sysroot"" />
<_WasiSdkClangArgs Include="-I"$(MicrosoftNetCoreAppRuntimePackRidNativeDir.Replace('\', '/'))include"" />
<_WasiSdkClangArgs Include="-Wl,--export=malloc,--export=free,--export=__heap_base,--export=__data_end" />
<!-- keep in sync with src\mono\wasi\wasi.proj -->
<_WasiSdkClangArgs Include="-Wl,-z,stack-size=8388608,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman"/>
<_WasiSdkClangArgs Include="-Wl,-s" /> <!-- Strip debug symbols -->
<_WasiSdkClangArgs Include="@(_WasiSdkLinkerFlags -> '-Xlinker %(Identity)', ' ')" />
<_WasiSdkClangArgs Condition="'@(WasiAfterRuntimeLoadedDeclarations)' != ''"
Include="-D WASI_AFTER_RUNTIME_LOADED_DECLARATIONS="@(WasiAfterRuntimeLoadedDeclarations, ' ')"" />
<_WasiSdkClangArgs Condition="'@(WasiAfterRuntimeLoadedCalls)' != ''"
Include="-D WASI_AFTER_RUNTIME_LOADED_CALLS="@(WasiAfterRuntimeLoadedCalls, ' ')"" />
<_WasiSdkClangArgs Include="-o "$(_WasmOutputFileName.Replace('\', '/'))"" />
</ItemGroup>
<WriteLinesToFile Lines="@(_WasiSdkClangArgs)" File="$(_WasmIntermediateOutputPath)clang-compile.rsp" Overwrite="true" />
<!--<Message Importance="High" Text="Performing WASI SDK build: "$(WasiClang)" @(_WasiSdkClangArgs, ' ')" />-->
<Message Importance="High" Text="Performing WASI SDK build: "$(WasiClang)" @$(_WasmIntermediateOutputPath)clang-compile.rsp" />
<!--<Exec Command=""$(WasiClang)" @(_WasiSdkClangArgs, ' ')" />-->
<Exec Command=""$(WasiClang)" @$(_WasmIntermediateOutputPath)clang-compile.rsp" />
<!-- FIXME: this will be done by the bundler -->
<Copy SourceFiles="$(_WasmOutputFileName)" DestinationFolder="$(WasmAppDir)" />
<ItemGroup>
<FileWrites Include="$(_WasmOutputFileName)" />
</ItemGroup>
</Target>
<Target Name="_CompleteWasmBuildNative">
<ItemGroup>
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.wasm" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.js" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.worker.js" Condition="Exists('$(_WasmIntermediateOutputPath)dotnet.worker.js')" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.js.symbols" Condition="'$(WasmEmitSymbolMap)' == 'true' and Exists('$(_WasmIntermediateOutputPath)dotnet.js.symbols')" />
</ItemGroup>
</Target>
<Target Name="_GenerateDriverGenC" Condition="'$(_WasmShouldAOT)' != 'true'">
</Target>
<!--
*******************************
************ AOT **************
*******************************
-->
<Target Name="_WasmAotCompileApp" Condition="'$(_WasmShouldAOT)' == 'true'">
<PropertyGroup>
<!-- FIXME: do it once -->
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
</PropertyGroup>
<Error Condition="'@(_WasmAssembliesInternal)' == ''" Text="Item _WasmAssembliesInternal is empty" />
<Error Condition="'$(_IsToolchainMissing)' == 'true'"
Text="$(_ToolchainMissingErrorMessage) SDK is required for AOT'ing assemblies." />
<Error Condition="'$(_MonoAotCrossCompilerPath)' == '' or !Exists('$(_MonoAotCrossCompilerPath)')"
Text="Could not find AOT cross compiler at %24(_MonoAotCrossCompilerPath)=$(_MonoAotCrossCompilerPath)" />
<ItemGroup>
<MonoAOTCompilerDefaultAotArguments Include="no-opt" />
<MonoAOTCompilerDefaultAotArguments Include="static" />
<MonoAOTCompilerDefaultAotArguments Include="direct-icalls" />
<MonoAOTCompilerDefaultAotArguments Include="deterministic" />
<MonoAOTCompilerDefaultAotArguments Include="mattr=simd" Condition="'$(WasmEnableSIMD)' == 'true'" />
<MonoAOTCompilerDefaultProcessArguments Include="--wasm-exceptions" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />
<MonoAOTCompilerDefaultProcessArguments Include="--wasm-gc-safepoints" Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true'" />
<AotProfilePath Include="$(WasmAotProfilePath)"/>
</ItemGroup>
<ItemGroup>
<_AotInputAssemblies Include="@(_WasmAssembliesInternal)">
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
</_AotInputAssemblies>
<_WasmAssembliesInternal Remove="@(_WasmAssembliesInternal)" />
<_WasmAOTSearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)" />
<_WasmAOTSearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidDir)\lib\net8.0" />
</ItemGroup>
<ItemGroup>
<!-- Skip known-huge assemblies specified in csproj -->
<_AotInputAssemblies Condition="'%(Filename)' != '' and '@(_AotInputAssemblies->Metadata(`Filename`))' != '' and '@(_AOT_InternalForceInterpretAssemblies->Metadata(`Filename`))' != ''">
<AOT_InternalForceToInterpret>true</AOT_InternalForceToInterpret>
</_AotInputAssemblies>
</ItemGroup>
<PropertyGroup>
<!--<AOTMode Condition="'$(AOTMode)' == '' and '$(AOTProfilePath)' != ''">LLVMOnlyInterp</AOTMode>-->
<AOTMode Condition="'$(AOTMode)' == ''">LLVMOnlyInterp</AOTMode>
<_AOTCompilerCacheFile>$(_WasmIntermediateOutputPath)aot_compiler_cache.json</_AOTCompilerCacheFile>
</PropertyGroup>
<Message Text="AOT'ing @(_AotInputAssemblies->Count()) assemblies" Importance="High" />
<!-- Dedup -->
<PropertyGroup Condition="'$(WasmDedup)' == 'true'">
<_WasmDedupAssembly>$(_WasmIntermediateOutputPath)\aot-instances.dll</_WasmDedupAssembly>
</PropertyGroup>
<WriteLinesToFile Condition="'$(WasmDedup)' == 'true'" File="$(_WasmIntermediateOutputPath)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
<Csc
Condition="'$(WasmDedup)' == 'true'"
Sources="$(_WasmIntermediateOutputPath)\aot-instances.cs"
OutputAssembly="$(_WasmDedupAssembly)"
TargetType="library"
Deterministic="true"
References="@(ReferencePath)"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)" />
<ItemGroup Condition="'$(WasmDedup)' == 'true'">
<_AotInputAssemblies Include="$(_WasmDedupAssembly)">
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
</_AotInputAssemblies>
</ItemGroup>
<MonoAOTCompiler
CompilerBinaryPath="$(_MonoAotCrossCompilerPath)"
OutputDir="$(_WasmIntermediateOutputPath)"
Mode="$(AOTMode)"
OutputType="AsmOnly"
Assemblies="@(_AotInputAssemblies)"
AdditionalAssemblySearchPaths="@(_WasmAOTSearchPaths)"
UseAotDataFile="false"
AOTProfilePath="$(AOTProfilePath)"
AotModulesTablePath="$(_DriverGenCPath)"
UseLLVM="true"
Profilers="$(WasmProfilers)"
DisableParallelAot="$(DisableParallelAot)"
DedupAssembly="$(_WasmDedupAssembly)"
CacheFilePath="$(_AOTCompilerCacheFile)"
LLVMDebug="dwarfdebug"
LLVMPath="$(EmscriptenUpstreamBinPath)"
IntermediateOutputPath="$(_WasmIntermediateOutputPath)"
AotProfilePath="@(AotProfilePath)">
<Output TaskParameter="CompiledAssemblies" ItemName="_WasmAssembliesInternal" />
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</MonoAOTCompiler>
<ItemGroup>
<_BitcodeFile Include="%(_WasmAssembliesInternal.LlvmBitcodeFile)" />
<_BitcodeFile ObjectFile="$(_WasmIntermediateOutputPath)%(FileName).o" />
<!-- Add the skipped assemblies -->
<_WasmAssembliesInternal Include="@(_AotInputAssemblies->WithMetadataValue('AOT_InternalForceToInterpret', 'true'))" />
</ItemGroup>
</Target>
<!-- '$(ArchiveTests)' != 'true' is to skip on CI for now -->
<Target Name="_WasmStripAOTAssemblies" Condition="'$(_WasmShouldAOT)' == 'true' and '$(WasmStripAOTAssemblies)' == 'true' and '$(AOTMode)' != 'LLVMOnlyInterp' and '$(ArchiveTests)' != 'true'">
<PropertyGroup>
<_WasmStrippedAssembliesPath>$([MSBuild]::NormalizeDirectory($(_WasmIntermediateOutputPath), 'stripped-assemblies'))</_WasmStrippedAssembliesPath>
</PropertyGroup>
<ItemGroup>
<_AOTedAssemblies Include="@(_WasmAssembliesInternal)" />
<_WasmStrippedAssemblies
Include="@(_AOTedAssemblies)"
OriginalPath="%(_WasmAssembliesInternal.Identity)" />
</ItemGroup>
<!-- Run mono-cil-strip on the assemblies -->
<!-- TODO: replace this with a linker task -->
<MakeDir Directories="$(_WasmStrippedAssembliesPath)" />
<Exec Command='mono-cil-strip -q "%(_WasmStrippedAssemblies.OriginalPath)" "%(_WasmStrippedAssemblies.Identity)"' />
<ItemGroup>
<_WasmAssembliesInternal Remove="@(_WasmAssembliesInternal)" />
<_WasmAssembliesInternal Include="@(_WasmStrippedAssemblies)" />
</ItemGroup>
</Target>
</Project>