Skip to content

feat(vscode): bundle verified native clangd in platform-specific VSIX packages #204

Closed

Description

@zackees

Context

#203 needs a guaranteed native clangd server. The llvm-vs-code-extensions.vscode-clangd extension is the language client; it does not guarantee that the native server is installed. clang-tool-chain-bins v0.4.6 now supplies clangd for all six FastLED desktop targets, and VS Code supports publishing platform-specific VSIX packages under one extension version.

This issue owns only native artifact ingestion, bundle discovery/probing, target-specific packaging, native validation, and publication. #203 remains responsible for installing the clangd/cpptools extensions, choosing exactly one language engine, writing clangd.path, generating editor metadata, and restarting language clients.

PR #183 must land first because it introduces the tracked vscode-plugin/ source used below.

Verified constraints

The implementation must use the package-local index from the pinned Python distribution, not a mutable remote index:

uvx --from clang-tool-chain-bins==0.4.6 clang-tool-chain-bins install clangd \
  --component clang-extra \
  --platform <win|linux|darwin> \
  --arch <x86_64|arm64> \
  --version <21.1.5|21.1.6> \
  --home-dir <cache-dir>

The command prints exactly one JSON object. Use its install_path; do not reconstruct the install directory name (clang-extra is normalized to clang_extra internally). Accept only installed and already_installed status values and verify every returned identity field against the lock below.

The upstream clang-extra archive builder copies every sibling LLVM shared library, even when clangd does not load it. Copying the whole archive would produce unnecessarily large VSIX packages. Direct inspection established the following minimal runtime contract:

