Skip to content

Commit

Permalink
[3.0] Contributor experience improvements (#2405)
Browse files Browse the repository at this point in the history
* Contributor experience improvements

* Document MSBuild USage
  • Loading branch information
Perksey authored Dec 31, 2024
1 parent 8dc7148 commit d7858d8
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ src/**/build/
# Silk.NET Build System
*.gen.sln
*.gen.txt
excluded-platforms.txt

# Silk.NET Website Generation Output
#/docs/
Expand Down
13 changes: 13 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"Clean",
"Compile",
"DeclareApi",
"DisablePlatforms",
"FinishRelease",
"Pack",
"Prerequisites",
"PushToNuGet",
Expand Down Expand Up @@ -134,6 +136,10 @@
"Release"
]
},
"DiscordWebhook": {
"type": "string",
"description": "Discord release announcement webhook"
},
"MsbuildProperties": {
"type": "array",
"description": "Extra properties passed to MSBuild commands",
Expand Down Expand Up @@ -161,6 +167,13 @@
"type": "string",
"description": "NuGet username"
},
"Platforms": {
"type": "array",
"description": "A list of platforms that DisablePlatforms should exclude from MSBuild usages, both inside and outside of NUKE. This can be reset by running DisablePlatforms with no platforms, or by deleting the excluded-platforms.txt file",
"items": {
"type": "string"
}
},
"SilkTouchAdditionalArgs": {
"type": "array",
"description": "Additional arguments to prepend to SilkTouch invocations",
Expand Down
11 changes: 11 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup>
<SilkExcludedPlatforms />
<SilkExcludedPlatforms Condition="Exists('$(MSBuildThisFileDirectory)excluded-platforms.txt')">$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)excluded-platforms.txt"))</SilkExcludedPlatforms>
<SilkExcludedPlatforms Condition="$([MSBuild]::IsOSPlatform('Linux'))">$(SilkExcludedPlatforms) ios tvos mac maccatalyst</SilkExcludedPlatforms>
<SilkAndroidDisabled Condition="$(SilkExcludedPlatforms.Contains('android'))">true</SilkAndroidDisabled>
<SilkiOSDisabled Condition="$(SilkExcludedPlatforms.Contains('ios'))">true</SilkiOSDisabled>
<SilkTvOSDisabled Condition="$(SilkExcludedPlatforms.Contains('tvos'))">true</SilkTvOSDisabled>
<SilkMacDisabled Condition="$(SilkExcludedPlatforms.Contains('mac'))">true</SilkMacDisabled>
<SilkMacCatalystDisabled Condition="$(SilkExcludedPlatforms.Contains('maccatalyst'))">true</SilkMacCatalystDisabled>
</PropertyGroup>
</Project>
12 changes: 11 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<Error Text="Native packages should have a version.txt file! Read documentation/for-contributors/build-system.md for more info."
Condition="'$(SilkNativePackage)' == 'true' and !Exists('$(SilkVersionTxtPath)')" />
<ItemGroup Condition="'$(SilkNativePackage)' == 'true'">
<None Include="$(MSBuildProjectDirectory)/runtimes/**/*" Pack="true" PackagePath="runtimes" />
<None Include="$(MSBuildProjectDirectory)/runtimes/**/*" Pack="true" PackagePath="runtimes" KeepMetadata="Link;CopyToOutputDirectory" CopyToOutputDirectory="PreserveNewest" />
<!-- bundled in the aar instead -->
<None Remove="$(MSBuildProjectDirectory)/runtimes/android*/**/*" Condition="'$(SilkNativeHasAndroidJars)' == 'true'" />
</ItemGroup>
Expand Down Expand Up @@ -260,4 +260,14 @@
Condition="'$(IncludeBuildOutput)' == 'false'" />
</ItemGroup>
</Target>

<!-- This is a bodge to make native packages feel like they're working when in repo i.e. with ProjectReferences -->
<Target Name="SilkProjectReferenceNatives" AfterTargets="GetCopyToOutputDirectoryItems" Condition="'$(RuntimeIdentifier)' != ''">
<ItemGroup>
<SilkThisRidItems Include="@(AllItemsFullPathWithTargetPath)"
Condition="$([System.String]::Copy('%(TargetPath)').Contains('$(RuntimeIdentifier)')) or $([System.String]::Copy('%(TargetPath)').Contains('$(RuntimeIdentifier.Split('-')[0])'))"
TargetPath="$([System.String]::Copy('%(Filename)%(Extension)'))" />
</ItemGroup>
<Copy SourceFiles="@(SilkThisRidItems)" DestinationFiles="@(SilkThisRidItems->'$(OutDir)%(TargetPath)')" />
</Target>
</Project>
57 changes: 57 additions & 0 deletions docs/for-contributors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# The Silk.NET Contributors Guide

Welcome to the Silk.NET project! We're so glad you want to help us create the best native interoperation experience that
.NET has ever seen.

This contributors guide covers many topics about Silk.NET's internals in great detail to help anyone pick up any part of
the codebase and hit the ground running.

## Table of Contents

