Skip to content

Add contract-driven flat Win32 bindings - #152

Merged
leileizhang (lei9444) merged 19 commits into
mainfrom
leilzh/win32-contracts
Sep 15, 2026
Merged

leileizhang (lei9444) merged 19 commits into
mainfrom
leilzh/win32-contracts

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add dynamic invocation of Win32 DLL exports and generate JavaScript bindings with TypeScript declarations from Windows.Win32.winmd.

  • Add an independent Win32 JSON contract registry for native types, ownership, buffer relationships, and lifecycle rules, with strict metadata and signature validation.
  • Implement immutable libffi call plans for supported native ABI shapes, status/LastError handling, and managed resources with explicit cleanup.
  • Add IOCP-backed asynchronous file I/O with cancellation and bounded buffers, plus explicit Winsock, GDI+, and Media Foundation contexts.
  • Generate namespace-organized modules with CJS/ESM indexes and separate safe/unsafe Win32 entrypoints, preserving the existing WinRT and Classic COM surfaces.
  • Add coverage reporting and regression coverage.

Samples

Examples in samples/js/win32:

Sample Demonstrates
system-info.mjs Read uptime with GetTickCount64 and UTC time through a native SYSTEMTIME structure.
registry-product-name.mjs Read the Windows product name with a two-phase buffer query and managed HKEY cleanup.
overlapped-file.mjs Round-trip a temporary file with IOCP-backed reads/writes, offsets, and an AbortSignal.

The README includes setup, generated module paths, expected output, and cleanup behavior.

Builds on #102.

Introduce standalone Win32 JSON evidence, immutable native call plans, branded handle carriers and namespace-isolated generation for five audited exports. Preserve the WinRT and COM surfaces and document the remaining migration scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 85.8% 80.84% 85.33% regions
Python aggregate 71.06% n/a 37.9% branches
Python runtime 99.12% n/a 97.37% branches
Generated Python WinRT projections 70.05% n/a 27.07% branches
Generated Python WinRT implementations 72.29% n/a 47.04% branches
JavaScript aggregate 22.13% 25.26% 57.85% branches
JavaScript runtime 44.56% 52.94% 80.95% branches
Generated WinRT projections 22.97% 18.71% 54.94% branches
Generated WinRT implementations 48.66% 59.76% 61.14% branches
Generated Classic COM projections 11.92% 23.97% 54.2% branches

View workflow run and download full HTML/LCOV/XML reports

@lei9444
leileizhang (lei9444) marked this pull request as draft September 11, 2026 08:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
@lei9444 leileizhang (lei9444) changed the title Introduce contract-driven flat Win32 foundation Migrate full flat Win32 support to contract-driven generation Sep 11, 2026
Preserve the complete frozen export and runtime surface, move manual evidence into independent JSON contracts, and restore native layouts, ownership, IOCP, subsystem contexts, census, samples and E2E scenarios. Add exact identity and semantic parity gates plus capability-preserving Registry and native-boundary hardening.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
@lei9444
leileizhang (lei9444) marked this pull request as ready for review September 11, 2026 12:45
@lei9444 leileizhang (lei9444) changed the title Migrate full flat Win32 support to contract-driven generation Add contract-driven flat Win32 bindings Sep 11, 2026
leileizhang (lei9444) and others added 13 commits September 11, 2026 21:08
Describe each sample's native APIs, setup requirements, generated namespace layout, expected output, resource cleanup and runtime side effects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Replace PR-specific Debug hash comparisons with explicit contract, ABI, ownership, buffer, IOCP, subsystem and package assertions. Load and typecheck all generated modules in ordinary tests, wire them into the existing CI jobs, and fix the strict-identifier, relative-import, pointer-null and descriptor validation bugs they expose.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Resolve architecture-specific utility symbols lazily so undecorated x86 imports do not prevent WinRT/COM binaries from loading. Run native subsystem lifecycle checks in bounded child processes with phase diagnostics instead of allowing one stalled platform call to block the whole test job.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Keep the native MAPI capability and architecture-specific loader unchanged. Exercise lifecycle and error handling through a test-only ABI function table, and retain bounded live coverage for configured providers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Lower conditional output validity and resource aliasing into native call plans, including exact pointer-width HKEY matching. Coordinate file completion modes with asynchronous leases and exactly-once IOCP retirement.

Support flags combinations, ship the complete JS runtime artifact, and add native, generated-module, artifact-consumer and live API regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Share versioned Win32 protocol types, structural validation and generated schema between codegen and core. Model validity, delivery, ownership and cleanup for direct returns and output parameters while retaining version-one compatibility.

Move resource coordination, typed file capabilities and IOCP lifetimes into native core. Keep Node references and copy-back on the owner thread, retain queued-result budgets, and expand native and generated compatibility coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Add version-three aggregate field results and typed pointee descriptors. Capture native field ownership before return conversion or N-API wrapping while preserving caller-owned storage, resource extraction and cleanup retry behavior.

Replace core callback receivers with token/channel delivery and keep TSFN registrations in an adapter-owned relay. Add generated CreateProcessW delivery-failure and GC handle-count regressions alongside native and Node lifecycle coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Document legacy ownership preconditions across the core and JS adapter, reject writes over pending raw cleanup fields, and cover borrowed handles, exclusive transfer, and partial result failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Register all described aggregate native states before fallible field processing and retain discarded-owned cleanup guards until cleanup succeeds. Cover protected-handle retries, cross-aggregate failures, truthful legacy markers, and undescribed legacy compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Apply successful input consumption and resource effects after output guards are registered, before fallible result decoding or cleanup. Add native success/failure regressions for consumed handles, leases, and file completion modes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Reject input and retiring-owner overlap before mutation or dispatch, acquire one owner-identity-ordered resource lock set, and retire through held guards. Add bounded regressions for DuplicateHandle reuse, aliases, cleanup retry, and concurrent lock coordination.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Share a retryable System32 module cache with typed lifecycle tables for Winsock, GDI+, Media Foundation and MAPI. Preserve explicit startup/shutdown state, balance concurrent load references, and enforce production addon import boundaries with native and artifact regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Avoid rereading and hashing WinMD for every COM request by reusing a lazy presence-only index within generate. Preserve routing precedence and full Win32 provenance validation, with snapshot reuse and strict-input regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Replace historical migration acceptance wording with current capabilities, clarify COM and flat Win32 boundaries, document package and E2E entrypoints, and repair the missing unsafe-guide reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
Preserve main CoreMessaging lazy loading and native import checks alongside Win32 runtime and type-check coverage. Resolve the overlapping package scripts without dropping either validation path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bfe6adcb-6e2c-4e05-86ca-83e923c28999
@lei9444
leileizhang (lei9444) merged commit 0130b3f into main Sep 15, 2026
24 checks passed
@lei9444
leileizhang (lei9444) deleted the leilzh/win32-contracts branch September 15, 2026 06:27
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