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
500 changes: 438 additions & 62 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

48 changes: 18 additions & 30 deletions .pipelines/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ extends:
- checkout: self
fetchDepth: 0

- task: PowerShell@2
displayName: Validate GitHub release notes
inputs:
targetType: filePath
filePath: eng/release/validate_release_notes.ps1

- task: PowerShell@2
displayName: Test GitHub release notes validation
inputs:
targetType: filePath
filePath: eng/release/test_validate_release_notes.ps1

- task: UseNode@1
displayName: Setup Node.js 24
inputs:
Expand Down Expand Up @@ -193,11 +205,10 @@ extends:
$tag = "$(Build.SourceBranchName)"
$version = $tag -replace '^v', ''
$isPrerelease = if ($version -match '-') { 'true' } else { 'false' }
$releaseLabel = if ($isPrerelease -eq 'true') { 'Prerelease' } else { 'Release' }

Write-Host "Publishing version: $version"
echo "##vso[task.setvariable variable=version;isOutput=true]$version"
echo "##vso[task.setvariable variable=isPrerelease;isOutput=true]$isPrerelease"
echo "##vso[task.setvariable variable=releaseLabel;isOutput=true]$releaseLabel"

# Update package.json versions
$jsPackage = Get-Content "bindings/js/package.json" | ConvertFrom-Json
Expand Down Expand Up @@ -325,7 +336,6 @@ extends:
variables:
version: $[ stageDependencies.Build.Build.outputs['SetMeta.version'] ]
isPrerelease: $[ stageDependencies.Build.Build.outputs['SetMeta.isPrerelease'] ]
releaseLabel: $[ stageDependencies.Build.Build.outputs['SetMeta.releaseLabel'] ]
jobs:
- job: create_github_release
pool:
Expand All @@ -342,6 +352,9 @@ extends:
artifactName: npm-packages
targetPath: $(Pipeline.Workspace)/npm-packages
steps:
- checkout: self
fetchDepth: 1

- task: GitHubRelease@1
displayName: Create GitHub Release
inputs:
Expand All @@ -352,33 +365,8 @@ extends:
tagSource: 'userSpecifiedTag'
tag: 'v$(version)'
title: 'v$(version)'
releaseNotesSource: 'inline'
releaseNotesInline: |
## $(releaseLabel) v$(version)

**Packages:**
- `@microsoft/dynwinrt` - JavaScript/TypeScript bindings for WinRT dynamic invocation
- `@microsoft/dynwinrt-codegen` - Code generation tool for typed WinRT bindings
- `dynwinrt` - Native Python runtime for generated WinRT projections
- `dynwinrt-codegen` - Standalone Python code generation tool

## Installation

```bash
npm install @microsoft/dynwinrt
npm install -D @microsoft/dynwinrt-codegen
python -m pip install --pre dynwinrt dynwinrt-codegen
```

## What's Included

- ✅ Native addons for x64 and ARM64
- ✅ TypeScript type definitions
- ✅ dynwinrt-codegen CLI for code generation
- ✅ CPython 3.11–3.14 runtime wheels for Windows x64 and ARM64
- ✅ Standalone Python codegen wheels for Windows x64 and ARM64

