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
496 changes: 496 additions & 0 deletions .github/workflows/python-release.yml

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions .github/workflows/winui-arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Python WinUI ARM64

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

on:
workflow_dispatch:

jobs:
live-winui:
# This runner must have an interactive desktop session and the ARM64
# Microsoft.WindowsAppRuntime.2 framework installed.
runs-on: [self-hosted, Windows, ARM64, winui]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: NuGet/setup-nuget@v2

- name: Verify native ARM64 environment
shell: pwsh
run: |
python -c "import platform, struct; assert platform.machine().lower() in ('arm64', 'aarch64'); assert struct.calcsize('P') == 8"
$runtime = Get-AppxPackage Microsoft.WindowsAppRuntime.2 |
Where-Object Architecture -eq Arm64 |
Sort-Object Version -Descending |
Select-Object -First 1
if (-not $runtime) {
throw 'Microsoft.WindowsAppRuntime.2 ARM64 must be installed on the live WinUI runner'
}

- name: Restore WinAppSDK metadata and bootstrap
shell: pwsh
run: |
$packages = Join-Path $env:RUNNER_TEMP 'winappsdk'
nuget install Microsoft.WindowsAppSDK.Foundation -Version 2.3.5 -OutputDirectory $packages -DirectDownload -NonInteractive
nuget install Microsoft.WindowsAppSDK.InteractiveExperiences -Version 2.1.3 -OutputDirectory $packages -DirectDownload -NonInteractive
nuget install Microsoft.WindowsAppSDK.WinUI -Version 2.3.0 -OutputDirectory $packages -DirectDownload -NonInteractive

$winui = Get-ChildItem $packages -Filter Microsoft.UI.Xaml.winmd -File -Recurse |
Select-Object -First 1
$bootstrap = Get-ChildItem $packages -Filter Microsoft.WindowsAppRuntime.Bootstrap.dll -File -Recurse |
Where-Object FullName -Match 'runtimes[\\/]win-arm64[\\/]native' |
Select-Object -First 1
if (-not $winui -or -not $bootstrap) {
throw 'WinAppSDK metadata or ARM64 bootstrap DLL was not restored'
}

$refs = Get-ChildItem $packages -Filter *.winmd -File -Recurse |
Where-Object {
$_.FullName -ne $winui.FullName -and (
$_.FullName -Match 'Foundation' -or
$_.FullName -Match 'metadata[\\/]10\.0\.18362\.0' -or
$_.Name -eq 'Microsoft.UI.Text.winmd'
)
} |
Sort-Object FullName -Unique
$refList = Join-Path $env:RUNNER_TEMP 'winappsdk-refs.txt'
$refs.FullName | Set-Content -LiteralPath $refList -Encoding utf8

"WINUI_WINMD=$($winui.FullName)" >> $env:GITHUB_ENV
"WINUI_REFS=$refList" >> $env:GITHUB_ENV
"WINUI_BOOTSTRAP=$($bootstrap.FullName)" >> $env:GITHUB_ENV

