dynwinrt
Copilot instructions61 starsChanged 3 months agoMITView on GitHub
This file provides instructions for the GitHub Copilot coding agent when working on this repository. dynwinrt is a Rust library for dynamically invoking Windows Runtime (WinRT) APIs. It includes: - Core library (crates/dynwinrt/) — Rust runtime using libffi for dynamic WinRT method invocation - JS binding (bindings/js/) — napi-rs binding for Node.js/Electron - Python binding (bindings/py/) — PyO3 binding for Python - Code generator (tools/dynwinrt-codegen/) — Source for dynwinrt-codegen, which generates typed JavaScript (.js) + TypeScript declarations (.d.ts), or Python…
- Installs packages
In this repository2 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- classic-com-abiSkill
The file
We split this copilot-instructions.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 64
Adding new test cases: Add entries to tests/e2e/e2e_specs.json:
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Agent Instructions
This file provides instructions for the GitHub Copilot coding agent when working on this repository.
Project Overview
dynwinrt is a Rust library for dynamically invoking Windows Runtime (WinRT) APIs. It includes:
- Core library (
crates/dynwinrt/) — Rust runtime using libffi for dynamic WinRT method invocation - JS binding (
bindings/js/) — napi-rs binding for Node.js/Electron - Python binding (
bindings/py/) — PyO3 binding for Python - Code generator (
tools/dynwinrt-codegen/) — Source for dynwinrt-codegen, which generates typed JavaScript (.js) + TypeScript declarations (.d.ts), or Python (.py+ optional.pyi) wrappers from .winmd metadata
Classic COM and flat Win32 have separate JavaScript/TypeScript projections and runtime subpaths. Flat Win32 uses its own native ABI, resource, and contract model; see the Win32 architecture.
Build & Test Commands
# Build everything
cargo build
# Core library tests (52 tests, 1 ignored — requires WinAppSDK)
cargo test -p dynwinrt
# dynwinrt-codegen tests (49 unit tests + 1 snapshot test)
cargo test -p dynwinrt-codegen
# Python binding (requires Python 3.8+ and maturin)
cd bindings/py
python -m venv .venv && .venv/Scripts/Activate.ps1
pip install pytest maturin
maturin build
pip install target/wheels/*.whl --force-reinstall
python -m pytest tests/ -v
# JS binding (requires Node.js 18+)
cd bindings/js
npm install
npm run build
# Code generation (JS + .d.ts is the default; --lang py for Python)
cargo run -p dynwinrt-codegen -- generate --namespace Windows.Foundation --class-name Uri --output ./generated
cargo run -p dynwinrt-codegen -- generate --namespace Windows.Foundation --class-name Uri --lang py --output ./generated
# E2E test (full pipeline: winmd → generate → call real WinRT APIs)
.\tests\e2e\e2e_test.ps1 -SkipBuild -Lang pyE2E Testing
The E2E test framework validates the full pipeline: reading .winmd metadata → generating code → calling real Windows APIs.
How it works
- Test specs are defined in
tests/e2e/e2e_specs.json(schema:tests/e2e/e2e_specs.schema.json) — each entry describes:instantiate: how to create an instance (activate,static_factory, ornone)checks: array of assertions (property_equals,property_exists,method_equals,method_result_contains,static_equals,static_not_null)
- Runners (
tests/e2e/runners/py_runner.py,tests/e2e/runners/ts_runner.ts,tests/e2e/runners/com/*.mjs, andtests/e2e/runners/win32/*.mjs) execute generated WinRT, Classic COM, and flat Win32 bindings. - Orchestrator (
tests/e2e/e2e_test.ps1) handles build, temporary code generation, and runner invocation. Use-Lang comfor Classic COM or-Lang win32for flat Win32; both requireDYNWINRT_WIN32_WINMDor an installedMicrosoft.Windows.SDK.Win32Metadatapackage. - Adding new test cases: Add entries to
tests/e2e/e2e_specs.json:
{
"namespace": "Windows.Foundation",
"class": "Uri",
"langs": ["py", "ts"],
"instantiate": { "kind": "static_factory", "method": "create_uri", "args": ["https://example.com"] },
"checks": [
{ "kind": "property_equals", "member": "host", "expected": "example.com" },
{ "kind": "method_result_contains", "member": "combine_uri", "args": ["sub/page"], "contains": "sub/page" },
{ "kind": "static_equals", "member": "escape_component", "args": ["hello world"], "expected": "hello%20world" }
]
}Testable WinRT APIs (no extra dependencies needed)
These APIs are available on any Windows 10/11 machine without WinAppSDK:
Windows.Foundation: Uri, PropertyValue, WwwFormUrlDecoder, MemoryBuffer, DeferralWindows.Data.Xml.Dom: XmlDocument (has circular import issue in Python codegen)Windows.Globalization: Calendar, Language, GeographicRegion, CurrencyIdentifiersWindows.Devices.Geolocation: Geopoint (factory with struct parameter)Windows.Storage.Streams: BufferWindows.Security.Cryptography: CryptographicBuffer
Architecture Notes
Type System Flow
.winmd metadata → MetadataTable (arena) → TypeHandle → MethodHandle → libffi call → WinRTValueKey Design Decisions
- MetadataTable is a global singleton (
LazyLock<Arc<MetadataTable>>) shared across all bindings - Interface registration is by IID (GUID) — each IID maps to one vtable with methods
- Method invocation returns a single
WinRTValue(not a list) in Python binding - Generated code uses relative imports (
from .module import Class) — must be in a Python package
Classic COM implementation rule
For Classic COM, Windows.Win32 metadata, pointer, handle, ownership, or native
ABI changes, follow
classic-com-abi. Model native type plus
parameter contract before language projection, keep COM separate from WinRT,
and fail closed when layout or ownership is incomplete. JavaScript ergonomics
belong to the codegen projection layer; the renderer must not infer ABI
semantics. Classic COM changes must preserve existing WinRT models, generated
output, runtime behavior, and the @microsoft/dynwinrt root API.
Code Generator (dynwinrt-codegen)
src/codegen/project.rs+src/codegen/projected.rs— Build the language-neutralProjectedFileIR from parsed metadatasrc/codegen/render_js.rs+src/codegen/render_dts.rs— Render IR to.jsand.d.tssrc/codegen/python.rs+src/codegen/py_method.rs+src/codegen/python_stub.rs— Python.pyand.pyigenerationsrc/codegen/common.rs— Shared helpers (type mapping, argument wrapping, return conversion)src/codegen/typescript.rs+src/codegen/method.rs— Index-file generation and ESM/CJS shim helpers (name is historical; no longer emits stand-alone.tsoutput)--lang js(default) generates.js+ ambient.d.tswith theDynWinRtType/DynWinRtValueAPI (camelCase)--lang pygenerates.py,.pyi, and apy.typedmarker by default using theDynWinRTType/DynWinRTValueAPI (snake_case);--no-pyiopts out
Python Binding API Names
- Types:
DynWinRTType.i32_type(),DynWinRTType.hstring(),DynWinRTType.bool_type(), etc. - Values:
DynWinRTValue.from_i32(),DynWinRTValue.from_hstring(),DynWinRTValue.from_bool() - GUID:
WinGUID.parse('...') - Method call:
method_handle.invoke(obj, [args])→ returns singleDynWinRTValue IReference<T>values project as native values plusNone; generatedIReference_*wrappers remain accepted for input compatibility- Generated
Objectpositions stay rawDynWinRTValues;unbox_object(raw, preserve_type=False)andto_winrt_object(value, property_type=None)convert boxed values explicitly, with tags, typed arrays,Point/Size/RectandPropertyTypeindynwinrt.values(never guess a WinRT type) dynwinrt.values.object_value_view(map, preserve_type=False)is the opt-in, live converting view of a generated map that QueryInterface confirms asIMap/IMapView<String or Guid, Object>; reads unbox, writes useto_winrt_object, andview.rawstays native
Common Issues
test_initializeis#[ignore]— requiresWINAPPSDK_BOOTSTRAP_DLL_PATHenv var- Python
@propertymust come before@prop.setter— codegen reorders methods for this - Windows SDK winmd is at
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0\Windows.winmd
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

