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

feat: upgrade to .NET 9 #165

Merged
merged 16 commits into from
Jan 5, 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 .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8
dotnet-version: 9
- name: initialize codeql
uses: github/codeql-action/init@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8
dotnet-version: 9
- name: package
run: |
cd src/js
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8
dotnet-version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
- name: cover
run: |
cd src/js
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/build-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Below is an example configuration, which will make Bootsharp name compiled modul
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<BootsharpName>backend</BootsharpName>
<BootsharpPackageDirectory>$(SolutionDir)</BootsharpPackageDirectory>
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/extensions/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Reference `Bootsharp.Inject` extension in the project configuration:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/extensions/file-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Install the NuGet package to C# project:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In `.csproj` file, set wasm runtime identifier and reference Bootsharp package:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Most simple types, such as numbers, booleans, strings, arrays (lists) and promis
| float | Number | ✔️ | ❌ |
| DateTime | Date | ✔️ | ❌ |

When a value of non-natively supported type is specified in an interop API, Bootsharp will attempt to de-/serialize it with [System.Text.JSON](https://learn.microsoft.com/en-us/dotnet/api/system.text.json?view=net-8.0) using fast source-generation mode. The whole process is encapsulated under the hood on both the C# and JavaScript sides, so you don't have to manually author generator hints or specify `[MarshallAs]` attributes for each value:
When a value of non-natively supported type is specified in an interop API, Bootsharp will attempt to de-/serialize it with [System.Text.JSON](https://learn.microsoft.com/en-us/dotnet/api/system.text.json) using fast source-generation mode. The whole process is encapsulated under the hood on both the C# and JavaScript sides, so you don't have to manually author generator hints or specify `[MarshallAs]` attributes for each value:

```csharp
public record User (long Id, string Name, DateTime Registered);
Expand Down
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"docs:preview": "vitepress preview"
},
"devDependencies": {
"typescript": "^5.6.2",
"@types/node": "^22.5.5",
"vitepress": "^1.3.4",
"typedoc-vitepress-theme": "^1.0.1",
"imgit": "^0.2.1"
"typescript": "5.7.2",
"@types/node": "22.10.5",
"vitepress": "1.5.0",
"typedoc-vitepress-theme": "1.1.1",
"imgit": "0.2.1"
}
}
2 changes: 1 addition & 1 deletion samples/minimal/cs/Minimal.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion samples/react/backend/Backend.Prime/Backend.Prime.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/react/backend/Backend.Prime/Options.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Backend.Prime;

public record Options(int Complexity, bool Multithreading);
public record Options (int Complexity, bool Multithreading);
2 changes: 1 addition & 1 deletion samples/react/backend/Backend.Prime/Prime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Backend.Prime;
// Implementation of the computer service that compute prime numbers.
// Injected in the application entry point assembly (Backend.WASM).

public class Prime(IPrimeUI ui) : IComputer
public class Prime (IPrimeUI ui) : IComputer
{
private static readonly SemaphoreSlim semaphore = new(0);
private readonly Stopwatch watch = new();
Expand Down
4 changes: 2 additions & 2 deletions samples/react/backend/Backend.WASM/Backend.WASM.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Specify custom name for the generated JavaScript module. -->
Expand All @@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="Bootsharp" Version="*-*"/>
<PackageReference Include="Bootsharp.Inject" Version="*-*"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/react/backend/Backend/Backend.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions samples/trimming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ To test and measure build size:
| .NET | Raw | Brotli |
|-------|-------|--------|
| 8.0.1 | 2,298 | 739 |
| 9.0.1 | 2,369 | 761 |
2 changes: 1 addition & 1 deletion samples/trimming/cs/Trimming.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<!-- Not embedding binaries to source module reduces build size by ~30%. -->
<BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
Expand Down
10 changes: 6 additions & 4 deletions samples/trimming/main.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import bootsharp, { Program } from "./cs/bin/bootsharp/index.mjs";
import { pathToFileURL } from "node:url";
import fs from "node:fs/promises";
import zlib from "node:zlib";
import util from "node:util";
import fs from "node:fs/promises";
import path from "node:path";

console.log(`Binary size: ${await measure("./cs/bin/bootsharp/bin")}KB`);
console.log(`Brotli size: ${await measure("./cs/bin/bootsharp/bro")}KB`);
Expand All @@ -13,13 +15,13 @@ await Promise.all([
]);

Program.log = console.log;
await bootsharp.boot({ root: "./bin", resources });
const root = pathToFileURL(path.resolve("./cs/bin/bootsharp/bin"));
await bootsharp.boot({ root, resources });

async function measure(dir) {
let size = 0;
for await (const entry of await fs.opendir(dir)) {
for await (const entry of await fs.opendir(dir))
size += (await fs.stat(`${entry.path}/${entry.name}`)).size;
}
return Math.ceil(size / 1024);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cs/.scripts/cover.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
dotnet test Bootsharp.Publish.Test/Bootsharp.Publish.Test.csproj /p:CollectCoverage=true /p:CoverletOutputFormat="json%2copencover" /p:ExcludeByAttribute=GeneratedCodeAttribute /p:CoverletOutput=$out /p:MergeWith=$json
reportgenerator "-reports:*/*.xml" "-targetdir:.cover" -reporttypes:HTML
python -m webbrowser http://localhost:3000
serve .cover
npx serve .cover
} finally {
rm .cover -r -force
}
4 changes: 2 additions & 2 deletions src/cs/Bootsharp.Common.Test/Bootsharp.Common.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.1"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 1 addition & 9 deletions src/cs/Bootsharp.Common.Test/InterfacesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

public class InterfacesTest
{
[Fact]
public void Records ()
{
// TODO: Remove once coverlet properly handles record coverage.
_ = new ExportInterface(default, default) with { Interface = typeof(int) };
_ = new ImportInterface(default) with { Instance = "" };
}

[Fact]
public void RegistersExports ()
{
var export = new ExportInterface(typeof(IBackend), default);
var export = new ExportInterface(typeof(IBackend), null);
Interfaces.Register(typeof(Backend), export);
Assert.Equal(typeof(IBackend), Interfaces.Exports[typeof(Backend)].Interface);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Common/Bootsharp.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyTitle>Bootsharp.Common</AssemblyTitle>
Expand Down
4 changes: 2 additions & 2 deletions src/cs/Bootsharp.Generate.Test/Bootsharp.Generate.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.11.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.1"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 3 additions & 3 deletions src/cs/Bootsharp.Inject.Test/Bootsharp.Inject.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand All @@ -12,9 +12,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.1"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/cs/Bootsharp.Inject/Bootsharp.Inject.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyTitle>Bootsharp.Inject</AssemblyTitle>
Expand All @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="Bootsharp.Common" Version="$(Version)"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0"/>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/cs/Bootsharp.Publish.Test/Bootsharp.Publish.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -12,10 +12,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.11.4"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="MSBuild.ProjectCreation" Version="13.0.0"/>
<PackageReference Include="xunit" Version="2.9.1"/>
<PackageReference Include="MSBuild.ProjectCreation" Version="14.0.0"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 4 additions & 4 deletions src/cs/Bootsharp.Publish/Bootsharp.Publish.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Bootsharp.Publish.Test"/>
<PackageReference Include="Microsoft.Build.Framework" Version="17.11.4" PrivateAssets="all"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.11.4" PrivateAssets="all"/>
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="8.0.0"/>
<PackageReference Include="Microsoft.Build.Framework" Version="17.12.6" PrivateAssets="all"/>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6" PrivateAssets="all"/>
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="9.0.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public void Patch ()
.Replace("import(", "import(/*@vite-ignore*//*webpackIgnore:true*/"), Encoding.UTF8);

File.WriteAllText(runtime, File.ReadAllText(runtime, Encoding.UTF8)
.Replace("pt('WebAssembly resource does not have the expected content type \"application/wasm\", so falling back to slower ArrayBuffer instantiation.')", "true")
.Replace("import(", "import(/*@vite-ignore*//*webpackIgnore:true*/"), Encoding.UTF8);

File.WriteAllText(native, File.ReadAllText(native, Encoding.UTF8)
Expand Down
9 changes: 9 additions & 0 deletions src/cs/Bootsharp.Publish/Pack/ModulePatcher/ModulePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ public void Patch ()
if (thread) PatchThreading();
if (embed) new InternalPatcher(dotnet, runtime, native).Patch();
if (trim) RemoveMaps();
RemoveWasmNag();
CopyInternals();
}

private void RemoveWasmNag ()
{
// Removes "WebAssembly resource does not have the expected content type..." warning.

File.WriteAllText(dotnet, File.ReadAllText(dotnet, Encoding.UTF8)
.Replace("w('WebAssembly resource does not have the expected content type \"application/wasm\", so falling back to slower ArrayBuffer instantiation.')", "true"));
}

private void PatchThreading ()
{
// Overprotective browser-only assert breaks unit testing:
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Bootsharp/Bootsharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyTitle>Bootsharp</AssemblyTitle>
Expand Down
Loading
Loading