- [Getting Started (you are here!)](#getting-started)
- [Build System](build-system.md)


## Getting Started

### Prerequisites

To get started, first clone Silk.NET using `git clone https://github.com/dotnet/Silk.NET --depth 1`. Your development
environment will need the latest production-ready .NET SDK, so make sure you've installed that from
[get.dot.net](https://get.dot.net). We also recommend installing NUKE using `dotnet tool install -g NUKE.GlobalTool` to
enable our auxiliary build commands/utilities, but this is optional and in fact can be accessed using the
`./build.sh`/`.\build.cmd`/`.\build.ps1` scripts in place of `nuke` in usages in this guide without installing the tool.

If you'd like to build and/or work with the mobile support in Silk.NET, you'll need to install the workloads using
`dotnet workload restore`. It is highly likely you need to prefix this with `sudo` on macOS and Linux. In addition,
you'll need to install the Android SDK with API 34 and API 35 support to ensure a successful build. Furthermore, on
macOS you will need Xcode installed with the iOS platform installed. Alternatively, if you don't want to work with our
mobile support, you can disable it for your local builds using `nuke disable-platforms --platforms android ios` for
example. The acceptable values for `--platforms` are any valid platform identifiers (i.e. right-hand side of the `-` of
a `TargetFramework`, without platform version information).

We automatically disable iOS support on Linux, as these workloads are only available on Windows and macOS. For more
information about the NUKE utilities, consult the [Build System](build-system.md) documentation or use `nuke --help`.

### Building from Source

Assuming you've got the prerequisites installed, `dotnet build`! Or `dotnet pack` to produce all the NuPkgs in
`artifacts/pkg`.

To learn more about the build system, see the [Build System](build-system.md) documentation. It is intentionally
designed to be as compatible as possible with the regular `dotnet build` system such that you can use the built-in
utilities of your favourite IDE.

### Regenerating Bindings

You can regenerate bindings using NUKE with `nuke regenerate-bindings`, but this isn't recommended. A full regeneration
of Silk.NET takes a long time and has the potential to touch the vast majority of the files that make up Silk.NET and/or
create loads of unrelated changes in your working tree. Instead, it is preferred to run SilkTouch manually using a
command like
`dotnet run --project sources/SilkTouch/SilkTouch/Silk.NET.SilkTouch.csproj -c Release -- generator.json -s Job1 -s Job2 ...`
where the values for the `-s` arguments are replaced with the job names (the keys of the `Jobs` dictionary in
`generator.json` e.g. `SDL`, `OpenGL`, etc).

For more information on SilkTocuh arguments, consult the [SilkTouch User Guide](../silktouch) or use
`dotnet run --project sources/SilkTouch/SilkTouch/Silk.NET.SilkTouch.csproj -- --help`.

24 changes: 24 additions & 0 deletions docs/for-contributors/build-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ library itself that are provided by a auxiliary build system implemented using t

## MSBuild Usage

### Target Frameworks

It is our goal to always target the latest LTS .NET release, and optionally multi-targeting to the next non-LTS version
thereafter. We also make use of the mobile frameworks e.g. `net8.0-android`, `net8.0-ios`, but these shall always be
guarded using properties such as `SilkAndroidDisabled`, `SilkiOSDisabled` etc which are set in `Directory.Build.props`,
which in turn check whether a file named `excluded-platforms.txt` exists and contains the target platform identifier.
This can be quickly modified by using the NUKE target `nuke disable-platforms`, which just writes to this file the
values provided for `--platforms`.

### Package READMEs

NuGet has recently added functionality to include a "README" rendered from Markdown on the front page of a package in
Expand Down Expand Up @@ -160,6 +169,21 @@ automatically, however in some cases there are specific linker flags required wh
The `.targets` injected can be seen at `eng/native/nuget/NativeNuGetPackage.targets` with the `TO_BE_REPLACED`
placeholders replaced in `Directory.Build.targets`.

Obviously, the native packages only work when consumed as a NuGet. However, we have a "best effort" attempt to copy the
appropriate native binary to the output directory for projects that `ProjectReference` a native binary, whether directly
or transitively. To make this work however, projects must include this:
```xml
<Project>
<PropertyGroup>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>
</Project>
```

This logic is defined in the `SilkProjectReferenceNatives` target in `Directory.Build.targets`.

We currently have not explored doing this for static linking (i.e. iOS) builds.

## Native Build Workflow

As mentioned previously, we build all of our native binaries in CI to ensure they come from a trusted source and also to
Expand Down
19 changes: 19 additions & 0 deletions eng/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

partial class Build : NukeBuild
Expand Down Expand Up @@ -112,4 +113,22 @@ out var releaseNotes
await SendWebhookAsync(version, versionSuffix, releaseNotes);
})
);

[Parameter(
$"A list of platforms that {nameof(DisablePlatforms)} should exclude from MSBuild usages, both "
+ $"inside and outside of NUKE. This can be reset by running {nameof(DisablePlatforms)} with no platforms, "
+ $"or by deleting the excluded-platforms.txt file."
)]
readonly string[]? Platforms;

Target DisablePlatforms =>
CommonTarget(x =>
x.Executes(
() =>
File.WriteAllText(
RootDirectory / "excluded-platforms.txt",
(Platforms ?? []).Join(' ')
)
)
);
}
1 change: 1 addition & 0 deletions sources/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file removed sources/Playground/libSDL3.dylib
Binary file not shown.
3 changes: 2 additions & 1 deletion sources/SDL/Native/Silk.NET.SDL.Native.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(SilkAndroidDisabled)' != 'true'">$(TargetFrameworks);net8.0-android</TargetFrameworks>
<SilkDescription>Native binaries for SDL3.</SilkDescription>
<SilkNativePackage>true</SilkNativePackage>
<SilkNativeHasAndroidJars>true</SilkNativeHasAndroidJars>
Expand Down
1 change: 1 addition & 0 deletions sources/SDL/SDL/Silk.NET.SDL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Core\Silk.NET.Core.csproj" />
<ProjectReference Include="..\Native\Silk.NET.SDL.Native.csproj" />
</ItemGroup>
<Import Project="..\..\Core\Core\Silk.NET.Core.targets" />
</Project>

0 comments on commit d7858d8

Please sign in to comment.