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
74 changes: 74 additions & 0 deletions sdk_v2/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,80 @@ The **C++ wrapper header** (`foundry_local_cpp.h`) stays C++17-consumable becaus
C++ consumers need to include it from any toolchain. The addon happily includes a C++17
header from a C++20 TU.

### 3.4 Native runtime install (ORT / ORT-GenAI via NuGet)

`npm install` runs [`script/install-native.cjs`](script/install-native.cjs) as an install
lifecycle step, which downloads the ONNX Runtime and ORT-GenAI native binaries from NuGet and stages
them into `prebuilds/<platform>-<arch>/`. Three modes are supported:

- **`http` (default)** — talks to the NuGet v3 HTTP protocol directly (service index ->
`PackageBaseAddress` -> `.nupkg`) with Node's built-in `https` module. No external tools
required. Feeds are queried anonymously; use `dotnet` or `nuget` mode for feeds that
require authentication.
- **`dotnet`** — shells out to `dotnet restore` against a throwaway project. Use this for a
private feed whose auth is wired through the .NET credential-provider ecosystem (e.g. the
Azure Artifacts Credential Provider) or a `NuGet.config`. Cross-platform, needs only the
.NET SDK.
- **`nuget`** — shells out to `nuget.exe install` (or a `nuget` on PATH) once per artifact.
Useful when your feed's auth is supplied by a NuGet/Visual Studio credential provider
(`CredentialProvider.Microsoft`, etc.) that `dotnet restore` can't host — for example a
netfx-only provider plugin. `dotnet` remains the cross-platform option when both work.

Set `FOUNDRY_LOCAL_SKIP_INSTALL=1` to skip the step entirely (e.g. when building from source
and copying binaries via `copy-native:dev` instead).

| Variable | Applies to | Purpose |
|------------------------------------|--------------------|-------------------------------------------------------------------------------------------------------|
| `FOUNDRY_LOCAL_NUGET_MODE` | all | `http` (default), `dotnet`, or `nuget`. Any other value is rejected. |
| `FOUNDRY_LOCAL_NUGET_FEEDS` | all | `;`-separated NuGet v3 service index URLs. Replaces the public defaults entirely. `http` mode requires HTTPS; `dotnet`/`nuget` do not. |
| `FOUNDRY_LOCAL_NUGET_CONFIG` | `dotnet`, `nuget` | Path to a `NuGet.config`. When set, the config owns package sources (`--configfile`/`-ConfigFile`, no `--source`/`-Source`). Rejected in `http` mode. |
| `FOUNDRY_LOCAL_DOTNET_COMMAND` | `dotnet` only | Command or path to the `dotnet` executable. Defaults to `dotnet`. Rejected in `http`/`nuget` mode. |
| `FOUNDRY_LOCAL_NUGET_COMMAND` | `nuget` only | Command or path to the `nuget` executable. Defaults to `nuget.exe` on Windows, `nuget` elsewhere. Rejected in `http`/`dotnet` mode. |

Authentication is delegated to the NuGet tooling in `dotnet`/`nuget` mode (a `NuGet.config`
or a credential provider), so no credentials pass through this script. Query strings and
fragments (which can carry SAS tokens) are stripped from every logged or thrown URL, and
`nuget`/`dotnet` mode never print their full command line — only stdout/stderr on failure,
with URLs redacted.

**Example — custom anonymous feed, HTTP mode (PowerShell):**

```pwsh
$env:FOUNDRY_LOCAL_NUGET_FEEDS = "https://pkgs.dev.azure.com/my-org/_packaging/my-feed/nuget/v3/index.json"
npm install
```

**Example — dotnet mode with a NuGet.config (either shell):**

The `NuGet.config` owns the package sources (and any credentials), so no feed variable is set here.

```pwsh
$env:FOUNDRY_LOCAL_NUGET_MODE = "dotnet"
$env:FOUNDRY_LOCAL_NUGET_CONFIG = "C:\secrets\NuGet.config"
Comment thread
Copilot marked this conversation as resolved.
npm install
```

```bash
export FOUNDRY_LOCAL_NUGET_MODE=dotnet
export FOUNDRY_LOCAL_NUGET_CONFIG=/etc/secrets/NuGet.config
npm install
```

**Example — nuget mode against a private Azure Artifacts feed, authenticated via
a NuGet/Visual Studio credential provider (PowerShell):**

```pwsh
$env:FOUNDRY_LOCAL_NUGET_MODE = "nuget"
$env:FOUNDRY_LOCAL_NUGET_COMMAND = "C:\tools\nuget\nuget.exe"
$env:FOUNDRY_LOCAL_NUGET_FEEDS = "https://pkgs.dev.azure.com/my-org/_packaging/my-feed/nuget/v3/index.json"
npm install
```

This mode is useful precisely when the feed's anonymous access is disabled and auth is
supplied out-of-band by a NuGet/Visual Studio credential provider (`CredentialProvider.Microsoft`)
that `dotnet restore` cannot host — `nuget.exe` on Windows can invoke netfx credential provider
plugins. `dotnet` remains the cross-platform option when your feed's credential provider supports it.

---

## 4. Using the C++ SDK directly (without the JS layer)
Expand Down
28 changes: 21 additions & 7 deletions sdk_v2/js/docs/PortJsToSdkV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,27 @@ on the v2 layer:
and the addon for every (platform × arch), drops each
`(.node addon + foundry_local.{dll,so,dylib})` pair into
`prebuilds/<platform>-<arch>/`, then `npm pack`s a single tarball
containing all variants. At install time, `npm install` just unpacks the
tarball — there is no postinstall download step, no separate artifact
host, and no network access beyond the normal npm fetch. At runtime, the
loader picks the matching `prebuilds/<process.platform>-<process.arch>/`
subdirectory. If a consumer is on an unsupported platform, the addon
load fails with a clear error; there is no automatic source-build
fallback in the published package.
containing all variants. `npm install` unpacks the tarball — the addon
and `foundry_local.{dll,so,dylib}` themselves require no postinstall
download. At runtime, the loader picks the matching
`prebuilds/<process.platform>-<process.arch>/` subdirectory. If a
consumer is on an unsupported platform, the addon load fails with a
clear error; there is no automatic source-build fallback in the
published package.
- **ORT / ORT-GenAI *are* fetched during the install lifecycle.** Unlike
`foundry_local` itself, the ONNX Runtime and ORT-GenAI native binaries
are not bundled in the tarball — `script/install-native.cjs` runs as
the package's `install` script and downloads them from NuGet into the
same `prebuilds/<platform>-<arch>/` directory. It supports an `http`
mode (default, raw NuGet v3 protocol), a `dotnet` mode (`dotnet
restore` against a throwaway project, for feeds that need .NET
credential-provider auth), and a `nuget` mode (`nuget.exe install` per
artifact, for feeds whose auth is supplied by a NuGet/Visual Studio
credential provider that `dotnet restore` can't host). Feeds and the
`NuGet.config` path are configurable via
`FOUNDRY_LOCAL_NUGET_*` env vars; see
[README.md § 3.4](../README.md#34-native-runtime-install-ort--ort-genai-via-nuget).
Set `FOUNDRY_LOCAL_SKIP_INSTALL=1` to opt out entirely.
- **Dev / source builds load the native from the canonical C++ build
dir.** Per
[cpp-build.instructions.md](../../../.github/instructions/cpp-build.instructions.md),
Expand Down
Loading
Loading