Skip to content

Commit

Permalink
Build custom profile instead of setting LTO in environment (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
thenextman authored Dec 7, 2021
1 parent 99b036d commit 5d767ba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
38 changes: 13 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# Continuous integration and deploymnent workflow for devolutions-gateway
# Builds on master will require approval to:
# - code sign binaries
# - build and upload containers to docker hub
# - create a GitHub release
# - upload PowerShell module to PSGallery

name: CI

Expand All @@ -23,6 +18,7 @@ jobs:
outputs:
version: ${{ steps.get-version.outputs.version }}
rust-channel: ${{ steps.rust-toolchain.outputs.rust-channel }}
rust-profile: ${{ steps.rust-profile.outputs.rust-profile }}

steps:
- name: Checkout ${{ github.repository }}
Expand Down Expand Up @@ -52,11 +48,17 @@ jobs:
exit 1
fi
- name: Check lto
- name: Configure rust profile
id: rust-profile
shell: pwsh
if: ${{ github.ref != 'refs/heads/master' }}
run: |
echo "::warning::Building branch; LTO will not be enabled"
$CargoProfile = "release"
if ("${{ github.ref }}" -Eq "refs/heads/master") {
echo "::notice::Building production profile"
$CargoProfile = "production"
}
echo "::set-output name=rust-profile::$CargoProfile"
- name: Upload version artifact
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -97,13 +99,6 @@ jobs:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v2

- name: Enable lto
shell: pwsh
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "CARGO_PROFILE_RELEASE_LTO=true" >> $GITHUB_ENV
echo "::notice::Building master; LTO is enabled"
- name: Load dynamic variables
id: load-variables
shell: pwsh
Expand Down Expand Up @@ -164,7 +159,7 @@ jobs:
$Env:CARGO_FEATURES = "native-tls"
}
./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }}
./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
- name: Upload artifacts
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -194,13 +189,6 @@ jobs:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v2

- name: Enable lto
shell: pwsh
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "CARGO_PROFILE_RELEASE_LTO=true" >> $GITHUB_ENV
echo "::notice::Building master; LTO is enabled"
- name: Load dynamic variables
id: load-variables
shell: pwsh
Expand Down Expand Up @@ -259,7 +247,7 @@ jobs:
DGATEWAY_EXECUTABLE: ${{ steps.load-variables.outputs.dgateway-executable }}
CARGO_PACKAGE: ${{ steps.load-variables.outputs.cargo-package }}
run: |
./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }}
./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
- name: Build PowerShell module
if: matrix.os == 'windows'
Expand All @@ -279,7 +267,7 @@ jobs:
$Env:DGATEWAY_PSMODULE_CLEAN = "1"
}
./ci/tlk.ps1 package -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }}
./ci/tlk.ps1 package -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
- name: Upload artifacts
uses: actions/upload-artifact@v2
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ default-members = [
"jet-proto",
"jetsocat",
]

[profile.production]
inherits = "release"
lto = true
17 changes: 14 additions & 3 deletions ci/tlk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TlkTarget
{
[string] $Platform
[string] $Architecture
[string] $CargoProfile

[string] $ExecutableExtension

Expand Down Expand Up @@ -291,7 +292,10 @@ class TlkRecipe
$CargoTarget = $this.Target.CargoTarget()
Write-Host "CargoTarget: $CargoTarget"

$CargoArgs = @('build', '--release')
$CargoProfile = $this.Target.CargoProfile
Write-Host "CargoProfile": $CargoProfile

$CargoArgs = @('build', '--profile', $CargoProfile)
$CargoArgs += @('--target', $CargoTarget)
if (Test-Path Env:CARGO_NO_DEFAULT_FEATURES) {
$CargoArgs += @('--no-default-features')
Expand All @@ -303,7 +307,7 @@ class TlkRecipe
& 'cargo' $CargoArgs

$SrcExecutableName = $CargoPackage, $this.Target.ExecutableExtension -ne '' -Join '.'
$SrcExecutablePath = "$($this.SourcePath)/target/${CargoTarget}/release/${SrcExecutableName}"
$SrcExecutablePath = "$($this.SourcePath)/target/${CargoTarget}/${CargoProfile}/${SrcExecutableName}"

if (-Not $this.Target.IsWindows()) {
& 'strip' $SrcExecutablePath
Expand Down Expand Up @@ -576,7 +580,9 @@ function Invoke-TlkStep {
[ValidateSet('windows','macos','linux')]
[string] $Platform,
[ValidateSet('x86','x86_64','arm64')]
[string] $Architecture
[string] $Architecture,
[ValidateSet('release', 'production')]
[string] $CargoProfile
)

if (-Not $Platform) {
Expand All @@ -587,12 +593,17 @@ function Invoke-TlkStep {
$Architecture = Get-TlkArchitecture
}

if (-Not $CargoProfile) {
$CargoProfile = 'release'
}

$RootPath = Split-Path -Parent $PSScriptRoot

$tlk = [TlkRecipe]::new()
$tlk.SourcePath = $RootPath
$tlk.Target.Platform = $Platform
$tlk.Target.Architecture = $Architecture
$tlk.Target.CargoProfile = $CargoProfile

switch ($TlkVerb) {
"build" { $tlk.Build() }
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.56.0"
channel = "1.57.0"

0 comments on commit 5d767ba

Please sign in to comment.