11# Copyright (c) Microsoft Corporation.
22# Licensed under the MIT License.
33
4- # Runs all stand-alone example binaries in the workspace (or the specified package).
4+ # Runs all stand-alone example binaries in the workspace, optionally excluding
5+ # packages that cargo-delta has determined to be unaffected by recent changes.
56# Each example has a 30-second timeout to avoid misbehaving examples causing trouble.
67# Supports both .rs files and subdirectories with main.rs files.
78# Sets IS_TESTING=1 environment variable for each example run, to allow "test mode" differentiation.
@@ -10,14 +11,31 @@ param(
1011 [Parameter (Mandatory = $true )]
1112 [string ]$CargoProfile ,
1213
14+ # Run examples for a single workspace package only. Intended for the local
15+ # `just package=foo examples` flow. Mutually exclusive with -Exclude.
1316 [Parameter (Mandatory = $false )]
14- [string ]$Package = " "
17+ [string ]$Package = " " ,
18+
19+ # Raw cargo-style excludes string, e.g. "--exclude foo --exclude bar".
20+ # This matches the format produced by `impact -f cargo-excludes` and used
21+ # by other workflow steps (cargo build/test/doc), so the YAML can pass
22+ # `${{ needs.delta.outputs.exclude_not_affected }}` directly without any
23+ # additional reshaping. Using --workspace + --exclude (rather than -p X
24+ # -p Y) avoids cargo's ambiguity between workspace members and remote
25+ # crates of the same name.
26+ [Parameter (Mandatory = $false )]
27+ [string ]$Exclude = " "
1528)
1629
1730$ErrorActionPreference = " Stop"
1831# We disable this because we manually handle exit codes and do not want to fail fast.
1932$PSNativeCommandUseErrorActionPreference = $false
2033
34+ if ($Package -ne " " -and $Exclude -ne " " ) {
35+ Write-Host " ✗ -Package and -Exclude are mutually exclusive." - ForegroundColor Red
36+ exit 1
37+ }
38+
2139# We will make the assumption that all the packages are in the "crates" folder
2240$packages_root = Join-Path $PSScriptRoot " ../crates"
2341
@@ -33,22 +51,52 @@ $total_count = 0
3351$success_count = 0
3452$timeout_seconds = 30
3553
36- # Determine which packages to process
37- $packages_to_process = @ ()
38- if ($Package -eq " " ) {
39- # Get all workspace members (assuming here they are just subdirectories).
40- $workspace_members = Get-ChildItem - Path $packages_root - Directory | Where-Object { Test-Path (Join-Path $_.FullName " Cargo.toml" ) }
41- $packages_to_process = $workspace_members | ForEach-Object { $_.Name }
54+ # Workspace members live as subdirectories of crates/ with a Cargo.toml.
55+ $workspace_members = @ (Get-ChildItem - Path $packages_root - Directory | Where-Object { Test-Path (Join-Path $_.FullName " Cargo.toml" ) } | ForEach-Object { $_.Name })
56+
57+ if ($Package -ne " " ) {
58+ # Single-package mode: scope cargo to just this package (unambiguous since
59+ # we name a single workspace member).
60+ $packages_to_process = @ ($Package )
61+ $excluded_packages = @ ()
62+ $cargo_scope_args = @ (" --package" , $Package )
4263}
4364else {
44- $packages_to_process = @ ($Package )
65+ # Workspace mode: forward the cargo-excludes string to cargo and compute
66+ # the matching local iteration set.
67+ $excluded_packages = @ ($Exclude -split ' \s+' | Where-Object { $_ -and $_ -ne ' --exclude' })
68+ $packages_to_process = @ ($workspace_members | Where-Object { $excluded_packages -notcontains $_ })
69+ $cargo_scope_args = @ (" --workspace" )
70+ foreach ($pkg in $excluded_packages ) {
71+ $cargo_scope_args += @ (" --exclude" , $pkg )
72+ }
4573}
4674
4775Write-Host " Running examples for packages: $ ( $packages_to_process -join ' , ' ) "
76+ if ($excluded_packages.Count -gt 0 ) {
77+ Write-Host " Excluded packages: $ ( $excluded_packages -join ' , ' ) "
78+ }
4879Write-Host " Timeout per example: $timeout_seconds seconds"
4980Write-Host " Cargo profile: $CargoProfile "
5081Write-Host " "
5182
83+ if ($packages_to_process.Count -eq 0 ) {
84+ Write-Host " No packages to process after applying excludes; nothing to do." - ForegroundColor DarkGray
85+ exit 0
86+ }
87+
88+ # Pre-build all examples for the selected packages so that the per-example
89+ # timeout below only covers execution (and a fingerprint check), not the
90+ # compile + link cost. On Windows debug builds the link step alone for the
91+ # first example in a package can blow past the 30 s timeout.
92+ Write-Host " Pre-building examples for selected packages..." - ForegroundColor Cyan
93+ & cargo build -- examples -- profile $CargoProfile -- all- features -- locked @cargo_scope_args
94+ if ($LASTEXITCODE -ne 0 ) {
95+ Write-Host " ✗ Pre-build of examples failed with exit code $LASTEXITCODE " - ForegroundColor Red
96+ exit $LASTEXITCODE
97+ }
98+ Write-Host " "
99+
52100foreach ($pkg in $packages_to_process ) {
53101 $examples_dir = Join-Path $packages_root $pkg " examples"
54102
0 commit comments