You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable --native-aot flag during spacetime init and spacetime publish for NativeAOT-LLVM support (#4672)
# Description of Changes
Adds `--native-aot` flag to `spacetime init` command for creating
NativeAOT-LLVM enabled C# projects. This automatically adds the required
LLVM package references to the generated `.csproj` file and sets
`"native-aot": true` in `spacetime.json`.
This also adds `--native-aot` flag to `spacetime publish`. This is
optional because the developer will still need to add the required LLVM
package references to their `.csproj` file, and the provided
instructions also include adding `"native-aot": true` to their
`spacetime.json` which will already apply the flag.
# API and ABI breaking changes
None.
# Expected complexity level and risk
1 (Low). Adds new optional flag to init command and post-processing of
generated .csproj files.
# Testing
- [X] Verified `spacetime init --lang csharp --native-aot` creates
projects with required LLVM package references
- [X] Confirmed `spacetime.json` is generated with `"native-aot": true`
- [X] Tested publish command works with both `--native-aot` flag and
`spacetime.json` configuration
---------
Signed-off-by: Ryan <r.ekhoff@clockworklabs.io>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
# Converting a SpacetimeDB 2.0.x project to use NativeAOT-LLVM
1
+
# Using NativeAOT-LLVM with SpacetimeDB C# Modules
2
2
3
-
This guide provides instructions on taking an existing C# module that targets the public-released SpacetimeDB CLI, and guides you through the necessary steps to enable `NativeAOT-LLVM` use.
3
+
This guide provides instructions for enabling NativeAOT-LLVM compilation for C# SpacetimeDB modules, which can provide performance improvements.
4
4
5
5
## Overview
6
-
In order to use `NativeAOT-LLVM` on a C# module, we'll need to set the `EXPERIMENTAL_WASM_AOT` environment variable to `1` which SpacetimeDB will check during publishing of a module.
7
-
For the module to work, we'll also need the `NuGet.Config` and `.csproj` files with the required package sources and references.
8
6
9
-
### Prerequisites:
7
+
NativeAOT-LLVM compiles C# modules to native WebAssembly (WASM) instead of using the Mono runtime.
8
+
9
+
> [!WARNING]
10
+
> This is currently only supported for Windows server modules and is experimental.
11
+
12
+
## Prerequisites
13
+
10
14
-**.NET SDK 8.x** (same version used by SpacetimeDB)
This should be a `NuGet.Config` placed in the root directory of your module folder (next to the `.csproj`). You can simply add the above line to the `packageSources` of your existing file, or if you need to create a minimal one, you can use:
- Creates a C# project with the required package references
60
+
- Generates a `spacetime.json` with `"native-aot": true`
61
+
- Configures the project for NativeAOT-LLVM compilation
62
+
63
+
## Converting an Existing Project
64
+
65
+
1.**Update spacetime.json**
66
+
Add `"native-aot": true` to your `spacetime.json`:
67
+
```json
68
+
{
69
+
"module": "your-module-name",
70
+
"native-aot": true
71
+
}
72
+
```
73
+
74
+
**Note:** Once `spacetime.json` has `"native-aot": true`, you can simply run `spacetime publish` without the `--native-aot` flag. The CLI will automatically detect the configuration and use NativeAOT compilation.
75
+
76
+
2.**Ensure NuGet feed is configured**
77
+
NativeAOT-LLVM packages come from **dotnet-experimental**. Add to `NuGet.Config`:
After completing either the **Creating a New NativeAOT Project** or **Converting an Existing Project** steps above, you can publish your module normally:
122
+
123
+
```
124
+
# From your project directory
125
+
spacetime publish your-database-name
126
+
```
127
+
128
+
If you have `"native-aot": true` in your `spacetime.json`, the CLI will automatically detect this and use NativeAOT compilation. Alternatively, you can use:
129
+
130
+
```
131
+
spacetime publish --native-aot your-database-name
132
+
```
133
+
134
+
The CLI will display "Using NativeAOT-LLVM compilation (experimental)" when NativeAOT is enabled.
95
135
96
136
## Troubleshooting
97
137
98
138
### Package source mapping enabled
99
-
If you have **package source mapping** enabled in `NuGet.Config`, you must add mappings for the LLVM packages or restores will fail.
100
-
Place the following in `NuGet.Config` inside the `configuration` section:
139
+
If you have **package source mapping** enabled in `NuGet.Config`, add mappings for the LLVM packages:
140
+
101
141
```xml
102
142
<packageSourceMapping>
103
143
<packageSourcekey="bsatn-runtime">
@@ -119,6 +159,16 @@ Place the following in `NuGet.Config` inside the `configuration` section:
119
159
### wasi-experimental workload install fails
120
160
If the CLI cannot install the `wasi-experimental` workload automatically, install it manually:
121
161
122
-
```powershell
162
+
```
123
163
dotnet workload install wasi-experimental
124
164
```
165
+
166
+
### Duplicate PackageReference warning
167
+
You may see a `NU1504` warning about duplicate `PackageReference` items. This is expected and non-blocking.
168
+
169
+
### Code generation failed
170
+
If you see errors like "Code generation failed for method", ensure:
171
+
1. You're using `SpacetimeDB.Runtime` version 2.0.4 or newer
172
+
2. All required package references are in your `.csproj`
173
+
3. The `dotnet-experimental` feed is configured in `NuGet.Config`
0 commit comments