Skip to content

Commit

Permalink
Reduce size of generated executable in release build
Browse files Browse the repository at this point in the history
  • Loading branch information
Spydr06 committed Jan 28, 2023
1 parent 99f46c8 commit 0c1d27e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ serde = {version = "1.0.147", features = ["derive"]}
log = "0.4.0"
env_logger = "0.9.0"
lazy_static = "1.4.0"

[profile.release]
strip = true # Automatically strip symbols from the binary.
lto = true
25 changes: 15 additions & 10 deletions make-dist.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ function Create-Shortcut {
$Shortcut.Save()
}

function Test-Remove {
param (
[string]$Path
)

if (Test-Path $Path) {
Write-Warning "Warn: Removing old file $Path."
Remove-Item -Path $Path
}
}

# go to script dir
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Push-Location $dir
# delete old files
if (Test-Path "$dist_dir\$shortcut") {
Write-Warning "Warn: Removing old shortcut $dist_dir\$shortcut."
Remove-Item -Path "$dist_dir\$shortcut"
}

if (Test-Path "$dist_dir\bin\$executable") {
Write-Warning "Warn: Removing old executable $dist_dir\bin\$executable."
Remove-Item -Path "$dist_dir\bin\$executable"
}
Test-Remove -Path $zip_name
Test-Remove -Path "$dist_dir\$shortcut"
Test-Remove -Path "$dist_dir\bin\$executable"

# compile for release
cargo rustc --release -- -Clink-args="-Wl,--subsystem,windows"
Expand Down Expand Up @@ -79,7 +84,7 @@ Push-Location $dir
Pop-Location # dist directory

# create the distributable zip archive
Compress-Archive -Path $dist_dir -Update -DestinationPath $zip_name
Compress-Archive -Path "$dist_dir\*" -Update -DestinationPath $zip_name

if (!(Test-Path $zip_name)) {
Write-Error "Error: $zip_name not created."
Expand Down

0 comments on commit 0c1d27e

Please sign in to comment.