For usage instructions, see the [README](https://github.com/microsoft/dynwinrt#readme).
releaseNotesSource: 'filePath'
releaseNotesFilePath: '$(Build.SourcesDirectory)/eng/release/RELEASE_NOTES.md'
assets: '$(Pipeline.Workspace)/npm-packages/*.tgz'
isDraft: false
isPreRelease: $(isPrerelease)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ builds, test suites, and contribution guidelines.

## Contributing

See the [Build CI guide](docs/guides/development/ci.md) for parallel validation,
artifact reuse, documentation-only PR checks, and running E2E with a prebuilt generator.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://cla.opensource.microsoft.com>.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
Expand Down
8 changes: 2 additions & 6 deletions bindings/js/__test__/borrowed-copy.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import test from 'ava'
import { spawnSync } from 'node:child_process'
import { mkdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { runCodegen } from '../scripts/run-codegen.mjs'

const packageRoot = resolve(process.cwd())
const repositoryRoot = resolve(packageRoot, '..', '..')
Expand All @@ -15,11 +16,6 @@ test.before((t) => {
t.truthy(winmd, 'Pinned DYNWINRT_WIN32_WINMD is required')
rmSync(output, { recursive: true, force: true })
const args = [
'run',
'--quiet',
'-p',
'dynwinrt-codegen',
'--',
'generate',
'--winmd',
winmd!,
Expand All @@ -29,7 +25,7 @@ test.before((t) => {
output,
]
for (const extra of [['--dry-run'], []]) {
const generated = spawnSync('cargo', [...args, ...extra], {
const generated = runCodegen([...args, ...extra], {
cwd: repositoryRoot,
encoding: 'utf8',
windowsHide: true,
Expand Down
16 changes: 3 additions & 13 deletions bindings/js/__test__/generated-unsafe-companion.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { spawnSync } from 'node:child_process'
import { lstatSync, readFileSync, readlinkSync, rmSync, mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'
import { basename, dirname, join, resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
import { runCodegen } from '../scripts/run-codegen.mjs'

test.serial('generated IUIAutomation unsafe companion parses and registers without native calls', (t) => {
const winmd = process.env.DYNWINRT_WIN32_WINMD
Expand All @@ -17,14 +18,8 @@ test.serial('generated IUIAutomation unsafe companion parses and registers witho
)

try {
const generation = spawnSync(
'cargo',
const generation = runCodegen(
[
'run',
'--quiet',
'-p',
'dynwinrt-codegen',
'--',
'generate',
'--winmd',
winmd!,
Expand Down Expand Up @@ -141,11 +136,6 @@ test.serial('generated safe COM and unsafe WinML companions preserve exact contr

try {
const generationArgs = [
'run',
'--quiet',
'-p',
'dynwinrt-codegen',
'--',
'generate',
'--winmd',
winmd!,
Expand All @@ -155,7 +145,7 @@ test.serial('generated safe COM and unsafe WinML companions preserve exact contr
output,
]
const runGeneration = (extraEnv: NodeJS.ProcessEnv = {}) =>
spawnSync('cargo', generationArgs, {
runCodegen(generationArgs, {
cwd: repositoryRoot,
encoding: 'utf8',
env: { ...process.env, DYNWINRT_CODEGEN_TEST_STRATEGY_RUNTIME: '1', ...extraEnv },
Expand Down
18 changes: 4 additions & 14 deletions bindings/js/__test__/native-completion.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import test from 'ava'
import { spawnSync } from 'node:child_process'
import { mkdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { runCodegen } from '../scripts/run-codegen.mjs'

const packageRoot = resolve(process.cwd())
const repositoryRoot = resolve(packageRoot, '..', '..')
Expand All @@ -17,11 +18,6 @@ test.before((t) => {
t.truthy(winmd, 'DYNWINRT_WIN32_WINMD is required for exact native-completion generation')
rmSync(output, { recursive: true, force: true })
const args = [
'run',
'--quiet',
'-p',
'dynwinrt-codegen',
'--',
'generate',
'--winmd',
winmd!,
Expand All @@ -30,28 +26,22 @@ test.before((t) => {
'--output',
output,
]
const dryRun = spawnSync('cargo', [...args, '--dry-run'], {
const dryRun = runCodegen([...args, '--dry-run'], {
cwd: repositoryRoot,
encoding: 'utf8',
windowsHide: true,
})
t.is(dryRun.status, 0, dryRun.stderr)
t.regex(dryRun.stdout, /Would generate ActivateAudioInterfaceAsync/)
const generation = spawnSync('cargo', args, {
const generation = runCodegen(args, {
cwd: repositoryRoot,
encoding: 'utf8',
windowsHide: true,
})
t.is(generation.status, 0, generation.stderr)
if (process.env.DYNWINRT_TEST_AUDIO_RENDER === '1') {
const renderDevice = spawnSync(
'cargo',
const renderDevice = runCodegen(
[
'run',
'--quiet',
'-p',
'dynwinrt-codegen',
'--',
'generate',
'--namespace',
'Windows.Media.Devices',
Expand Down
9 changes: 9 additions & 0 deletions bindings/js/scripts/run-codegen.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { SpawnSyncOptionsWithStringEncoding, SpawnSyncReturns } from 'node:child_process'

export declare function runCodegen(
args: string[],
options: SpawnSyncOptionsWithStringEncoding,
): SpawnSyncReturns<string>
24 changes: 24 additions & 0 deletions bindings/js/scripts/run-codegen.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { spawnSync } from 'node:child_process'
import { statSync } from 'node:fs'
import { resolve } from 'node:path'

/**
* An explicit artifact path must never fall back to a local Cargo build.
* @param {string[]} args
* @param {import('node:child_process').SpawnSyncOptionsWithStringEncoding} options
*/
export function runCodegen(args, options) {
const codegen = (options.env ?? process.env).DYNWINRT_CODEGEN
if (codegen !== undefined) {
if (!codegen.trim()) throw new Error('DYNWINRT_CODEGEN must name a prebuilt dynwinrt-codegen executable')
const executable = resolve(options.cwd?.toString() ?? process.cwd(), codegen)
if (!statSync(executable).isFile()) throw new Error(`Prebuilt dynwinrt-codegen is not a file: ${executable}`)
const result = spawnSync(executable, args, options)
if (result.error) throw result.error
return result
}
return spawnSync('cargo', ['run', '--quiet', '-p', 'dynwinrt-codegen', '--', ...args], options)
}
72 changes: 72 additions & 0 deletions bindings/js/scripts/run-codegen.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import assert from 'node:assert/strict'
import childProcess from 'node:child_process'
import { mkdtempSync, rmSync } from 'node:fs'
import { syncBuiltinESMExports } from 'node:module'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { test } from 'node:test'
import { runCodegen } from './run-codegen.mjs'

test('prebuilt invocation executes the selected file, arguments and environment without Cargo', () => {
const env = { ...process.env, DYNWINRT_CODEGEN: process.execPath, CODEGEN_SENTINEL: 'forwarded' }
const result = runCodegen(['-e', 'console.log(process.env.CODEGEN_SENTINEL); process.exit(23)'], {
encoding: 'utf8',
env,
windowsHide: true,
})
assert.equal(result.status, 23)
assert.equal(result.stdout.trim(), 'forwarded')
})

test('an invalid executable reports its launch error without trying Cargo', (t) => {
const calls = []
const error = new Error('not a valid executable')
t.mock.method(childProcess, 'spawnSync', (...args) => {
calls.push(args)
return { error, status: null, stdout: null, stderr: null }
})
syncBuiltinESMExports()
try {
assert.throws(
() => runCodegen(['generate'], { encoding: 'utf8', env: { DYNWINRT_CODEGEN: process.execPath } }),
(actual) => actual === error,
)
assert.equal(calls.length, 1)
assert.equal(calls[0][0], process.execPath)
} finally {
t.mock.restoreAll()
syncBuiltinESMExports()
}
})

test('invalid explicit paths never fall back; omission retains the developer Cargo command', (t) => {
const directory = mkdtempSync(join(tmpdir(), 'dynwinrt-codegen-selection-'))
const calls = []
t.mock.method(childProcess, 'spawnSync', (...args) => {
calls.push(args)
return { status: 31, stdout: '', stderr: 'cargo boundary' }
})
syncBuiltinESMExports()
try {
for (const path of ['', ' ', directory, join(directory, 'missing.exe')]) {
assert.throws(() => runCodegen(['generate'], { encoding: 'utf8', env: { DYNWINRT_CODEGEN: path } }))
}
assert.deepEqual(calls, [])
const options = { encoding: 'utf8', env: {}, cwd: directory }
assert.equal(runCodegen(['generate', '--output', 'a path with spaces'], options).status, 31)
assert.deepEqual(calls, [
[
'cargo',
['run', '--quiet', '-p', 'dynwinrt-codegen', '--', 'generate', '--output', 'a path with spaces'],
options,
],
])
} finally {
t.mock.restoreAll()
syncBuiltinESMExports()
rmSync(directory, { recursive: true, force: true })
}
})
Loading
Loading