Skip to content

Commit 8a2d22d

Browse files
authored
[NativeAOT-LLVM] Add some version checking to build integration #3157 from SingleAccretion/Version-Checks
[NativeAOT-LLVM] Add some version checking to build integration
2 parents 4a6a4b6 + 3c6262e commit 8a2d22d

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,30 @@ The .NET Foundation licenses this file to you under the MIT license.
2121
<DirectPInvoke Include="libSystem.Globalization.Native" />
2222
<DirectPInvoke Include="libSystem.Native" />
2323
</ItemGroup>
24+
25+
<Target Name="ValidateEmsdk"
26+
Condition="'$(_targetOS)' == 'browser'">
27+
<!-- $(EMSDK) is typically set by the user and points to a standard emscripten layout. -->
28+
<!-- $(EmscriptenSdkToolsPath) comes from upstream mono workload and points to the dotnet/emsdk-style SDK layout. -->
29+
<!-- See https://github.com/dotnet/runtime/blob/main/src/mono/browser/build/EmSdkRepo.Defaults.props. -->
30+
<Error Text="Emscripten not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Emscripten and ensure the EMSDK environment variable points to the directory containing emsdk.bat"
31+
Condition="'$(EMSDK)' == '' and '$(EmscriptenSdkToolsPath)' == ''" />
32+
</Target>
33+
34+
<Target Name="ValidateWasiSdk"
35+
Condition="'$(_targetOS)' == 'wasi'">
36+
<Error Text="Wasi SDK not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Wasi SDK and ensure the WASI_SDK_PATH environment variable points to the directory containing share/wasi-sysroot"
37+
Condition="'$(WASI_SDK_PATH)' == ''" />
38+
39+
<!-- Verify the SDK version. We only issue a warning since it's **possible** a newer SDK might work. -->
40+
<PropertyGroup>
41+
<_ExpectedWasiSdkVersion>25.0</_ExpectedWasiSdkVersion>
42+
<_ActualWasiSdkVersion>?</_ActualWasiSdkVersion>
43+
<_ActualWasiSdkVersion Condition="Exists('$(WASI_SDK_PATH)/VERSION')">$([System.IO.File]::ReadAllText('$(WASI_SDK_PATH)/VERSION').Split()[0])</_ActualWasiSdkVersion>
44+
</PropertyGroup>
45+
46+
<Warning Text="Wasi SDK version $(_ActualWasiSdkVersion) is being used. This differs from the expected $(_ExpectedWasiSdkVersion) and might result in build or runtime failures."
47+
Condition="'$(_ExpectedWasiSdkVersion)' != '$(_ActualWasiSdkVersion)'" />
48+
</Target>
49+
2450
</Project>

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ The .NET Foundation licenses this file to you under the MIT license.
391391
</Target>
392392

393393
<Target Name="InitializeTheListOfLlvmObjects"
394-
AfterTargets="IlcCompile"
395-
BeforeTargets="CompileWasmObjects;LinkNativeLlvm">
394+
DependsOnTargets="IlcCompile">
396395
<ReadLinesFromFile File="$(NativeIntermediateOutputPath)$(TargetName).results.txt">
397396
<Output TaskParameter="Lines" ItemName="_IlcProducedFiles" />
398397
</ReadLinesFromFile>
@@ -406,28 +405,10 @@ The .NET Foundation licenses this file to you under the MIT license.
406405
</ItemGroup>
407406
</Target>
408407

