11# !/usr/bin/env pwsh
2+ param (
3+ [Parameter (Mandatory = $false , HelpMessage = " The build profile to use, e.g. 'release' or 'dev'. Default is 'release'." )]
4+ [string ]$Profile = " release" ,
5+ [Parameter (Mandatory = $false , HelpMessage = " The toolchain to use, e.g. 'stable', 'nightly', etc. Default is 'stable'." )]
6+ [string ]$Toolchain = " stable" ,
7+ [Parameter (Mandatory = $false , HelpMessage = " Additional cargo arguments to pass" )]
8+ [string ]$CargoArgs = " " ,
9+ [Parameter (Mandatory = $false , HelpMessage = " Additional rustc arguments to pass" )]
10+ [string ]$RustcArgs = " " ,
11+ [Parameter (Mandatory = $false , HelpMessage = " Additional flags to set for the C compiler" )]
12+ [string ]$CCFlags = " "
13+ )
214
315$ErrorActionPreference = " Stop"
416
517$SCRIPT_DIR = Split-Path - Parent $MyInvocation.MyCommand.Path
618
719Set-Location $SCRIPT_DIR
820
9- if ($args.Count -eq 0 ) {
10- $profile = " release"
11- } else {
12- $profile = $args [0 ]
21+ Write-Host " Building libafl_libfuzzer runtime with profile '$Profile ' on toolchain '$Toolchain '" - ForegroundColor Green
22+ Invoke-Command - ScriptBlock {
23+ $env: RUSTFLAGS = $RustcArgs
24+ $env: CFLAGS = $CCFlags
25+ Write-Host " Using Rust flags: $env: RUSTFLAGS " - ForegroundColor Cyan
26+ Write-Host " Using Cargo arguments: $CargoArgs " - ForegroundColor Cyan
27+ Write-Host " Using C compiler flags: $env: CFLAGS " - ForegroundColor Cyan
28+ if ($CargoArgs ) {
29+ cargo + $Toolchain build -- profile $Profile $CargoArgs
30+ } else {
31+ cargo + $Toolchain build -- profile $Profile
32+ }
1333}
1434
15- Write-Host " Building libafl_libfuzzer runtime with profile '$profile '" - ForegroundColor Green
16- Invoke-Expression " cargo build --profile $profile "
1735
1836$tmpdir = Join-Path $env: TEMP ([System.IO.Path ]::GetRandomFileName())
1937New-Item - ItemType Directory - Path $tmpdir | Out-Null
@@ -25,13 +43,13 @@ function Cleanup {
2543}
2644
2745try {
28- if ($profile -eq " dev" ) {
46+ if ($Profile -eq " dev" ) {
2947 # Set the profile to debug for dev builds, because the path isn't the same
3048 # as the profile name
31- $profile = " debug"
49+ $Profile = " debug"
3250 }
3351
34- $targetPath = Join-Path $SCRIPT_DIR " target\$profile \afl_libfuzzer_runtime.lib"
52+ $targetPath = Join-Path $SCRIPT_DIR " target\$Profile \afl_libfuzzer_runtime.lib"
3553 $outputPath = Join-Path $SCRIPT_DIR " libFuzzer.lib"
3654
3755 Copy-Item - Path $targetPath - Destination $outputPath - Force | Out-Null
0 commit comments