Skip to content

[WSLC] Generate WSLC SDK FFI bindings with bindgen#669

Open
SohamDas2021 wants to merge 3 commits into
mainfrom
user/sodas/wslc-bindgen
Open

[WSLC] Generate WSLC SDK FFI bindings with bindgen#669
SohamDas2021 wants to merge 3 commits into
mainfrom
user/sodas/wslc-bindgen

Conversation

@SohamDas2021

@SohamDas2021 SohamDas2021 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📖 Description

Replaces the hand-written WSLC SDK FFI bindings with bindgen-generated bindings so any ABI drift between the SDK headers and our Rust declarations becomes a compile error instead of silent undefined behavior at runtime.

🔗 References

🔍 Validation

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

GitHub Actions runs the PR validation build automatically. The ADO pipeline
(MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with the GitHub
Actions build; it runs on merge to main, and Microsoft reviewers with write access can trigger it
on a PR with /azp run. See docs/pull-requests.md.

If the dependency-feed-check check fails on a new dependency, the crate must be added to
the feed before the PR can pass. See docs/pull-requests.md
for the steps.

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings July 22, 2026 18:32
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the WSLC backend’s Rust FFI surface from hand-written declarations to bindgen-generated bindings, so ABI drift between the pinned WSLC SDK header (wslcsdk.h) and our Rust types/signatures is caught at compile time rather than becoming silent runtime UB.

Changes:

  • Add and commit bindgen-generated WSLC SDK bindings (wslcsdk_sys.rs) plus a PowerShell regeneration script.
  • Refactor wslc_bindings.rs into a thin façade over the generated module (DLL anti-hijack load + required-symbol validation + RAII guards).
  • Update the WSLC runner + policy mapping and add documentation/runbook for maintaining the bindings.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/backends/wslc/common/src/wslcsdk_sys.rs New bindgen-generated ABI surface + dynamic-loading WslcSdk table (committed artifact).
src/backends/wslc/common/src/wslc_bindings.rs Façade over generated bindings: safe-ish load(), required-export validation, RAII guards, S_OK, helpers.
src/backends/wslc/common/src/wsl_container_runner.rs Update call sites/struct field names/enum constants and callback ABI to match bindgen output.
src/backends/wslc/common/src/policy_mapping.rs Update networking mode mapping/tests to use bindgen newtype constants.
src/backends/wslc/common/src/lib.rs Export new wslcsdk_sys module.
scripts/generate-wslc-bindings.ps1 New standalone regeneration script (bindgen CLI + libclang + MSVC/WinSDK include discovery + header extraction from .nupkg).
docs/wsl/wslc-sdk-bindings.md New runbook documenting the generated file, why it’s committed, and how to bump/regenerate safely.
docs/wsl/wsl-container-getting-started.md Link to the new bindings-maintenance documentation.
.github/copilot-instructions.md Document the bindgen-generated WSLC bindings convention and regeneration procedure.

Comment on lines +352 to 356
let mut missing = WslcComponentFlags::WSLC_COMPONENT_FLAG_NONE;
let hr = sdk.WslcGetMissingComponents(&mut missing);
if hr != S_OK {
return Err(sdk_error("WslcGetMissingComponents failed", hr, ""));
}
@SohamDas2021
SohamDas2021 marked this pull request as ready for review July 22, 2026 18:55
@SohamDas2021
SohamDas2021 requested a review from a team as a code owner July 22, 2026 18:55
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants