Skip to content
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
1 change: 0 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default defineConfig({
{ text: "Interop Instances", link: "/guide/interop-instances" },
{ text: "Preferences", link: "/guide/preferences" },
{ text: "Build Configuration", link: "/guide/build-config" },
{ text: "Sideloading Binaries", link: "/guide/sideloading" },
{ text: "NativeAOT-LLVM", link: "/guide/llvm" }
]
},
Expand Down
22 changes: 9 additions & 13 deletions docs/guide/build-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

Build and publish related options are configured in `.csproj` file via MSBuild properties.

| Property | Default | Description |
|----------------------------|------------|--------------------------------------------------------------|
| BootsharpName | bootsharp | Name of the generated JavaScript module. |
| BootsharpEmbedBinaries | true | Whether to embed binaries to the JavaScript module file. |
| BootsharpBundleCommand | npx rollup | The command to bundle generated JavaScrip solution. |
| BootsharpPublishDirectory | /bin | Directory to publish generated JavaScript module. |
| BootsharpTypesDirectory | /types | Directory to publish type declarations. |
| BootsharpBinariesDirectory | /bin | Directory to publish binaries when `EmbedBinaries` disabled. |
| BootsharpPackageDirectory | / | Directory to publish `package.json` file. |

Below is an example configuration, which will make Bootsharp name compiled module "backend" (instead of the default "bootsharp"), publish the module under solution directory root (instead of "/bin") and disable binaries embedding in favor of publishing them under "public/bin" directory one level above the solution root:
| Property | Default | Description |
|----------------------------|------------------|---------------------------------------------------|
| BootsharpName | bootsharp | Name of the generated JavaScript module. |
| BootsharpPublishDirectory | /bin/bootsharp | Directory to publish generated JavaScript module. |
| BootsharpBinariesDirectory | publish-dir/bin | Directory to publish binaries. |
| BootsharpPackageDirectory | project-dir | Directory to publish `package.json` file. |

Below is an example configuration, which will make Bootsharp name the compiled module "backend" (instead of the default "bootsharp"), publish the `package.json` under the solution directory root and emit the runtime binaries into a "public/bin" directory one level above the solution root:

```xml
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -22,7 +19,6 @@ Below is an example configuration, which will make Bootsharp name compiled modul
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<BootsharpName>backend</BootsharpName>
<BootsharpPackageDirectory>$(SolutionDir)</BootsharpPackageDirectory>
<BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
<BootsharpBinariesDirectory>$(SolutionDir)../public/bin</BootsharpBinariesDirectory>
</PropertyGroup>

Expand All @@ -45,7 +41,7 @@ To enable globalization, explicitly disable invariant globalization in your proj
</PropertyGroup>
```

When invariant globalization is disabled, Bootsharp will automatically include the ICU files emitted by the .NET WASM build and configure the runtime accordingly. This works for both embedded and sideloaded binaries.
When invariant globalization is disabled, Bootsharp will automatically include the ICU files emitted by the .NET WASM build and configure the runtime accordingly.

Bootsharp supports the following globalization modes:

Expand Down
10 changes: 2 additions & 8 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ Run following command under the solution root:
dotnet publish
```

— which will produce `bin/bootsharp` directory with the following content:

| Name | Type | Description |
|--------------|--------|-----------------------------------------------------------|
| types | folder | Contains type declarations for the authored interop APIs. |
| index.mjs | file | The compiled ES module with embedded binaries. |
| package.json | file | NPM package manifest for convenient importing. |
— which will produce a `bin/bootsharp` directory with the compiled module and a `package.json` next to the `.csproj`.

::: tip
When publishing in `Release` (default for `dotnet publish`), Bootsharp automatically enables the [NativeAOT-LLVM](/guide/llvm) compiler, speed-focused WASM optimization, aggressive trimming, and an extra Binaryen pass when `wasm-opt` is available.
Expand Down Expand Up @@ -110,7 +104,7 @@ console.log(`Hello ${Program.getBackendName()}!`);
Program.onMainInvoked.subscribe(console.log);

// Initializing dotnet runtime and invoking entry point.
await bootsharp.boot();
await bootsharp.boot("/bin");

// Invoking 'Program.GetBackendName' C# method.
console.log(`Hello ${Program.getBackendName()}!`);
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Bootsharp will automatically build and bundle the JavaScript package when publis
import bootsharp, { Backend, Frontend } from "backend";

// Boot C# WASM module.
await boosharp.boot();
await bootsharp.boot("/bin");

// Subscribe to C# event.
Frontend.onUserChanged.subscribe(updateUserUI);
Expand Down
36 changes: 0 additions & 36 deletions docs/guide/sideloading.md

This file was deleted.

17 changes: 10 additions & 7 deletions docs/scripts/api.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# https://typedoc-plugin-markdown.org/themes/vitepress/quick-start

DOCS_DIR=$(cd "$(dirname "$0")/.." && pwd)
JS_DIR=$(cd "$DOCS_DIR/../src/js" && pwd)

echo '{
"entryPoints": [
"../src/js/src/index.ts"
"src/index.mts"
],
"tsconfig": "../src/js/tsconfig.json",
"out": "api",
"tsconfig": "tsconfig.json",
"out": "../../docs/api",
"name": "Bootsharp",
"readme": "none",
"githubPages": false,
Expand All @@ -17,8 +20,8 @@ echo '{
"title.memberPage": "{name}",
},
"plugin": ["typedoc-plugin-markdown", "typedoc-vitepress-theme"]
}' > typedoc.json
}' > "$JS_DIR/typedoc.json"

typedoc
sed -i -z "s/API Reference/API Reference\nAuto-generated with [typedoc-plugin-markdown](https:\/\/typedoc-plugin-markdown.org)./" api/index.md
rm typedoc.json
(cd "$JS_DIR" && NODE_PATH="$DOCS_DIR/node_modules" "$DOCS_DIR/node_modules/.bin/typedoc" --skipErrorChecking)
sed -i -z "s/API Reference/API Reference\nAuto-generated with [typedoc-plugin-markdown](https:\/\/typedoc-plugin-markdown.org)./" "$DOCS_DIR/api/index.md"
rm "$JS_DIR/typedoc.json"
2 changes: 1 addition & 1 deletion samples/bench/bootsharp/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function init() {
Imported.getNumber = getNumber;
Imported.getStruct = getStruct;

await bootsharp.boot();
await bootsharp.boot(import.meta.resolve("./bin/bootsharp/bin"));

return { ...Exported };
}
15 changes: 15 additions & 0 deletions samples/bench/bootsharp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bootsharp",
"type": "module",
"exports": {
".": "./bin/bootsharp/index.mjs"
},
"browser": {
"node:fs": false,
"node:url": false,
"node:path": false,
"node:module": false,
"node:crypto": false,
"node:process": false
}
}
2 changes: 1 addition & 1 deletion samples/minimal/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Minimal example on using Bootsharp in web browsers and popular JavaScript runtimes.

- Run `dotnet publish cs`;
- Run `node main.mjs` to test in [Node](https://nodejs.org);
- Run `node main.mjs` to test in [Node](https://nodejs.org) (blocker: https://github.com/elringus/bootsharp/pull/203);
- Run `deno run main.mjs` to test in [Deno](https://deno.com);
- Run `bun main.mjs` to test in [Bun](https://bun.sh);
- Run an HTML server (eg, `npx serve`) to test in browser.
2 changes: 1 addition & 1 deletion samples/minimal/cs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public static partial class Program
{
[Export] // Used in JS as Program.onMainInvoked.subscribe(...)
public static event Action<string>? OnMainInvoked;
public static event Action<string> OnMainInvoked;

public static void Main ()
{
Expand Down
15 changes: 15 additions & 0 deletions samples/minimal/cs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bootsharp",
"type": "module",
"exports": {
".": "./bin/bootsharp/index.mjs"
},
"browser": {
"node:fs": false,
"node:url": false,
"node:path": false,
"node:module": false,
"node:crypto": false,
"node:process": false
}
}
2 changes: 1 addition & 1 deletion samples/minimal/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Program.getFrontendName = () =>
Program.onMainInvoked.subscribe(console.log);

// Initializing dotnet runtime and invoking entry point.
await bootsharp.boot();
await bootsharp.boot(import.meta.resolve("./cs/bin/bootsharp/bin"));

// Invoking 'Program.GetBackendName' C# method.
console.log(`Hello ${Program.getBackendName()}!`);
2 changes: 0 additions & 2 deletions samples/react/backend/Backend.WASM/Backend.WASM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<BootsharpName>backend</BootsharpName>
<!-- Publish module's package.json file under solution folder. -->
<BootsharpPackageDirectory>$(SolutionDir)</BootsharpPackageDirectory>
<!-- Don't embed the C# solution binaries to the JavaScript module. -->
<BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
<!-- Publish the binaries to the React public directory for deployment. -->
<BootsharpBinariesDirectory>$(SolutionDir)../public/bin</BootsharpBinariesDirectory>
<!-- Enable multi-threaded mode to run CPU-intensive tasks on worker threads. -->
Expand Down
6 changes: 3 additions & 3 deletions samples/trimming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ To test and measure build size:

| Bootsharp | Raw | Brotli |
|-------------|-------|--------|
| 0.1 .NET 8 | 2,298 | 739 |
| 0.7 .NET 9 | 1,737 | 518 |
| 0.8 .NET 10 | 1,610 | 482 |
| 0.1 .NET 8 | 2,010 | 662 |
| 0.7 .NET 9 | 1,449 | 441 |
| 0.8 .NET 10 | 1,322 | 405 |
2 changes: 0 additions & 2 deletions samples/trimming/cs/Trimming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<!-- Not embedding binaries to source module reduces build size by ~30%. -->
<BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions samples/trimming/cs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bootsharp",
"type": "module",
"exports": {
".": "./bin/bootsharp/index.mjs"
},
"browser": {
"node:fs": false,
"node:url": false,
"node:path": false,
"node:module": false,
"node:crypto": false,
"node:process": false
}
}
17 changes: 5 additions & 12 deletions samples/trimming/main.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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";
Expand All @@ -8,15 +7,8 @@ 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`);

const resources = { ...bootsharp.resources };
await Promise.all([
fetchBro(resources.wasm),
...resources.assemblies.map(fetchBro)
]);

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

async function measure(dir) {
let size = 0;
Expand All @@ -25,7 +17,8 @@ async function measure(dir) {
return Math.ceil(size / 1024);
}

async function fetchBro(resource) {
const bro = await fs.readFile(`./cs/bin/bootsharp/bro/${resource.name}.br`);
resource.content = await util.promisify(zlib.brotliDecompress)(bro);
async function loadBro(name) {
const bro = await fs.readFile(`./cs/bin/bootsharp/bro/${name}.br`);
const buf = await util.promisify(zlib.brotliDecompress)(bro);
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
2 changes: 1 addition & 1 deletion src/cs/Bootsharp.Publish.Test/Pack/BindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ class JSExported {
get getImportedSerialized() { return this.getImportedSerializedHandler; }
};
export const Exported = {
broadcastChangedSerialized(_id, arg1, arg2) { instances.export(_id, id => new JSExported(id)).broadcastChanged(instances.export(arg1, id => new JSExported(id)), deserialize(arg2, Info)); }
broadcastChangedSerialized: (_id, arg1, arg2) => instances.export(_id, /* v8 ignore next -- @preserve */ id => new JSExported(id)).broadcastChanged(instances.export(arg1, /* v8 ignore next -- @preserve */ id => new JSExported(id)), deserialize(arg2, Info))
};
""");
}
Expand Down
7 changes: 0 additions & 7 deletions src/cs/Bootsharp.Publish.Test/Pack/DeclarationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ public class DeclarationTest : PackTest
{
protected override string TestedContent => GeneratedDeclarations;

[Fact]
public void ImportsEventTypes ()
{
Execute();
Contains("""import type { EventBroadcaster, EventSubscriber } from "./event";""");
}

[Fact]
public void DeclaresNamespace ()
{
Expand Down
11 changes: 3 additions & 8 deletions src/cs/Bootsharp.Publish.Test/Pack/PackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ public class PackTest : TaskTest
protected string MockDotNetContent { get; } = "MockDotNetContent";
protected string MockRuntimeContent { get; } = "MockRuntimeContent";
protected string MockNativeContent { get; } = "MockNativeContent";
protected string GeneratedBindings => ReadProjectFile("bindings.g.js");
protected string GeneratedDeclarations => ReadProjectFile("bindings.g.d.ts");
protected string GeneratedResources => ReadProjectFile("resources.g.js");
protected string GeneratedDotNetModule => ReadProjectFile("dotnet.g.js");
protected string GeneratedRuntimeModule => ReadProjectFile("dotnet.runtime.g.js");
protected string GeneratedNativeModule => ReadProjectFile("dotnet.native.g.js");
protected string GeneratedBindings => ReadProjectFile("generated/bindings.g.mjs");
protected string GeneratedDeclarations => ReadProjectFile("generated/bindings.g.d.mts");
protected string GeneratedResources => ReadProjectFile("generated/resources.g.mjs");

public PackTest ()
{
Expand Down Expand Up @@ -44,9 +41,7 @@ protected override void AddAssembly (string assemblyName, params MockSource[] so
InspectedDirectory = Project.Root,
EntryAssemblyName = "System.Runtime.dll",
BuildEngine = Engine,
EmbedBinaries = false,
Globalization = false,
Threading = false,
LLVM = false,
Debug = false
};
Expand Down
35 changes: 0 additions & 35 deletions src/cs/Bootsharp.Publish.Test/Pack/PatcherTest.cs

This file was deleted.

Loading
Loading