From b90f33e582256cf890e5b43b8c2d4d9cba02db7e Mon Sep 17 00:00:00 2001 From: Caleb Leak Date: Fri, 1 May 2026 21:17:30 -0700 Subject: [PATCH] Build Tempyr before installing --- docs/install.md | 18 ++++++++++--- install.ps1 | 67 +++++++++++++++++++++++++++++++++++++++---------- install.sh | 9 +++++++ 3 files changed, 78 insertions(+), 16 deletions(-) diff --git a/docs/install.md b/docs/install.md index 6590dab..bb948f8 100644 --- a/docs/install.md +++ b/docs/install.md @@ -10,7 +10,13 @@ Run: bash install.sh ``` -The script installs Tempyr with: +The script first builds Tempyr in release mode: + +```bash +cargo build --release --manifest-path crates/tempyr-cli/Cargo.toml --locked --bin tempyr +``` + +Then it installs Tempyr with: ```bash cargo install --path crates/tempyr-cli --root "${XDG_DATA_HOME:-$HOME/.local/share}/tempyr" --locked --force --bin tempyr @@ -32,7 +38,13 @@ Run: powershell -ExecutionPolicy Bypass -File .\install.ps1 ``` -The script installs Tempyr with: +The script first builds Tempyr in release mode: + +```powershell +cargo build --release --manifest-path .\crates\tempyr-cli\Cargo.toml --locked --bin tempyr +``` + +Then it installs Tempyr with: ```powershell cargo install --path .\crates\tempyr-cli --root "$Env:LocalAppData\Tempyr" --locked --force --bin tempyr @@ -48,7 +60,7 @@ If you want `install.ps1` to skip user `PATH` changes, pass `-NoPathUpdate`: ## Updating safely -Rerun the installer to update Tempyr. Both installers check whether the target Tempyr binary is already in use before invoking `cargo install`. If it is, they only stop processes whose executable path exactly matches the target installed binary. They do not kill processes based on name alone. +Rerun the installer to update Tempyr. Both installers run the release build before checking whether the target Tempyr binary is already in use, so compile failures do not interrupt a currently running installed binary. If the target binary is in use, they only stop processes whose executable path exactly matches the target installed binary. They do not kill processes based on name alone. If the binary becomes locked during the install anyway, the installers stop matching Tempyr processes and retry. On Windows, the installer also waits and retries a few times before failing when the lock appears to be transient. diff --git a/install.ps1 b/install.ps1 index 7923af6..1b0abdb 100644 --- a/install.ps1 +++ b/install.ps1 @@ -323,33 +323,25 @@ function ConvertTo-WindowsArgument { return $builder.ToString() } -function Invoke-CargoInstall { +function Invoke-CargoCommand { param( [Parameter(Mandatory)] - [string]$CratePath, + [string[]]$Arguments, [Parameter(Mandatory)] - [string]$InstallRootPath + [string]$WorkingDirectory ) $cargoExe = (Get-Command cargo -ErrorAction Stop).Source - $cargoArgs = @( - "install", - "--path", $CratePath, - "--root", $InstallRootPath, - "--locked", - "--force", - "--bin", "tempyr" - ) $stdoutFile = New-TemporaryFile $stderrFile = New-TemporaryFile try { # Windows PowerShell 5.1 turns native stderr into a terminating NativeCommandError # when ErrorActionPreference=Stop, even for cargo's normal progress output. - $argumentLine = ($cargoArgs | ForEach-Object { ConvertTo-WindowsArgument -Value "$_" }) -join ' ' + $argumentLine = ($Arguments | ForEach-Object { ConvertTo-WindowsArgument -Value "$_" }) -join ' ' $process = Start-Process ` -FilePath $cargoExe ` -ArgumentList $argumentLine ` - -WorkingDirectory $CratePath ` + -WorkingDirectory $WorkingDirectory ` -RedirectStandardOutput $stdoutFile.FullName ` -RedirectStandardError $stderrFile.FullName ` -NoNewWindow ` @@ -381,6 +373,53 @@ function Invoke-CargoInstall { } } +function Invoke-CargoInstall { + param( + [Parameter(Mandatory)] + [string]$CratePath, + [Parameter(Mandatory)] + [string]$InstallRootPath + ) + + $cargoArgs = @( + "install", + "--path", $CratePath, + "--root", $InstallRootPath, + "--locked", + "--force", + "--bin", "tempyr" + ) + + return Invoke-CargoCommand -Arguments $cargoArgs -WorkingDirectory $CratePath +} + +function Invoke-CargoBuild { + param( + [Parameter(Mandatory)] + [string]$CratePath + ) + + $cargoArgs = @( + "build", + "--release", + "--manifest-path", (Join-Path $CratePath "Cargo.toml"), + "--locked", + "--bin", "tempyr" + ) + + $buildResult = Invoke-CargoCommand -Arguments $cargoArgs -WorkingDirectory $CratePath + if ($buildResult.ExitCode -ne 0) { + $message = "cargo build --release failed with exit code $($buildResult.ExitCode)." + if (-not [string]::IsNullOrWhiteSpace($buildResult.Output)) { + $output = $buildResult.Output.TrimEnd() + if (-not [string]::IsNullOrWhiteSpace($output)) { + $message = "$message`n$output" + } + } + throw $message + } +} + function Invoke-CargoInstallWithLockRecovery { param( [Parameter(Mandatory)] @@ -455,6 +494,8 @@ if (-not (Test-Path -LiteralPath (Join-Path $cratePath "Cargo.toml"))) { throw "Could not find crates/tempyr-cli/Cargo.toml relative to $scriptRoot." } +Invoke-CargoBuild -CratePath $cratePath + $installResult = Invoke-CargoInstallWithLockRecovery ` -CratePath $cratePath ` -InstallRootPath $InstallRoot ` diff --git a/install.sh b/install.sh index fbd6b24..1944dc9 100644 --- a/install.sh +++ b/install.sh @@ -83,6 +83,14 @@ run_cargo_install() { return "$status" } +run_cargo_build() { + cargo build \ + --release \ + --manifest-path "$CRATE_PATH/Cargo.toml" \ + --locked \ + --bin tempyr +} + preflight_locked_target() { [[ -e "$TARGET_BIN" ]] || return 0 @@ -313,6 +321,7 @@ ensure_path_persistence() { esac } +run_cargo_build preflight_locked_target run_cargo_install || {