Skip to content
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

Build AOT demo project on CI #16108

Closed
wants to merge 6 commits into from
Closed
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: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"items": {
"type": "string",
"enum": [
"BuildAotDemo",
"BuildToNuGetCache",
"CiAzureLinux",
"CiAzureOSX",
Expand Down Expand Up @@ -110,6 +111,7 @@
"items": {
"type": "string",
"enum": [
"BuildAotDemo",
"BuildToNuGetCache",
"CiAzureLinux",
"CiAzureOSX",
Expand Down
21 changes: 20 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'PRNumber'
publishLocation: 'Container'

- job: Linux
pool:
vmImage: 'ubuntu-20.04'
Expand Down Expand Up @@ -207,3 +207,22 @@ jobs:
artifactName: 'Samples'
condition: succeeded()

- job: BuildAotDemo
pool:
vmImage: 'ubuntu-20.04'
variables:
SolutionDir: '$(Build.SourcesDirectory)'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 8.0 SDK'
inputs:
packageType: sdk
useGlobalJson: true
- task: CmdLine@2
displayName: 'Run Build'
inputs:
script: ./build.sh --target BuildAotDemo
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/artifacts/demo/'
ArtifactName: 'AotDemo'
1 change: 1 addition & 0 deletions build/EmbedXaml.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<AdditionalFiles Include="**\*.xaml" SourceItemGroup="AvaloniaXaml" />
</ItemGroup>
</Project>
29 changes: 28 additions & 1 deletion nukebuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ DotNetConfigHelper ApplySettingCore(DotNetConfigHelper c)
.AddProperty("SkipBuildingTests", "True");
return c;
}

DotNetBuildSettings ApplySetting(DotNetBuildSettings c, Configure<DotNetBuildSettings> configurator = null) =>
ApplySettingCore(c).Build.Apply(configurator);


DotNetPublishSettings ApplySetting(DotNetPublishSettings c, Configure<DotNetPublishSettings> configurator = null) =>
ApplySettingCore(c).Publish.Apply(configurator);
DotNetPackSettings ApplySetting(DotNetPackSettings c, Configure<DotNetPackSettings> configurator = null) =>
ApplySettingCore(c).Pack.Apply(configurator);

Expand Down Expand Up @@ -405,6 +408,30 @@ await Task.WhenAll(
file.GenerateCppHeader());
});

// Skip anything that might slow down PublishAot build.
// Runtime configuration will be assumed from the running OS.
Target BuildAotDemo => _ => _
.DependsOn(Clean, CompileNative)
.Executes(() =>
{
var outputDir = Parameters.ArtifactsDir / "demo" / "BindingDemo";
DotNetPublish(c => ApplySetting(c)
.SetOutput(outputDir)
// Extra property instead of PublishAot, see https://github.com/dotnet/sdk/issues/37228 why.
.AddProperty("EnablePublishAot", true)
.SetProject(RootDirectory.GlobFiles(@"**\BindingDemo.csproj").FirstOrDefault()
?? throw new InvalidOperationException($"Project BindingDemo doesn't exist"))
);
if (Parameters.Configuration != Parameters.ReleaseConfiguration)
{
foreach (var extraFile in Directory.EnumerateFiles(outputDir, "*.xml")
.Concat(Directory.EnumerateFiles(outputDir, "*.pdb"))
.Concat(Directory.EnumerateFiles(outputDir, "*.dbg")))
{
File.Delete(extraFile);
}
}
});

public static int Main() =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
Expand Down
10 changes: 10 additions & 0 deletions nukebuild/DotNetConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class DotNetConfigHelper
{
public DotNetBuildSettings Build;
public DotNetPublishSettings Publish;
public DotNetPackSettings Pack;
public DotNetTestSettings Test;

Expand All @@ -13,6 +14,11 @@ public DotNetConfigHelper(DotNetBuildSettings s)
Build = s;
}

public DotNetConfigHelper(DotNetPublishSettings s)
{
Publish = s;
}

public DotNetConfigHelper(DotNetPackSettings s)
{
Pack = s;
Expand All @@ -28,6 +34,7 @@ public DotNetConfigHelper AddProperty(string key, bool value) =>
public DotNetConfigHelper AddProperty(string key, string value)
{
Build = Build?.AddProperty(key, value);
Publish = Publish?.AddProperty(key, value);
Pack = Pack?.AddProperty(key, value);
Test = Test?.AddProperty(key, value);

Expand All @@ -37,6 +44,7 @@ public DotNetConfigHelper AddProperty(string key, string value)
public DotNetConfigHelper SetConfiguration(string configuration)
{
Build = Build?.SetConfiguration(configuration);
Publish = Publish?.SetConfiguration(configuration);
Pack = Pack?.SetConfiguration(configuration);
Test = Test?.SetConfiguration(configuration);
return this;
Expand All @@ -45,12 +53,14 @@ public DotNetConfigHelper SetConfiguration(string configuration)
public DotNetConfigHelper SetVerbosity(DotNetVerbosity verbosity)
{
Build = Build?.SetVerbosity(verbosity);
Publish = Publish?.SetVerbosity(verbosity);
Pack = Pack?.SetVerbosity(verbosity);
Test = Test?.SetVerbosity(verbosity);
return this;
}

public static implicit operator DotNetConfigHelper(DotNetBuildSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetPublishSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetPackSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetTestSettings s) => new DotNetConfigHelper(s);
}
2 changes: 1 addition & 1 deletion samples/BindingDemo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BindingDemo
{
public class App : Application
public partial class App : Application
{
public override void Initialize()
{
Expand Down
10 changes: 6 additions & 4 deletions samples/BindingDemo/BindingDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators>
<PublishAot Condition="'$(EnablePublishAot)' == 'True'">true</PublishAot>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Condition="'$(Configuration)' == 'Debug'" Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" />
<ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
</ItemGroup>
<Import Project="..\..\build\SampleApp.props" />
<Import Project="..\..\build\EmbedXaml.props" />
<Import Project="..\..\build\Rx.props" />
<Import Condition="'$(TargetFramework)'=='net461'" Project="..\..\build\NetFX.props" />
<Import Project="..\..\build\TrimmingEnable.props" />
<Import Project="..\..\build\ReferenceCoreLibraries.props" />
<Import Project="..\..\build\BuildTargets.targets" />
<Import Project="..\..\build\SourceGenerators.props" />
</Project>
4 changes: 2 additions & 2 deletions samples/BindingDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<TextBlock FontSize="16" Text="Multiple"/>
<ListBox ItemsSource="{Binding Items}" SelectionMode="Multiple" Selection="{Binding Selection}"/>
</StackPanel>
<ContentControl Content="{ReflectionBinding Selection.SelectedItems[0]}">
<ContentControl Content="{Binding Selection.SelectedItems[0]}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:TestItem">
<local:TestItemView></local:TestItemView>
Expand Down Expand Up @@ -126,7 +126,7 @@
</TabItem.Resources>
<StackPanel>
<!-- Tests for #10856 -->
<TextBlock Text="{local:GenericMarkupExtension, Value=Red, x:TypeArguments=Color}"/>
<TextBlock Text="{local:GenericMarkupExtension Value=Red, x:TypeArguments=Color}"/>
<TextBlock HorizontalAlignment="Left"
Text="{Binding $self.Background, Converter={StaticResource BrushConverter}}">
<TextBlock.Background>
Expand Down
14 changes: 3 additions & 11 deletions samples/BindingDemo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
using BindingDemo.ViewModels;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace BindingDemo
{
public class MainWindow : Window
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.DataContext = new MainWindowViewModel();
this.AttachDevTools();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
InitializeComponent();
DataContext = new MainWindowViewModel();
}
}
}
9 changes: 2 additions & 7 deletions samples/BindingDemo/TestItemView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@

namespace BindingDemo
{
public class TestItemView : UserControl
public partial class TestItemView : UserControl
{
public TestItemView()
{
this.InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;

namespace BindingDemo.ViewModels
{
public class DataAnnotationsErrorViewModel
{
[Phone]
[MaxLength(10)]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "MaxLength is safe here, as string implements ICollection.")]
public string PhoneNumber { get; set; }

[Range(0, 9)]
Expand Down
9 changes: 7 additions & 2 deletions samples/BindingDemo/ViewModels/IndeiErrorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public class IndeiErrorViewModel : ViewModelBase, INotifyDataErrorInfo

public IndeiErrorViewModel()
{
this.WhenAnyValue(x => x.Maximum, x => x.Value)
.Subscribe(_ => UpdateErrors());
PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(Maximum) || args.PropertyName == nameof(Value))
{
UpdateErrors();
}
};
}

public bool HasErrors
Expand Down
32 changes: 28 additions & 4 deletions samples/BindingDemo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Threading;
using MiniMvvm;
using Avalonia.Controls;
using Avalonia.Metadata;
using Avalonia.Controls.Selection;
using Avalonia.Threading;

namespace BindingDemo.ViewModels
{
Expand Down Expand Up @@ -54,8 +53,7 @@ public MainWindowViewModel()
}
});

CurrentTimeObservable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1))
.Select(x => DateTimeOffset.Now);
CurrentTimeObservable = new DispatcherTimerObservable(TimeSpan.FromMilliseconds(500));
}