bin/clangd[.exe]
lib/clang/21/include/**
third_party/llvm/LICENSE.TXT
third_party/llvm/NOTICE.md
manifest.json

Do not copy lib/clang/21/lib, lib/*.so*, lib/*.dylib, bin/*.dll, or any other clang tool. Representative binary inspection found only operating-system dependencies:

  • Windows x64 imports Windows system DLLs only.
  • Linux x64 needs glibc, libm, libz, and the ELF loader only; it does not load libLLVM or libclang.
  • macOS ARM64 loads only /usr/lib/libSystem, /usr/lib/libz, and /usr/lib/libc++.

The native matrix must enforce this contract for all six targets. A local Windows x64 minimal bundle passed clangd --check and compressed from 57.84 MiB to 18.36 MiB. A Linux x64 minimal bundle passed the same check in a clean Ubuntu 24.04 container with an empty PATH and compressed from 110.68 MiB to 29.26 MiB.

Primary references:

Normative implementation specification

1. Commit the complete artifact lock

Create vscode-plugin/clangd-artifacts.json with this schema and initial data. These values come from the packaged v0.4.6 index and provenance sidecars; do not replace them with latest lookups.

{
  "schema_version": 1,
  "provider": {
    "package": "clang-tool-chain-bins",
    "package_version": "0.4.6",
    "component": "clang-extra"
  },
  "targets": {
    "win32-x64": {
      "platform": "win",
      "arch": "x86_64",
      "llvm_version": "21.1.5",
      "llvm_commit": "8e2cd28cd4ba46613a46467b0c91b1cabead26cd",
      "provenance_method": "extracted",
      "archive_filename": "clang-extra-21.1.5-win-x86_64.tar.zst",
      "archive_sha256": "342b91b880a52c47223ac25a5a9652c56c6460fee93738ffd069b62ba07837c7",
      "binary_path": "bin/clangd.exe",
      "binary_size": 45101568,
      "binary_sha256": "ceef318729b3e3f75925d3cadd232cc52a679b77112e3f2f883733d3b9348f7f",
      "resource_include_path": "lib/clang/21/include"
    },
    "win32-arm64": {
      "platform": "win",
      "arch": "arm64",
      "llvm_version": "21.1.5",
      "llvm_commit": "8e2cd28cd4ba46613a46467b0c91b1cabead26cd",
      "provenance_method": "extracted",
      "archive_filename": "clang-extra-21.1.5-win-arm64.tar.zst",
      "archive_sha256": "00f220603612c22a063159745e2834508b6278bcd575dbe8e1ddf4b4784c81ef",
      "binary_path": "bin/clangd.exe",
      "binary_size": 41637376,
      "binary_sha256": "38534a0e6ad32512ef8f57ee640b8f30da19137c7deb43a25d7d1bb3488f7441",
      "resource_include_path": "lib/clang/21/include"
    },
    "linux-x64": {
      "platform": "linux",
      "arch": "x86_64",
      "llvm_version": "21.1.5",
      "llvm_commit": "8e2cd28cd4ba46613a46467b0c91b1cabead26cd",
      "provenance_method": "extracted",
      "archive_filename": "clang-extra-21.1.5-linux-x86_64.tar.zst",
      "archive_sha256": "e02a9fbf7e0ef2ae466ef90f7ac1fff03a165dfb707ddf3f4249e4be7360933e",
      "binary_path": "bin/clangd",
      "binary_size": 100539280,
      "binary_sha256": "26a89213310f41bc4b63184726aa1f1995703aef69de1d00b41a562d7e6afe69",
      "resource_include_path": "lib/clang/21/include"
    },
    "linux-arm64": {
      "platform": "linux",
      "arch": "arm64",
      "llvm_version": "21.1.5",
      "llvm_commit": "8e2cd28cd4ba46613a46467b0c91b1cabead26cd",
      "provenance_method": "extracted",
      "archive_filename": "clang-extra-21.1.5-linux-arm64.tar.zst",
      "archive_sha256": "fa48034cf7e29879ee3f0d89925aa3ef6d5dc068fb5e4d0af32af8a92f0f5643",
      "binary_path": "bin/clangd",
      "binary_size": 95086552,
      "binary_sha256": "5f450cf0a2f9fbb66aca2bd9bdc43fb75f1ff9eae208328e8bab1cfc0e7e7af8",
      "resource_include_path": "lib/clang/21/include"
    },
    "darwin-x64": {
      "platform": "darwin",
      "arch": "x86_64",
      "llvm_version": "21.1.6",
      "llvm_commit": "a832a5222e489298337fbb5876f8dcaf072c5cca",
      "provenance_method": "forge",
      "archive_filename": "clang-extra-21.1.6-darwin-x86_64.tar.zst",
      "archive_sha256": "9b87a73523cc9d9e9fb1781b552418fc48f4f77616f44d092a074d62a13c1934",
      "binary_path": "bin/clangd",
      "binary_size": 58535376,
      "binary_sha256": "9f4ff95171aa35a0e89815eb1a22de0059dd6c52da15d3ba1a66a5d0dc9b64c3",
      "resource_include_path": "lib/clang/21/include"
    },
    "darwin-arm64": {
      "platform": "darwin",
      "arch": "arm64",
      "llvm_version": "21.1.6",
      "llvm_commit": "a832a5222e489298337fbb5876f8dcaf072c5cca",
      "provenance_method": "extracted",
      "archive_filename": "clang-extra-21.1.6-darwin-arm64.tar.zst",
      "archive_sha256": "a668593eada9da5222b4c9d40fb84f72772cf4db1e9ca1cc91d82b38ec73a7a0",
      "binary_path": "bin/clangd",
      "binary_size": 58428896,
      "binary_sha256": "b03fb31978f7238229e29004f6f8a366d2009cbe9c2086d0d6abb5d7b297a88b",
      "resource_include_path": "lib/clang/21/include"
    }
  }
}

Lock validation must reject unknown keys, missing targets, duplicate (platform, arch) pairs, unsupported VS Code targets, non-hex hashes, non-positive sizes, absolute paths, and any path containing ...

2. Implement deterministic ingestion

Create vscode-plugin/scripts/ingest_clangd.py with this interface:

python scripts/ingest_clangd.py \
  --target <six-target-name> \
  --output resources/clangd \
  --ctcb-home <cache-directory>

python scripts/ingest_clangd.py --clean --output resources/clangd

Algorithm:

  1. Load and strictly validate clangd-artifacts.json.
  2. Run the pinned uvx --from clang-tool-chain-bins==<version> install command shown above. Set a hard download/install timeout and print the child output on failure.
  3. Parse exactly one JSON object from stdout and compare component, platform, arch, version, archive_sha256, and operation status with the lock.
  4. Treat the returned install_path as untrusted input: resolve it, require that it exists, and never construct commands with shell=True.
  5. Verify the source clangd byte size and SHA256 before copying anything.
  6. Require lib/clang/21/include/stddef.h and stdint.h as resource sentinels.
  7. Stage into a temporary sibling directory, never directly into the final output.
  8. Copy only:
    • the locked binary_path;
    • the complete locked resource_include_path tree;
    • vscode-plugin/third_party/llvm/LICENSE.TXT;
    • vscode-plugin/third_party/llvm/NOTICE.md.
  9. Set the staged Unix binary mode to 0755; do not alter header modes.
  10. Generate resources/clangd/manifest.json with sorted keys and a trailing newline. It must contain schema_version, target, LLVM version/commit, CTCB version/archive hash, binary relative path/size/hash, resource directory, and a sorted {path,size,sha256} entry for every staged file except the manifest itself.
  11. Re-hash the completed staging tree, then atomically replace the old output directory.
  12. On every failure, delete only the temporary staging directory and leave any previously valid output untouched.

The script must not copy symlinks, device files, files outside the resolved install root, lib/clang/21/lib, sibling LLVM libraries, or other executables.

Commit vscode-plugin/third_party/llvm/LICENSE.TXT from the pinned LLVM tag and a NOTICE.md that lists both LLVM versions/commits, the six artifact origins, clang-tool-chain-bins as the distributor, and the Apache-2.0-with-LLVM-exception terms. The current CTCB archives do not contain these license files, so ingestion must fail if the committed copies are absent.

3. Add native/runtime and VSIX verifiers

Create:

  • vscode-plugin/scripts/verify_clangd_runtime.py
  • vscode-plugin/scripts/verify_vsix.py
  • vscode-plugin/test/fixtures/clangd/fixture.cpp
  • vscode-plugin/test/fixtures/clangd/compile_commands.json.in

verify_clangd_runtime.py --root resources/clangd --target <target> must:

  • validate every manifest path, size, and SHA256;
  • reject any file outside the exact payload allowlist;
  • verify PE, ELF, or Mach-O architecture without executing a foreign-architecture binary;
  • on the native target, run the absolute binary path with PATH empty and a five-second timeout;
  • require clangd --version to report the locked LLVM version and expected target architecture;
  • render an absolute compile_commands.json from the fixture template and run clangd --check with C++20, -target wasm32-wasi, -nostdinc++, and -fsyntax-only;
  • reject unresolved native dependencies;
  • reject packaged LLVM dependencies:
    • Windows: no imported DLL may resolve inside the bundle;
    • Linux: readelf -d must not contain libLLVM or libclang, and ldd must contain no not found result;
    • macOS: every otool -L dependency must begin with /usr/lib/ or /System/Library/; reject @rpath, @loader_path, and bundle-relative dylibs.

verify_vsix.py --vsix <file> --target <target|universal> must use Python zipfile and verify:

  • the VSIX target and filename match;
  • extension/package.json has the expected version and "extensionKind": ["workspace"];
  • a native VSIX has exactly one extension/resources/clangd/manifest.json and its target matches;
  • the packaged file hashes equal the generated manifest;
  • the only native executable is bin/clangd[.exe];
  • no path contains another clang tool, lib/clang/21/lib, *.dll, *.so*, or *.dylib;
  • the universal VSIX contains no extension/resources/clangd/ path.

4. Add the TypeScript bundle API

Create vscode-plugin/src/clangdBundle.ts and export these stable shapes (additional diagnostic fields are allowed):

export type BundledClangdResult =
  | { kind: 'ready'; path: string; target: string; version: string }
  | { kind: 'unavailable'; reason: 'universal-package' | 'unsupported-host' }
  | {
      kind: 'invalid';
      reason:
        | 'manifest-missing'
        | 'manifest-invalid'
        | 'target-mismatch'
        | 'binary-missing'
        | 'binary-hash-mismatch'
        | 'resource-dir-missing'
        | 'not-executable'
        | 'probe-timeout'
        | 'probe-failed'
        | 'version-mismatch';
      message: string;
    };

export interface FastLedExtensionApi {
  resolveBundledClangd(): Promise<BundledClangdResult>;
}

Resolver behavior:

  1. Map the extension-host process.platform/process.arch pair to one of the six VS Code targets. Only x64 and arm64 are accepted.
  2. Locate resources/clangd/manifest.json relative to ExtensionContext.extensionUri.
  3. A missing manifest in the universal package is unavailable, not an error. Determine that package type from a small build marker in package.json or a generated package metadata file; do not treat arbitrary corruption as universal fallback.
  4. Validate the manifest schema and target before resolving paths. Reject traversal and require all resolved paths to remain below the bundle root.
  5. Verify binary size/SHA256 and resource sentinels. Full header-tree verification remains a CI/package responsibility.
  6. On Unix, check execute access; attempt one chmod(0755) repair and recheck.
  7. Probe with child_process.execFile, never a shell: clangd --version, five-second timeout, windowsHide: true, and a bounded output buffer.
  8. Require the locked LLVM version and expected platform/architecture in probe output.
  9. Return the absolute binary path. Do not search PATH, download anything, modify LD_LIBRARY_PATH/DYLD_LIBRARY_PATH, write clangd.path, activate the clangd extension, or select a language engine in this issue.

Change activate() to return FastLedExtensionApi. #203 can call the same resolver internally. Add a FastLED: Show Bundled clangd Diagnostics command that logs target, version, path, and structured failure reason without dumping the environment.

Add this manifest field so remote SSH/WSL/Dev Container installations run beside the workspace and receive the package matching the remote extension host:

"extensionKind": ["workspace"]

5. Make packaging stale-state-safe

Create vscode-plugin/scripts/package_extension.py:

python scripts/package_extension.py --target <six-target-name|universal> --out dist/

For a native target it must clean, ingest, verify, run npm run compile, package, inspect, and finally remove the generated staging directory. For universal it must clean the staging directory before packaging and prove the resulting VSIX contains no native payload. A failed build must not leave a target payload that a later universal build can accidentally package.

Pin @vscode/vsce in devDependencies and package-lock.json; invoke the local binary through npx --no-install vsce. Use Node 22 in CI. Output names are normative:

dist/fastled-wasm-<version>-win32-x64.vsix
dist/fastled-wasm-<version>-win32-arm64.vsix
dist/fastled-wasm-<version>-linux-x64.vsix
dist/fastled-wasm-<version>-linux-arm64.vsix
dist/fastled-wasm-<version>-darwin-x64.vsix
dist/fastled-wasm-<version>-darwin-arm64.vsix
dist/fastled-wasm-<version>-universal.vsix

Update ignores as follows:

  • .gitignore: ignore /resources/clangd/, /dist/, and local CTCB caches.
  • .vscodeignore: continue including resources/clangd/** and third_party/llvm/**, but exclude scripts, tests, fixtures, caches, and source maps.

6. Add tests and commands

Add Python unit tests under vscode-plugin/scripts/tests/ covering:

  • the exact six-target lock and mapping;
  • malformed locks and unsafe paths;
  • installer JSON parsing and identity mismatch;
  • hash/size mismatch;
  • missing resource sentinels;
  • copy allowlist and rejection of symlinks;
  • atomic replacement and failure preservation;
  • deterministic manifest ordering;
  • universal cleanup after a native package;
  • VSIX content/target/version validation.

Add TypeScript tests under vscode-plugin/src/test/ covering every BundledClangdResult variant, host mapping, traversal rejection, timeout/kill behavior, hash mismatch, chmod repair, and successful absolute-path probing. Use @vscode/test-electron for the installed-extension test.

Required local commands:

cd vscode-plugin
npm ci
npm run compile
uv run --no-project --with pytest pytest scripts/tests -q
python scripts/package_extension.py --target <native-host-target> --out dist/
python scripts/package_extension.py --target universal --out dist/
npm test

The Extension Development Host test must install the produced VSIX into a clean profile, remove system clangd from PATH, activate fastled.fastled-wasm, call the returned API, and assert that the ready path is inside the installed extension. The universal test must return unavailable/universal-package without a prompt or download.

7. Add CI and release workflows

Add .github/workflows/vscode-extension.yml for pull requests and pushes that touch vscode-plugin/** or the workflow itself. Use this native matrix:

Target Runner
win32-x64 windows-2025
win32-arm64 windows-11-arm
linux-x64 ubuntu-24.04
linux-arm64 ubuntu-24.04-arm
darwin-x64 macos-15-intel
darwin-arm64 macos-15

Each lane must use npm ci, package on the native runner, run all native verifier checks, install-test its VSIX, and upload the VSIX plus its manifest/SHA256/size report. Cache the CTCB home using a key containing the target and locked archive SHA. Build the universal VSIX on Ubuntu in a separate job. An aggregate job must download all artifacts and fail unless the exact seven filenames and one shared extension version are present.

Add .github/workflows/vscode-extension-release.yml, triggered only by vscode-v* tags. Require the tag suffix to equal vscode-plugin/package.json version exactly. Rebuild the seven packages from that tag SHA, rerun the aggregate verifier, generate SHA256 files and Sigstore attestations, attach everything to the GitHub release, and publish the same seven prebuilt VSIX files to the Marketplace. Never rebuild between GitHub Release upload and Marketplace publication. Use protected credentials/workload identity; no credential may appear in repository files or logs.

Implementation order

  1. Merge/rebase on PR [codex] track vscode extension #183.
  2. Add the lock, LLVM licensing files, ingestion script, and Python unit tests.
  3. Add runtime and VSIX verifiers; prove one local native target plus universal packaging.
  4. Add clangdBundle.ts, activation API, diagnostics command, and TypeScript tests.
  5. Add the six-target CI matrix and Extension Development Host tests.
  6. Add the tag-gated release workflow and documentation.
  7. Hand the ready-path API to feat(vscode): provide verified clangd and Microsoft C/C++ IntelliSense for WASM sketches #203; do not implement engine arbitration in this PR.

Expected files

  • vscode-plugin/clangd-artifacts.json
  • vscode-plugin/third_party/llvm/LICENSE.TXT
  • vscode-plugin/third_party/llvm/NOTICE.md
  • vscode-plugin/scripts/ingest_clangd.py
  • vscode-plugin/scripts/package_extension.py
  • vscode-plugin/scripts/verify_clangd_runtime.py
  • vscode-plugin/scripts/verify_vsix.py
  • vscode-plugin/scripts/tests/**
  • vscode-plugin/src/clangdBundle.ts
  • vscode-plugin/src/test/**
  • vscode-plugin/test/fixtures/clangd/**
  • vscode-plugin/package.json
  • vscode-plugin/package-lock.json
  • vscode-plugin/.gitignore
  • vscode-plugin/.vscodeignore
  • vscode-plugin/README.md
  • .github/workflows/vscode-extension.yml
  • .github/workflows/vscode-extension-release.yml

Acceptance criteria

  • The committed lock contains exactly the six entries and pinned values above; ingestion never resolves latest or a remote index.
  • Ingestion uses the returned CTCB install_path, verifies identity/size/hashes, stages atomically, and copies only clangd, builtin headers, license/notice, and the generated manifest.
  • No native binary, generated payload, VSIX, or CTCB cache is committed to git.
  • Every native payload contains no LLVM shared library, other clang executable, compiler runtime library, or lib/clang/21/lib file.
  • Every target passes architecture inspection, dependency allowlist checks, clangd --version, and the C++20/WASM clangd --check fixture on its native runner with system clangd absent and PATH empty.
  • The runtime resolver is traversal-safe, bounded, shell-free, does not download, does not search PATH, and returns the structured result contract above.
  • activate() exposes FastLedExtensionApi, and a clean Extension Development Host resolves a path inside the installed target-specific extension.
  • The universal package contains no clangd payload and reports unavailable/universal-package without blocking activation.
  • Packaging a native target followed by universal cannot leak the previous target's staging tree.
  • Six platform-specific VSIX files and one universal fallback are generated with the exact names above and a single package version.
  • PR CI produces and verifies all seven artifacts; Windows ARM64 runs natively on windows-11-arm, not under x64 emulation.
  • A vscode-v<version> release builds once, verifies once, signs/attests, attaches, and publishes the same bytes to GitHub and the VS Code Marketplace.
  • LLVM license, version, commit, distribution method, and artifact provenance are present in every native VSIX.
  • Python tests, TypeScript tests, Extension Development Host tests, VSIX inspection, npm run compile, bash lint, and existing repository tests pass.
  • Documentation gives exact update, local reproduction, offline behavior, supported-target, universal-fallback, and troubleshooting commands.

Out of scope

  • Installing or requiring llvm-vs-code-extensions.vscode-clangd or ms-vscode.cpptools.
  • Writing clangd.path or C/C++ settings.
  • Starting, stopping, or switching language engines.
  • Generating compile_commands.json, .clangd, or c_cpp_properties.json.

Those remain in #203 and consume the verified FastLedExtensionApi produced here.

Related issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions