Skip to content

[NativeAOT-LLVM] Add sample testing #3123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>

<PublishTrimmed>true</PublishTrimmed>
<SelfContained>true</SelfContained>
Expand Down
4 changes: 2 additions & 2 deletions samples/NativeLibrary/NativeLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<PublishTrimmed>true</PublishTrimmed>
Expand All @@ -15,7 +15,7 @@
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-*" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
<LinkerArg Include="-sEXPORTED_RUNTIME_METHODS=stringToNewUTF8" />
</ItemGroup>

Expand Down
62 changes: 35 additions & 27 deletions src/tests/nativeaot/SmokeTests/HelloWasm/PackagingTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,44 @@
</PropertyGroup>

<Target Name="PublishPackagingTestProject" BeforeTargets="BeforeBuild">
<ItemGroup>
<PackagingTestProject Include="PackagingTests/PackagingTestProject.csproj" />

<PackagingTestProject>
<TestOutputPath>$(OutputPath)%(FileName)</TestOutputPath>
</PackagingTestProject>
</ItemGroup>

<PropertyGroup>
<Test_Configuration>$(Configuration)</Test_Configuration>
<Test_TargetFramework>$(NetCoreAppCurrent)</Test_TargetFramework>
<Test_RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</Test_RuntimeIdentifier>
<Test_RestoreSource>$(ArtifactsShippingPackagesDir)</Test_RestoreSource>
<Test_RestorePackagesPath>$([MSBuild]::NormalizeDirectory('$(PackageOutputPath)', 'packages', '$(Configuration)'))</Test_RestorePackagesPath>
<Test_HostPackageRuntimeIdentifier>$(NETCoreSdkPortableRuntimeIdentifier.Replace('-$(BuildArchitecture)', '-$(IlcHostArch)'))</Test_HostPackageRuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<PackagingTestProject Include="PackagingTests/PackagingTestProject.csproj">
<BuildProperties>
Test_Configuration=$(Test_Configuration);
Test_TargetFramework=$(Test_TargetFramework);
Test_RuntimeIdentifier=$(Test_RuntimeIdentifier);
Test_PackageVersion=$(NetCoreAppCurrentVersion).0-*;
Test_RestoreSource=$(Test_RestoreSource);
Test_RestorePackagesPath=$(Test_RestorePackagesPath);
Test_HostPackageRuntimeIdentifier=$(Test_HostPackageRuntimeIdentifier);
_hostArchitecture=$(IlcHostArch); <!-- Override host package resolution in ILC targets. -->
</BuildProperties>
</PackagingTestProject>
<PackagingTestProject OutputPathRoot="$(OutputPath)%(FileName)/" />
<PackagingTestProject BuildProperties="Test_TestOutputPath=%(OutputPathRoot);%(BuildProperties)" />

<SampleProject Include="$(RepoRoot)samples/HelloWorld/HelloWorld.csproj;
$(RepoRoot)samples/NativeLibrary/NativeLibrary.csproj">
<BuildProperties>
Configuration=$(Test_Configuration);
RuntimeIdentifier=$(Test_RuntimeIdentifier);
</BuildProperties>
</SampleProject>
<SampleProject OutputPathRoot="%(RootDir)%(Directory)" />

<PackagingTestProject Include="@(SampleProject)"
Condition="'$(Test_HostPackageRuntimeIdentifier)' == '$(NETCoreSdkPortableRuntimeIdentifier)'" />
</ItemGroup>

<Error Condition="!Exists($(Test_RestoreSource))"
Text="The 'nativeaot.packages' subset must be built before building this project" />

Expand All @@ -35,33 +57,19 @@
before "./build nativeaot.packages" because the pkgproj targets do
not declare their inputs properly. -->
<RemoveDir Directories="$(Test_RestorePackagesPath)" />
<RemoveDir Directories="@(PackagingTestProject->'%(TestOutputPath)')" />

<PropertyGroup>
<PackagingTestProjectProperties>
Test_Configuration=$(Test_Configuration);
Test_TargetFramework=$(Test_TargetFramework);
Test_RuntimeIdentifier=$(Test_RuntimeIdentifier);
Test_PackageVersion=$(NetCoreAppCurrentVersion).0-*;
Test_RestoreSource=$(Test_RestoreSource);
Test_RestorePackagesPath=$(Test_RestorePackagesPath);
Test_HostPackageRuntimeIdentifier=$(NETCoreSdkPortableRuntimeIdentifier.Replace('-$(BuildArchitecture)', '-$(IlcHostArch)'));
_hostArchitecture=$(IlcHostArch); <!-- Override host package resolution in ILC targets. -->
</PackagingTestProjectProperties>
</PropertyGroup>
<RemoveDir Directories="%(PackagingTestProject.OutputPathRoot)bin;
%(PackagingTestProject.OutputPathRoot)obj" />

<MSBuild Projects="@(PackagingTestProject)"
Targets="Restore"
Properties="$(PackagingTestProjectProperties);
Test_TestOutputPath=%(TestOutputPath);
Properties="%(BuildProperties);
MSBuildRestoreSessionId=$([System.Guid]::NewGuid())" />

<MSBuild Projects="@(PackagingTestProject)"
Targets="Publish"
Properties="$(PackagingTestProjectProperties);
Test_TestOutputPath=%(TestOutputPath)" />
Properties="%(BuildProperties)" />

<Error Condition="!Exists('%(TestOutputPath)/bin/$(Test_Configuration)/$(Test_TargetFramework)/$(Test_RuntimeIdentifier)/publish/%(FileName).wasm')"
<Error Condition="!Exists('%(OutputPathRoot)/bin/$(Test_Configuration)/$(Test_TargetFramework)/$(Test_RuntimeIdentifier)/publish/%(FileName).wasm')"
Text="%(PackagingTestProject.FullPath) did not produce the expected native artifacts" />
</Target>
</Project>