|
| 1 | +param( |
| 2 | + [string]$Device, |
| 3 | + [string[]]$Features |
| 4 | +) |
| 5 | + |
| 6 | +function Show-Usage { |
| 7 | + Write-Host "Usage:" |
| 8 | + Write-Host " .\build.ps1 # build all devices" |
| 9 | + Write-Host " .\build.ps1 -Device esp32 # build single device" |
| 10 | + Write-Host " .\build.ps1 -Features log,max-cpu-frequency # build with specified features" |
| 11 | + Write-Host "" |
| 12 | + Write-Host "Notes:" |
| 13 | + Write-Host " - The -Features parameter accepts multiple values or a comma-separated string." |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +# Remove existing YAML outputs (ignore errors if none exist) |
| 18 | +Remove-Item -Path output/*.yaml -Force -ErrorAction SilentlyContinue |
| 19 | + |
| 20 | +# map device -> target |
| 21 | +$deviceMap = @{ |
| 22 | + "esp32" = "xtensa-esp32-none-elf" |
| 23 | + "esp32s2" = "xtensa-esp32s2-none-elf" |
| 24 | + "esp32s3" = "xtensa-esp32s3-none-elf" |
| 25 | + "esp32c2" = "riscv32imc-unknown-none-elf" |
| 26 | + "esp32c3" = "riscv32imc-unknown-none-elf" |
| 27 | + "esp32c5" = "riscv32imac-unknown-none-elf" |
| 28 | + "esp32c6" = "riscv32imac-unknown-none-elf" |
| 29 | + # "esp32c61" = "riscv32imac-unknown-none-elf" |
| 30 | + "esp32h2" = "riscv32imac-unknown-none-elf" |
| 31 | +} |
| 32 | + |
| 33 | +# Validate device (if specified) and build list |
| 34 | +if ($Device) { |
| 35 | + if (-not $deviceMap.ContainsKey($Device)) { |
| 36 | + Write-Error "Unknown device: $Device. Valid devices are: $($deviceMap.Keys -join ', ')" |
| 37 | + Show-Usage |
| 38 | + } |
| 39 | + $devicesToBuild = @($Device) |
| 40 | +} else { |
| 41 | + $devicesToBuild = $deviceMap.Keys |
| 42 | +} |
| 43 | + |
| 44 | +# Normalize features passed via -Features (accepts array items and comma-separated strings) |
| 45 | +$parsedFeatures = @() |
| 46 | +if ($Features) { |
| 47 | + $joined = $Features -join ',' |
| 48 | + $parsedFeatures = $joined -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' } |
| 49 | +} |
| 50 | + |
| 51 | +# Deduplicate while preserving order |
| 52 | +$finalFeatures = @() |
| 53 | +foreach ($f in $parsedFeatures) { |
| 54 | + if (-not ($finalFeatures -contains $f)) { |
| 55 | + $finalFeatures += $f |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +# Build loop |
| 60 | +foreach ($d in $devicesToBuild) { |
| 61 | + $targetPath = ("target/{0}/release/esp-flashloader" -f ( $deviceMap[$d] )) |
| 62 | + Write-Host "=== Building $d ===" |
| 63 | + |
| 64 | + # Build cargo arguments |
| 65 | + $cargoArgs = @("+esp", $d) |
| 66 | + |
| 67 | + if ($finalFeatures.Count -gt 0) { |
| 68 | + $cargoArgs += "--features" |
| 69 | + $cargoArgs += ($finalFeatures -join ",") |
| 70 | + Write-Host ("running command: cargo {0}" -f ($cargoArgs -join ' ')) |
| 71 | + } else { |
| 72 | + Write-Host ("running command: cargo {0}" -f ($cargoArgs -join ' ')) |
| 73 | + } |
| 74 | + |
| 75 | + # Run cargo |
| 76 | + $cargoExit = & cargo @cargoArgs |
| 77 | + if ($LASTEXITCODE -ne 0) { |
| 78 | + Write-Error "cargo failed for device $d (exit code $LASTEXITCODE). Aborting." |
| 79 | + exit $LASTEXITCODE |
| 80 | + } |
| 81 | + |
| 82 | + # Run target-gen to produce YAML |
| 83 | + $outYaml = "output/$d.yaml" |
| 84 | + Write-Host "Generating YAML: $outYaml" |
| 85 | + & target-gen elf $targetPath $outYaml --name "$d-flashloader" |
| 86 | + if ($LASTEXITCODE -ne 0) { |
| 87 | + Write-Error "target-gen failed for device $d (exit code $LASTEXITCODE). Aborting." |
| 88 | + exit $LASTEXITCODE |
| 89 | + } |
| 90 | + |
| 91 | + Write-Host "" |
| 92 | +} |
| 93 | + |
| 94 | +Write-Host "All done." |
0 commit comments