- name: Build ARM64 codegen and Python runtime
shell: pwsh
run: |
cargo build -p dynwinrt-codegen --release
python -m venv bindings\py\.venv
$python = Join-Path $PWD 'bindings\py\.venv\Scripts\python.exe'
& $python -m pip install "maturin>=1.11,<2" --quiet
$env:VIRTUAL_ENV = Join-Path $PWD 'bindings\py\.venv'
Push-Location bindings\py
try {
& $python -m maturin develop --release
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally {
Pop-Location
}
"WINUI_PYTHON=$python" >> $env:GITHUB_ENV

- name: Run live Python WinUI ARM64 E2E
shell: pwsh
run: |
.\tests\python_winui_e2e.ps1 `
-WinuiWinmd $env:WINUI_WINMD `
-RefList $env:WINUI_REFS `
-BootstrapDll $env:WINUI_BOOTSTRAP `
-Major 2 `
-Minor 3 `
-Python $env:WINUI_PYTHON `
-SkipBuild
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,4 @@ bench-electron/out/
**/settings.local.json
# Generated E2E projections are recreated and removed by tests/e2e_test.ps1.
tests/e2e_generated/
.python-release/
45 changes: 36 additions & 9 deletions PYTHON_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ of a dynamic projection.
- [x] Accept `T | None` in `IReference<T>` input positions.
- [x] Project null reference returns and reference-array elements as `T | None`
consistently in runtime code and stubs.
- [x] Project `IReference<T>` struct fields as native `T | None` on reads while
accepting native values, `None`, and legacy wrappers on writes.
- [x] Preserve the full `UInt32` / `UInt64` range when converting to Python
integers.
- [x] Make Python stubs part of E2E and run a static type checker.
Expand All @@ -75,13 +77,21 @@ of a dynamic projection.

- [x] Execute all tests under `bindings/py/tests` in CI.
- [x] Build and install wheels before running Python E2E.
- [ ] Test supported CPython versions on x64 and ARM64.
- [ ] Remove unverified PyPy metadata or add real PyPy coverage.
- [ ] Derive the Python package version from the release tag.
- [ ] Complete the first live CPython 3.11–3.14 x64/ARM64 release-matrix run.
The native ARM64 jobs are configured on the existing self-hosted WinUI
runner and fail closed; local x64 validation does not count as ARM64
validation.
- [x] Remove unverified PyPy metadata.
- [x] Require `python-v<version>` release tags to match both Cargo package
versions rather than rewriting release sources in CI.
- [ ] Publish signed/provenanced wheels to an approved internal Python feed.
- [ ] Add Python wheel assets and installation notes to GitHub releases.
- [ ] Provide a Python-native or standalone codegen installation path.
- [ ] Add a clean-machine consumer test that uses only released artifacts.
- [x] Add a protected-environment, OIDC trusted-publishing path that requires
manual opt-in from an existing release tag.
- [x] Add complete tested Python wheel assets and installation notes to GitHub
releases.
- [x] Provide a Python-native codegen CLI wheel using maturin binary bindings.
- [x] Add clean, isolated wheel consumers that import/call stock WinRT and run
codegen with Cargo/Rust unavailable.

## P1: Python-native behavior

Expand Down Expand Up @@ -126,8 +136,17 @@ of a dynamic projection.
for parity and still exposes its raw ABI shape.
- [x] Keep protected composable constructors out of generated Python
`__init__` overloads.
- [ ] Hide or explicitly mark constructors for all system-returned classes.
- [ ] Add composition/aggregation support required by XAML runtime classes.
- [x] Make WinMD activation/composition metadata the constructor boundary:
system-returned and protected-composition classes retain native wrapping
but reject public construction and expose no constructible `.pyi` overload.
- [x] Add a reusable outer/inner aggregation host for public composable Python
subclasses, preserving controlling COM identity and inner ownership.
- [x] Add metadata-driven local overridable-interface vtables for public
composable subclasses, including native-invoked FrameworkElement
measure/arrange/template callbacks and fail-closed ABI validation.
- [x] Register arbitrary Python runtime-class names and compose them into the
XAML metadata-provider chain so custom types can be instantiated by name
from XAML markup.
- [ ] Make Windows App SDK initialization idempotent and version-aware.
- [ ] Auto-discover or explicitly provision the bootstrap DLL.
- [x] Expose the selected framework `resources.pri` path.
Expand All @@ -139,7 +158,14 @@ of a dynamic projection.
- [x] Validate worker-thread and `asyncio` scheduling while the WinUI
DispatcherQueue owns the UI thread, including a WinRT async completion
and `try_enqueue` back to the UI thread.
- [ ] Load Fluent Light, Dark, and High Contrast resources.
- [x] Add projected lifetime scopes that release UI/COM wrappers before
apartment teardown.
- [x] Add awaitable DispatcherQueue result/error/priority scheduling helpers.
- [x] Project `IObservableVector<T>` as a mutable Python sequence with typed
`VectorChanged` events.
- [x] Add a GIL-safe Python `IElementFactory` bridge and live ItemsRepeater
get/recycle identity coverage.
- [x] Load and validate Fluent Light, Dark, and High Contrast resources.
- [x] Add a real Python WinUI application E2E on x64.
- [ ] Add Python WinUI application E2E coverage on ARM64.

Expand Down Expand Up @@ -174,6 +200,7 @@ of a dynamic projection.
19. [x] Balance COM initialization with `RoApartment` and add deterministic `IClosable` cleanup.
20. [x] Make reference returns null-safe without lying in generated annotations.
21. [x] Preserve `UInt32` / `UInt64` values across the Python boundary.
22. [x] Project and box `IReference<T>` struct fields, including struct-valued `T`.
22. [x] Add typed event arguments while preserving token subscriptions and adding
idempotent unsubscribe helpers.
23. [x] Project public composable constructors and reject protected composition.
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ common-interface test matrix, unsupported native types, and ownership rules.
Generated bindings project unambiguous public WinRT activation metadata as JavaScript
constructors, including overloads such as `new Uri(base, relative)`. Existing
static factory methods remain available. Classes that can only be returned by
the system, or that expose only protected composition, remain non-constructible.
the system, or that expose only protected composition, remain non-constructible;
Python stubs do not advertise their internal native-value wrapping path.
Bindings also include async + progress support, generic collections
(`IVector<T>`, `IMap<K,V>`), structs, enums, and delegates — see
`tools/dynwinrt-codegen/npm/README.md` for the full feature list.
Expand Down Expand Up @@ -110,7 +111,7 @@ dynwinrt/
├── crates/dynwinrt/ # Core Rust runtime (FFI, metadata, async, delegates, collections)
├── bindings/
│ ├── js/ # @microsoft/dynwinrt — JS / TS bindings (napi-rs)
│ └── py/ # Python bindings (PyO3, experimental — not published)
│ └── py/ # Python bindings (PyO3; release workflow ready)
├── tools/
│ └── dynwinrt-codegen/ # @microsoft/dynwinrt-codegen — typed-binding generator
├── tests/ # Integration tests + sample E2E projects
Expand All @@ -135,6 +136,11 @@ cargo build -p dynwinrt-codegen --release
cargo run -p dynwinrt-codegen -- generate --namespace Windows.Foundation --class-name Uri --output ./generated
```

Python runtime wheels target CPython 3.11–3.14 on Windows x64 and ARM64. The
standalone `dynwinrt-codegen` Python wheel targets CPython 3.8–3.14 and needs no
Rust installation at consumption time. Release and trusted-publishing
instructions are in [`bindings/py/README.md`](bindings/py/README.md).

Python runtime, codegen, packaging, and WinUI readiness are tracked in
[`PYTHON_CHECKLIST.md`](PYTHON_CHECKLIST.md).

Expand Down
32 changes: 27 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ _None currently. Reserved for issues that make v0.1 unshippable (crash on happy

## P1 — Correctness / quality (near-term)

- [ ] **Complete the first native Python ARM64 release-matrix run**. The
fail-closed wheel workflow targets the existing
`[self-hosted, Windows, ARM64, winui]` runner for CPython 3.11–3.14, but this
worktree can validate only x64. Do not mark ARM64 wheels releasable until all
native consumer jobs have imported them and called `Windows.Foundation.Uri`.

- [ ] **Panic-free COM entrypoints**. Several `extern "system"` COM callbacks still `unwrap()` on raw pointer inputs, which is UB across the FFI boundary if a caller passes a bad pointer:
- `crates/dynwinrt/src/delegate.rs:309` — `IUnknown::from_raw_borrowed(&raw).unwrap()` inside `marshal_abi_ptr` (fires whenever WinRT passes a null pointer arg to a delegate; not just malicious callers)
- `crates/dynwinrt/src/com_helpers.rs:42, 53` — same pattern in `com_to_usize` / `com_usize_addref_out`
Expand All @@ -30,9 +36,15 @@ _None currently. Reserved for issues that make v0.1 unshippable (crash on happy

- [ ] **Codegen: `extract_iid` silently zero-fills malformed GuidAttribute**. `tools/dynwinrt-codegen/src/meta.rs:1030-1051` — if any GuidAttribute field is the wrong integer width, helpers return `0`, producing a plausible-but-wrong IID that will corrupt interface registration without any error. Treat non-matching shapes as a hard error / empty IID.

- [ ] **Codegen: generic ancestors are dropped from projected classes**. `tools/dynwinrt-codegen/src/meta.rs:717-760` — the inherited-interface flattening skips any ancestor whose `TypeName` has generics, so classes inheriting a generic interface via a base class lose those members. Resolve generic ancestors to concrete instantiations (or document + guard the gap).
- [x] **Codegen: project concrete generic ancestor interfaces**. Inherited generic
interfaces are resolved with their concrete arguments, deduplicated by full
instantiated identity, and covered with `ColorPaletteResources` inheriting
`IMap<Object, Object>` from `ResourceDictionary`.

- [ ] **Codegen: composable `.ctor` on instance interfaces**. Runtime classes whose instance interface exposes a bare `.ctor(IInspectable* base, IInspectable** inner)` (the COM aggregation pattern used by XAML) still fall through the generic instance-method path. Confirmed unaffected outside `Microsoft.UI.Xaml.*`. Minimal fix: skip `method.name == ".ctor"` in `codegen/method.rs` + TS/Py generators; the `add_method(".ctor", ...)` vtable entry can stay so parameterized IID computation is unaffected. Full fix requires composition/aggregation support — out of scope until we take on XAML hosting.
- [x] **Named Python XAML custom types**. Process-local registrations are chained
into the composed `IXamlMetadataProvider`; `XamlReader` activates generated
Python control subclasses by arbitrary qualified names and preserves native
overrides/identity. OS activation remains deliberately outside this boundary.

- [ ] **Codegen: default-interface lookup returns first hit**. `tools/dynwinrt-codegen/src/meta.rs:1075-1090` — `find_default_interface_iid` returns on the first `DefaultAttribute` it resolves, which may not be the actual default in edge cases with malformed metadata. Validate against parsed default interface metadata or fail loudly.

Expand All @@ -56,7 +68,14 @@ _None currently. Reserved for issues that make v0.1 unshippable (crash on happy

- [ ] **Nullable / `IReference<T>` handling**. Null COM pointers surface as `WinRTValue::Null`; codegen wrappers should surface `T | null` in `.d.ts` for these return positions.

- [ ] **`IReference<T>` as struct field**. `napi` has `getObject`/`setObject` and codegen has a fallback path, but this is exercised only by `Windows.Web.Http.HttpProgress` in Windows.winmd and untested. Add coverage.
- [x] **Python `IReference<T>` as struct field**. Generated structs read native
`T | None`, accept native values and legacy wrappers, and box through
`DynWinRTStruct.set_object`; covered by SDK `HttpProgress` and synthetic
`IReference<Point>`.
- [x] **JS `IReference<T>` as struct field**. Generated structs read native
`T | null`, accept native values, `null`, and legacy wrappers, and box
through `DynWinRtStruct.setObject`; covered by SDK `HttpProgress`,
synthetic `IReference<Point>`, and a runtime object-field round trip.

- [ ] **Guid array / bool array fast paths**. Currently per-element via `.toValues().map(...)`. Add `toGuidVec()` / `toBoolVec()` if any real workload hits these.

Expand All @@ -82,8 +101,8 @@ _None currently. Reserved for issues that make v0.1 unshippable (crash on happy
collections, structs, typed delegates/events, nullable references, and an
experimental WinUI Application bootstrap. Remaining work is tracked in
`PYTHON_CHECKLIST.md`, especially generated package layout, CPython/architecture
coverage, DispatcherQueue/GIL integration, general XAML aggregation, object
identity, and delegates with more than two ABI parameters.
coverage, native XAML custom-control registration/overrides, object identity,
and delegates with more than two ABI parameters.

- [ ] **Troubleshooting docs in READMEs**. Common failure modes not covered end-to-end: `WINAPPSDK_BOOTSTRAP_DLL_PATH` not set, mismatched apartment, missing capability. Root `README.md` has a small table; grow it based on the last three GitHub issues that repeated.

Expand Down Expand Up @@ -132,6 +151,9 @@ Kept for reference; git history is the source of truth. Grouped by area.
- [x] Python `.pyi` type stubs and `py.typed` marker by default with `--lang py`

### Distribution / CI
- [x] Python runtime wheel matrix for CPython 3.11–3.14 on x64/native ARM64,
standalone `py3-none-win_<arch>` codegen wheels, isolated artifact consumers,
GitHub release assets, and manual OIDC trusted-publishing gates
- [x] npm prebuilds for `win32-x64-msvc` + `win32-arm64-msvc`
- [x] `.github/workflows/build.yml` builds winrt-meta and dynwinrt-js on x64 + arm64, plus publishing and sample generation
- [x] `winapp init --add-js-bindings` toolchain integration
Expand Down
2 changes: 2 additions & 0 deletions bindings/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ methods remain available for compatibility.

Generated `IReference<T>` values use `T | null` in JavaScript. Native values,
`null`, and generated `IReference_*` wrappers are accepted as inputs.
The same projection applies when `IReference<T>` appears inside a WinRT struct;
packing boxes the field automatically and unpacking returns the native value.

Generated packages export `createProjectedLifetimeScope()`. WinUI/XAML hosts
can create a scope after Application and Window setup, then dispose it before
Expand Down
Loading
Loading