From a0790bc050dd57765f005fc6fe6dc34e59fbbfe4 Mon Sep 17 00:00:00 2001 From: Iain McGinniss <309153+iainmcgin@users.noreply.github.com> Date: Wed, 29 Apr 2026 20:10:59 +0000 Subject: [PATCH] build: enable lto + codegen-units=1 for release profile (#60) Shrinks the prebuilt protoc-gen-buffa* release binaries by ~20% at the cost of ~2x clean release-build time. Only the workspace root profile is set (Cargo ignores per-crate profile sections inside a workspace, and the warning noise outweighs the cargo-install benefit); the guide documents the CARGO_PROFILE_RELEASE_LTO env-var path for cargo install users, and the CHANGELOG notes that library consumers do not inherit this. --- CHANGELOG.md | 11 +++++++++++ Cargo.toml | 8 ++++++++ docs/guide.md | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 621c695..8a31af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Changed + +- The workspace `[profile.release]` now sets `lto = true` and + `codegen-units = 1`. This shrinks the prebuilt `protoc-gen-buffa` / + `protoc-gen-buffa-packaging` release binaries by roughly 20% at the cost of + ~2× clean release-build time. Cargo only honors profile sections from the + top-level workspace, so library consumers of `buffa` / `buffa-build` do not + inherit this — set `[profile.release]` in your own workspace (or + `CARGO_PROFILE_RELEASE_LTO=true` for `cargo install`) to get the same + benefit. ([#60](https://github.com/anthropics/buffa/issues/60)) + ### Fixed - `write_to` now emits fields in ascending field-number order regardless of diff --git a/Cargo.toml b/Cargo.toml index 29afb6d..259fb65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,14 @@ repository = "https://github.com/anthropics/buffa" keywords = ["protobuf", "protocol-buffers", "serialization", "no-std", "editions"] categories = ["encoding", "no-std"] +# Applies to release builds within this workspace (CI-built release binaries, +# benchmarks, conformance). Library consumers do not inherit this — Cargo only +# honors [profile.*] from the top-level workspace, so a project depending on +# buffa/buffa-build must set its own [profile.release] to get LTO. +[profile.release] +lto = true +codegen-units = 1 + [workspace.dependencies] buffa = { path = "buffa", version = "0.4.0", default-features = false } buffa-types = { path = "buffa-types", version = "0.4.0" } diff --git a/docs/guide.md b/docs/guide.md index 9954766..339affe 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -283,6 +283,13 @@ From crates.io (recommended): cargo install --locked protoc-gen-buffa protoc-gen-buffa-packaging ``` +`cargo install` builds with its own default release profile, so the workspace's `lto = true` / `codegen-units = 1` settings (used for the prebuilt release binaries below) are not applied. For the smallest binary, set them via the environment: + +```sh +CARGO_PROFILE_RELEASE_LTO=true CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \ + cargo install --locked protoc-gen-buffa protoc-gen-buffa-packaging +``` + Or from a git ref, for unreleased changes: ```sh