From 0db783be40abd5cfdab6575b8811b6d640784f6d Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 28 Oct 2024 12:31:55 -0700 Subject: [PATCH] update build script to default to anonymous CFS and strip release binaries --- .cargo/config.toml | 2 +- build.ps1 | 38 +++++++++++++++------------- dsc_lib/Cargo.toml | 7 +++++ osinfo/Cargo.toml | 7 ++++- registry/Cargo.toml | 3 --- runcommandonset/Cargo.toml | 7 ++++- security_context_lib/Cargo.toml | 7 +++++ tree-sitter-dscexpression/Cargo.toml | 7 +++++ y2j/Cargo.toml | 7 +++++ 9 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 8945e070..7e2bf62b 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,7 +3,7 @@ registry-auth = true [registries] -POWERSHELL = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/" } +POWERSHELL = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" } [registry] global-credential-providers = ["cargo:token"] diff --git a/build.ps1 b/build.ps1 index 839c2ad2..9cc8b4b1 100644 --- a/build.ps1 +++ b/build.ps1 @@ -15,7 +15,8 @@ param( [switch]$UseX64MakeAppx, [switch]$UseCratesIO, [switch]$UpdateLockFile, - [switch]$Audit + [switch]$Audit, + [switch]$UseCFSAuth ) if ($GetPackageVersion) { @@ -191,25 +192,26 @@ if (!$SkipBuild) { ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null $env:CARGO_REGISTRIES_CRATESIO_INDEX = $null - if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) { - throw "Azure CLI not found" - } + if ($UseCFSAuth -or $null -ne $env:TF_BUILD) { + if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) { + throw "Azure CLI not found" + } - if ($null -ne (Get-Command az -ErrorAction Ignore)) { - Write-Host "Getting token" - $accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv - if ($LASTEXITCODE -ne 0) { - Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access." - $env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" - } else { - $header = "Bearer $accessToken" - $env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header - $env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token' + if ($null -ne (Get-Command az -ErrorAction Ignore)) { + Write-Host "Getting token" + $accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv + if ($LASTEXITCODE -ne 0) { + Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access." + } else { + $header = "Bearer $accessToken" + $env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/" + $env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header + $env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token' + } + } + else { + Write-Warning "Azure CLI not found, proceeding with anonymous access." } - } - else { - Write-Warning "Azure CLI not found, proceeding with anonymous access." - $env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" } } diff --git a/dsc_lib/Cargo.toml b/dsc_lib/Cargo.toml index e49321b0..049dab8b 100644 --- a/dsc_lib/Cargo.toml +++ b/dsc_lib/Cargo.toml @@ -3,6 +3,13 @@ name = "dsc_lib" version = "3.0.0" edition = "2021" +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true + [dependencies] base64 = "0.22" chrono = "0.4" diff --git a/osinfo/Cargo.toml b/osinfo/Cargo.toml index b83f0e7d..f339f9df 100644 --- a/osinfo/Cargo.toml +++ b/osinfo/Cargo.toml @@ -3,7 +3,12 @@ name = "osinfo" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true [dependencies] os_info = { version = "3.7" } diff --git a/registry/Cargo.toml b/registry/Cargo.toml index 2550f8d1..b8c8a8f6 100644 --- a/registry/Cargo.toml +++ b/registry/Cargo.toml @@ -10,9 +10,6 @@ opt-level = 2 # enable link time optimization to remove dead code lto = true -[profile.dev] -lto = true - [dependencies] clap = { version = "4.5", features = ["derive"] } crossterm = "0.28" diff --git a/runcommandonset/Cargo.toml b/runcommandonset/Cargo.toml index 3eff0b7f..00d4a998 100644 --- a/runcommandonset/Cargo.toml +++ b/runcommandonset/Cargo.toml @@ -3,7 +3,12 @@ name = "runcommandonset" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true [dependencies] clap = { version = "4.4", features = ["derive"] } diff --git a/security_context_lib/Cargo.toml b/security_context_lib/Cargo.toml index eebb7cff..75184245 100644 --- a/security_context_lib/Cargo.toml +++ b/security_context_lib/Cargo.toml @@ -3,6 +3,13 @@ name = "security_context_lib" version = "0.1.0" edition = "2021" +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true + [target.'cfg(target_os = "windows")'.dependencies] is_elevated = "0.1" diff --git a/tree-sitter-dscexpression/Cargo.toml b/tree-sitter-dscexpression/Cargo.toml index e0e4a05d..689dbfc8 100644 --- a/tree-sitter-dscexpression/Cargo.toml +++ b/tree-sitter-dscexpression/Cargo.toml @@ -19,6 +19,13 @@ include = [ [lib] path = "bindings/rust/lib.rs" +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true + [dependencies] tree-sitter-rust = "0.23" tree-sitter = "0.24" diff --git a/y2j/Cargo.toml b/y2j/Cargo.toml index c0729cfc..7e65656f 100644 --- a/y2j/Cargo.toml +++ b/y2j/Cargo.toml @@ -3,6 +3,13 @@ name = "y2j" version = "1.0.0" edition = "2021" +[profile.release] +strip = true +# optimize for size +opt-level = 2 +# enable link time optimization to remove dead code +lto = true + [dependencies] serde_json = { version = "1.0.0", features = ["preserve_order"] } serde_yaml = { version = "0.9.3" }