public ObservableCollection<TestItem> Items { get; }
Expand Down Expand Up @@ -115,5 +113,31 @@ bool CanDo(object parameter)
{
return BooleanFlag;
}

private class DispatcherTimerObservable(TimeSpan interval) : IObservable<DateTimeOffset>
{
public IDisposable Subscribe(IObserver<DateTimeOffset> observer)
{
var timer = new DispatcherTimer();
timer.Tag = observer;
timer.Interval = interval;
timer.Tick += static (s, _) =>
{
var observer = (IObserver<DateTimeOffset>)((DispatcherTimer)s!).Tag!;
observer.OnNext(DateTimeOffset.Now);
};
timer.Start();
return new Disposable(timer, observer);
}

private class Disposable(DispatcherTimer timer, IObserver<DateTimeOffset> observer) : IDisposable
{
public void Dispose()
{
timer.Stop();
observer.OnCompleted();
}
}
}
}
}
9 changes: 2 additions & 7 deletions samples/Generators.Sandbox/Generators.Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="**\*.xaml"/>
<!-- Note this AdditionalFiles directive. -->
<AdditionalFiles Include="**\*.xaml" SourceItemGroup="AvaloniaXaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ReactiveUI.Validation" Version="3.0.22"/>
</ItemGroup>
Expand All @@ -23,6 +17,7 @@
<ProjectReference Include="..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj"/>
</ItemGroup>

<Import Project="..\..\build\BuildTargets.targets"/>
<Import Project="..\..\build\EmbedXaml.props"/>
<Import Project="..\..\build\SourceGenerators.props"/>
<Import Project="..\..\build\BuildTargets.targets"/>
</Project>
Loading