409-
<Target Name="CheckWasmSdks">
410-
<!-- $(EMSDK) is typically set by the user and points to a standard emscripten layout. -->
411-
<!-- $(EmscriptenSdkToolsPath) comes from upstream mono workload and points to the dotnet/emsdk-style SDK layout. -->
412-
<!-- See https://github.com/dotnet/runtime/blob/main/src/mono/browser/build/EmSdkRepo.Defaults.props. -->
413-
<Error Text="Emscripten not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Emscripten and ensure the EMSDK environment variable points to the directory containing emsdk.bat"
414-
Condition="'$(EMSDK)' == '' and '$(EmscriptenSdkToolsPath)' == '' and '$(_targetOS)' == 'browser'" />
415-
416-
<!-- Verify the WASI SDK location and version (through indirect means...). -->
417-
<Error Text="Wasi SDK not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Wasi SDK and ensure the WASI_SDK_PATH environment variable points to the directory containing share/wasi-sysroot"
418-
Condition="'$(_targetOS)' == 'wasi' and '$(WASI_SDK_PATH)' == ''" />
419-
<Exec Command="&quot;$(WASI_SDK_PATH)/bin/wasm-component-ld&quot; --version" StandardOutputImportance="Low" ConsoleToMsBuild="true"
420-
Condition="'$(_targetOS)' == 'wasi'">
421-
<Output TaskParameter="ConsoleOutput" PropertyName="_WasmComponentLdVersion" />
422-
</Exec>
423-
<Warning Text="The WASI SDK version is too low. Please use WASI SDK 24 or newer."
424-
Condition="'$(_targetOS)' == 'wasi' and $([MSBuild]::VersionLessThan($(_WasmComponentLdVersion.Replace('wasm-component-ld ', '')), '0.5.6'))" />
425-
</Target>
426-
427408
<Target Name="CompileWasmObjects"
428409
Inputs="@(LlvmObjects)"
429410
Outputs="@(LlvmObjects->'%(NativeObject)')"
430-
DependsOnTargets="IlcCompile;CheckWasmSdks"
411+
DependsOnTargets="InitializeTheListOfLlvmObjects;ValidateEmsdk;ValidateWasiSdk"
431412
Condition="'$(NativeCodeGen)' == 'llvm'">
432413

433414
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(NativeBinary)))" />

src/coreclr/nativeaot/BuildIntegration/OverrideImportRuntimeIlcPackageTarget.targets

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<!-- NativeAOT-LLVM: override ImportRuntimeIlcPackageTarget to not depend on the SDK-provided ResolvedILCompilerPack item -->
33
<Target Name="ImportRuntimeIlcPackageTarget" Condition="'$(BuildingFrameworkLibrary)' != 'true' and '$(_targetArchitecture)' == 'wasm'" DependsOnTargets="$(ImportRuntimeIlcPackageTargetDependsOn)" BeforeTargets="Publish">
4-
<Error Condition="'@(PackageDefinitions)' == ''" Text="The PackageDefinitions ItemGroup is required for target ImportRuntimeIlcPackageTarget" />
4+
<Error Condition="'@(PackageDefinitions)' == ''"
5+
Text="The PackageDefinitions ItemGroup is required for target ImportRuntimeIlcPackageTarget" />
6+
7+
<PropertyGroup>
8+
<_IlcHostPackageVersion Condition="'%(PackageDefinitions.Name)' == '$(_hostPackageName)'">%(PackageDefinitions.Version)</_IlcHostPackageVersion>
9+
<_IlcRuntimePackageVersion Condition="'%(PackageDefinitions.Name)' == '$(_targetPackageName)'">%(PackageDefinitions.Version)</_IlcRuntimePackageVersion>
10+
</PropertyGroup>
11+
12+
<Warning Condition="'$(_IlcHostPackageVersion)' != '$(_IlcRuntimePackageVersion)'"
13+
Text="$(_hostPackageName) version ($(_IlcHostPackageVersion)) differs from the Microsoft.DotNet.ILCompiler.LLVM version ($(_IlcRuntimePackageVersion)). This will likely result in build or runtime failures." />
514

615
<PropertyGroup>
716
<IlcHostPackagePath Condition="'%(PackageDefinitions.Name)' == '$(_hostPackageName)'">%(PackageDefinitions.ResolvedPath)</IlcHostPackagePath>

0 commit comments

Comments
 (0)