-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
wasm.proj
216 lines (180 loc) · 11.3 KB
/
wasm.proj
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
<Project Sdk="Microsoft.Build.NoTargets">
<UsingTask TaskName="Microsoft.WebAssembly.Build.Tasks.RunWithEmSdkEnv" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<PropertyGroup>
<!-- FIXME: clean up the duplication with libraries Directory.Build.props -->
<PackageRID>browser-wasm</PackageRID>
<NativeBinDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'native', '$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)'))</NativeBinDir>
<ICULibDir>$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib'))</ICULibDir>
<WasmEnableES6 Condition="'$(WasmEnableES6)' == ''">false</WasmEnableES6>
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
<EmccCmd>emcc</EmccCmd>
<WasmObjDir>$(ArtifactsObjDir)wasm</WasmObjDir>
<_EmccDefaultsRspPath>$(NativeBinDir)src\emcc-default.rsp</_EmccDefaultsRspPath>
</PropertyGroup>
<Target Name="CheckEnv">
<Error Condition="'$(TargetArchitecture)' != 'wasm'" Text="Expected TargetArchitecture==wasm, got '$(TargetArchitecture)'"/>
<Error Condition="'$(TargetOS)' != 'Browser'" Text="Expected TargetOS==Browser, got '$(TargetOS)'"/>
<Error Condition="'$(EMSDK_PATH)' == ''" Text="The EMSDK_PATH environment variable should be set pointing to the emscripten SDK root dir."/>
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Runtime.ICU.Transport" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
<PackageReference Include="System.Runtime.TimeZoneData" PrivateAssets="all" Version="$(SystemRuntimeTimeZoneDataVersion)" GeneratePathProperty="true" />
</ItemGroup>
<UsingTask TaskName="PInvokeTableGenerator" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)"/>
<Target Name="BuildPInvokeTable" DependsOnTargets="CheckEnv;ResolveLibrariesFromLocalBuild">
<PropertyGroup>
<WasmPInvokeTablePath>$(ArtifactsObjDir)wasm\pinvoke-table.h</WasmPInvokeTablePath>
</PropertyGroup>
<ItemGroup>
<WasmPInvokeModule Include="libSystem.Native" />
<WasmPInvokeModule Include="libSystem.IO.Compression.Native" />
<WasmPInvokeModule Include="libSystem.Globalization.Native" />
<WasmPInvokeAssembly Include="@(LibrariesRuntimeFiles)" Condition="'%(Extension)' == '.dll' and '%(IsNative)' != 'true'" />
</ItemGroup>
<!-- Retrieve CoreLib's targetpath via GetTargetPath as it isn't binplaced yet. -->
<MSBuild Projects="$(CoreLibProject)"
Targets="GetTargetPath">
<Output TaskParameter="TargetOutputs" ItemName="WasmPInvokeAssembly" />
</MSBuild>
<MakeDir Directories="$(ArtifactsObjDir)wasm" />
<PInvokeTableGenerator Modules="@(WasmPInvokeModule)"
Assemblies="@(WasmPInvokeAssembly)"
OutputPath="$(WasmPInvokeTablePath)" />
</Target>
<UsingTask TaskName="GenerateWasmBundle"
AssemblyFile="$(WasmBuildTasksAssemblyPath)"/>
<Target Name="BundleTimeZones">
<PropertyGroup>
<TimeZonesDataPath>$(NativeBinDir)dotnet.timezones.blat</TimeZonesDataPath>
</PropertyGroup>
<GenerateWasmBundle
InputDirectory="$([MSBuild]::NormalizePath('$(PkgSystem_Runtime_TimeZoneData)', 'contentFiles', 'any', 'any', 'data'))"
OutputFileName="$(TimeZonesDataPath)" />
</Target>
<Target Name="GenerateEmccPropsAndRspFiles">
<ItemGroup>
<_EmccCommonFlags Include="-s ALLOW_MEMORY_GROWTH=1" />
<_EmccCommonFlags Include="-s NO_EXIT_RUNTIME=1" />
<_EmccCommonFlags Include="-s FORCE_FILESYSTEM=1" />
<_EmccCommonFlags Include="-s "EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']"" />
<_EmccCommonFlags Include="-s "EXPORTED_FUNCTIONS=['_putchar']"" />
<_EmccCommonFlags Include="--source-map-base http://example.com" />
<_EmccCommonFlags Include="-s STRICT_JS=1" />
<_EmccCommonFlags Include="-s MODULARIZE=1" Condition="'$(WasmEnableES6)' != 'false'" />
<_EmccCommonFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' != 'false'" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
<_EmccFlags Include="--profiling-funcs" />
<_EmccFlags Include="@(_EmccCommonFlags)" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<_EmccFlags Include="@(_EmccCommonFlags)" />
<_EmccFlags Include="-s USE_ZLIB=1" />
</ItemGroup>
<WriteLinesToFile File="$(_EmccDefaultsRspPath)"
Lines="@(_EmccFlags)"
WriteOnlyWhenDifferent="true"
Overwrite="true" />
<!-- Generate emcc-props.json -->
<RunWithEmSdkEnv Command="$(EmccCmd) --version"
ConsoleToMsBuild="true"
EmSdkPath="$(EMSDK_PATH)"
IgnoreStandardErrorWarningFormat="true">
<Output TaskParameter="ConsoleOutput" ItemName="_VersionLines" />
</RunWithEmSdkEnv>
<!-- we want to get the first line from the output, which has the version.
Rest of the lines are the license -->
<ItemGroup>
<_ReversedVersionLines Include="@(_VersionLines->Reverse())" />
</ItemGroup>
<PropertyGroup>
<_EmccVersionRaw>%(_ReversedVersionLines.Identity)</_EmccVersionRaw>
<_EmccVersionRegexPattern>^ *emcc \([^\)]+\) *([0-9\.]+).*\(([^\)]+)\)$</_EmccVersionRegexPattern>
<_EmccVersion>$([System.Text.RegularExpressions.Regex]::Match($(_EmccVersionRaw), $(_EmccVersionRegexPattern)).Groups[1].Value)</_EmccVersion>
<_EmccVersionHash>$([System.Text.RegularExpressions.Regex]::Match($(_EmccVersionRaw), $(_EmccVersionRegexPattern)).Groups[2].Value)</_EmccVersionHash>
<_EmccPropsJson>
<![CDATA[
{
"items": {
"EmccProperties": [
{ "identity": "RuntimeEmccVersion", "value": "$(_EmccVersion)" },
{ "identity": "RuntimeEmccVersionRaw", "value": "$(_EmccVersionRaw)" },
{ "identity": "RuntimeEmccVersionHash", "value": "$(_EmccVersionHash)" }
]
}
}
]]>
</_EmccPropsJson>
</PropertyGroup>
<Error Text="Failed to parse emcc version, and hash from the full version string: '$(_EmccVersionRaw)'"
Condition="'$(_EmccVersion)' == '' or '$(_EmccVersionHash)' == ''" />
<WriteLinesToFile File="$(NativeBinDir)src\emcc-props.json"
Lines="$(_EmccPropsJson)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
</Target>
<!-- This is a documented target that is invoked by developers in their innerloop work. -->
<Target Name="BuildWasmRuntimes"
AfterTargets="Build"
DependsOnTargets="GenerateEmccPropsAndRspFiles;BuildPInvokeTable;BundleTimeZones">
<ItemGroup>
<ICULibNativeFiles Include="$(ICULibDir)/libicuuc.a;
$(ICULibDir)/libicui18n.a" />
<ICULibFiles Include="$(ICULibDir)/*.dat" />
</ItemGroup>
<PropertyGroup>
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g;-Os;-s;-DDEBUG=1</CMakeConfigurationEmccFlags>
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz</CMakeConfigurationEmccFlags>
<CMakeBuildRuntimeConfigureCmd>emcmake cmake $(MSBuildThisFileDirectory)runtime -DCONFIGURATION_EMCC_FLAGS="$(CMakeConfigurationEmccFlags)" -DMONO_INCLUDES="$(MonoArtifactsPath)include/mono-2.0" -DMONO_OBJ_INCLUDES="$(MonoObjDir.TrimEnd('\/'))" -DICU_LIB_DIR="$(ICULibDir.TrimEnd('\/'))" -DMONO_ARTIFACTS_DIR="$(MonoArtifactsPath.TrimEnd('\/'))" -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/'))" -DSYSTEM_NATIVE_DIR="$(RepoRoot)src/libraries/Native/Unix/System.Native" -DEMSDK_PATH="$(EMSDK_PATH.TrimEnd('\/'))" -DSOURCE_DIR="$(MSBuildThisFileDirectory.TrimEnd('\/'))/runtime"</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" && call "$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env.bat'))" && $(CMakeBuildRuntimeConfigureCmd)</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(OS)' != 'Windows_NT'">bash -c 'source $(EMSDK_PATH)/emsdk_env.sh 2>&1 && $(CMakeBuildRuntimeConfigureCmd)'</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeCmd>cmake --build . --config $(Configuration)</CMakeBuildRuntimeCmd>
<CMakeBuildRuntimeCmd Condition="'$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" && call "$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env.bat'))" && $(CMakeBuildRuntimeCmd)</CMakeBuildRuntimeCmd>
<CMakeBuildRuntimeCmd Condition="'$(OS)' != 'Windows_NT'">bash -c 'source $(EMSDK_PATH)/emsdk_env.sh 2>&1 && $(CMakeBuildRuntimeCmd)'</CMakeBuildRuntimeCmd>
<SystemNativeDir>$(RepoRoot)src\libraries\Native\Unix\System.Native</SystemNativeDir>
</PropertyGroup>
<Copy SourceFiles="$(PInvokeTableFile)"
DestinationFolder="$(MonoObjDir)"
SkipUnchangedFiles="true" />
<Copy SourceFiles="runtime/driver.c;
runtime/pinvoke.c;
runtime/corebindings.c;
runtime/binding_support.js;
runtime/dotnet_support.js;
runtime/library_mono.js;
$(SystemNativeDir)\pal_random.js;"
DestinationFolder="$(NativeBinDir)src"
SkipUnchangedFiles="true" />
<Copy SourceFiles="runtime\pinvoke.h"
DestinationFolder="$(NativeBinDir)include\wasm"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(ICULibFiles);@(ICULibNativeFiles)"
DestinationFolder="$(NativeBinDir)"
SkipUnchangedFiles="true" />
<Exec Command="$(CMakeBuildRuntimeConfigureCmd)" WorkingDirectory="$(NativeBinDir)" />
<Exec Command="$(CMakeBuildRuntimeCmd)" WorkingDirectory="$(NativeBinDir)" />
<ItemGroup>
<IcuDataFiles Include="$(NativeBinDir)*.dat" />
<WasmSrcFiles Include="$(NativeBinDir)src\*.c;
$(NativeBinDir)src\*.js;
$(_EmccDefaultsRspPath);
$(NativeBinDir)src\emcc-props.json" />
<WasmHeaderFiles Include="$(NativeBinDir)include\wasm\*.h" />
</ItemGroup>
<Copy SourceFiles="$(NativeBinDir)dotnet.js;
$(NativeBinDir)dotnet.wasm;
$(NativeBinDir)dotnet.timezones.blat"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(IcuDataFiles);@(ICULibNativeFiles)"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(WasmSrcFiles)"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)src"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(WasmHeaderFiles)"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\wasm"
SkipUnchangedFiles="true" />
</Target>
</Project>