Skip to content

Start with a working Sidecar ​

Build a minimal endpoint that authenticates, registers an integer query, answers a request and retires cleanly. Keep the process lifecycle working before adding features; it is the foundation every later chapter assumes.

Version scope: these source-level examples target v2.0.0.alpha.14. Use the Plugin SDK for current Wasm plugin authoring.

Build an independent endpoint with real process bootstrap, authentication, registration, Int32 query, health, and cleanup. Read goal-first XSR design and establish this slice before UI or new behavior.

1. Pin inputs ​

Install .NET 10. NativeAOT also needs the target OS toolchain. Use A14 source and current docs main:

sh
git clone --branch v2.0.0.alpha.14 --depth 1 https://github.com/Nexa-MC/NexaCL.git
git clone https://github.com/Nexa-MC/PCLN-Docs.git
text
examples/sidecar/
├── Example.Sidecar.csproj    Protocol/Transport only
├── Program.cs               Small independent endpoint
├── SmokeHost.cs             Test-only Host peer
└── ContractRecipes.cs       Runnable codec/state/stream/UI recipes

NexaCLSourceRoot is an explicit source reference. Do not commit workstation paths or assume a same-named SDK NuGet package.

2. Run real-process IPC ​

From the docs repository, substitute an absolute source path:

sh
dotnet run --project examples/sidecar/Example.Sidecar.csproj -c Release -p:NexaCLSourceRoot=/absolute/path/to/NexaCL -- --self-test

Expected:

text
PASS: native IPC bootstrap, registration, empty snapshot, binary query, health, unregister and shutdown.

The test creates a randomized current-user endpoint, starts child mode, supplies a one-use 32-byte challenge over stdin, and authenticates real IPC. It proves protocol behavior, not production publisher authorization.

3. Understand every phase ​

StageBehaviorReason
ArgumentsPeer or explicit test modes onlyInvalid invocation fails
Bootstrapstdin proof and connectionAuthentication precedes frames
HELLO/WELCOMEVersion/features intersectionUnnegotiated features are unavailable
REGISTERexample.echo Query, I32→I32Explicit argument/result types
Empty snapshotBEGIN(0), ENDRequired even without State
READY/ACTIVATEEnter executionReady alone is not active authorization
QueryRequestActive, contract 1, I32Do not guess payload shape
QueryResultOriginal correlationCannot complete unrelated work
Health/retirementPreserve nonce, unregister, exitComplete long-lived behavior

The query is ordinal 1 in its kind/session, not a semantic hash or permanent global ID. The first State would independently be ID 1.

4. Run codec recipes ​

sh
dotnet run --project examples/sidecar/Example.Sidecar.csproj -c Release -p:NexaCLSourceRoot=/absolute/path/to/NexaCL -- --recipes

Recipes cover versioned DTO, correlation, State/Event, stream sequence/credit encoding, schema 2, caption, HookSignal, and invalid values. They do not claim actual stream backpressure, Host UI execution, or target grants.

5. Publish and test NativeAOT output ​

Linux x64:

sh
dotnet publish examples/sidecar/Example.Sidecar.csproj -c Release -r linux-x64 -p:PublishAot=true -p:NexaCLSourceRoot=/absolute/path/to/NexaCL -o out/sidecar
out/sidecar/Example.Sidecar --self-test
out/sidecar/Example.Sidecar --recipes

Use each platform's tools and win-x64/win-arm64/linux-arm64/osx-x64/osx-arm64 where appropriate. Renaming cannot convert architectures.

Rename verified native output to example.nsc (Windows starts from .exe); preserve Unix execute permission. Production discovery additionally needs .nsc.asc and trusted publisher admission: packaging/discovery.

6. Extend toward your goal ​

Keep the lifecycle skeleton and add one business contract with explicit argument/result/state. For concurrency keep one receive loop and a correlation-indexed worker table, not a reader per request.

Continue with lifecycle and the note-extension design.

Implementation references ​

Check your result ​

Run both self-test and codec recipes. Record their actual results, then repeat the process test with the NativeAOT executable for the platform you intend to distribute.

Site documentation: CC BY-SA 4.0. Imported SDK documents: Apache-2.0 as marked.