From 0c57e655ed9d01547afaa06dec973ddd3b330fd5 Mon Sep 17 00:00:00 2001 From: Zihan Chen Date: Tue, 14 Nov 2023 18:43:04 -0800 Subject: [PATCH] crosvm: Add more release build profiles Add codegen-units=1 build profile to further reduce binary size and potentially improve performance. tools/build_release is updated to allow choice of build profiles. To keep binary size measurement trend consistent, release build recipe is running with chromeos profile. crosvm size of different profiles at current cl: relase profile (w/o strip symbols) 24192680, chromeos profile (strip symbols from release) 15088272, lto profile (fat lto & strip symbols) 14326144, largecodegen profile (codegen-units=1 w/ fat lto) 13764896 TEST=./tools/build_release --profile largecodegen BUG=b:181105093 Change-Id: I057ddfce3e78aa4dfe6b4810f4bcb1f13b954bb4 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5027712 Reviewed-by: Daniel Verkamp Auto-Submit: Zihan Chen Commit-Queue: Daniel Verkamp --- Cargo.toml | 5 +++++ infra/README.recipes.md | 2 +- infra/recipes/build_linux.expected/build_x86_64.json | 3 ++- infra/recipes/build_linux.py | 3 ++- tools/build_release | 6 +++++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67ac11dc26..32b18bc1d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,11 @@ strip = "symbols" inherits = "chromeos" lto = true +# Set codegen units to 1 to further reduce binary size. +[profile.largecodegen] +inherits = "lto" +codegen-units = 1 + [workspace] # Explicitly list all crates of crosvm as workspace members since not all of them may be referenced # by dependencies. diff --git a/infra/README.recipes.md b/infra/README.recipes.md index 44a9705fdc..5eb6f76c65 100644 --- a/infra/README.recipes.md +++ b/infra/README.recipes.md @@ -122,7 +122,7 @@ This recipe requires ambient luci authentication. To test locally run: [DEPS](/infra/recipes/build_linux.py#11): [crosvm](#recipe_modules-crosvm), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step] -— **def [RunSteps](/infra/recipes/build_linux.py#73)(api, properties):** +— **def [RunSteps](/infra/recipes/build_linux.py#74)(api, properties):** — **def [collect\_binary\_sizes](/infra/recipes/build_linux.py#24)(api, properties):** ### *recipes* / [build\_windows](/infra/recipes/build_windows.py) diff --git a/infra/recipes/build_linux.expected/build_x86_64.json b/infra/recipes/build_linux.expected/build_x86_64.json index 0fefa5a32e..fd0d46c99a 100644 --- a/infra/recipes/build_linux.expected/build_x86_64.json +++ b/infra/recipes/build_linux.expected/build_x86_64.json @@ -95,7 +95,8 @@ "./tools/build_release", "--json", "--platform=x86_64", - "--strip" + "--profile", + "chromeos" ], "cwd": "[CACHE]/builder/crosvm", "env": { diff --git a/infra/recipes/build_linux.py b/infra/recipes/build_linux.py index 820fc5ebed..c255b81b57 100644 --- a/infra/recipes/build_linux.py +++ b/infra/recipes/build_linux.py @@ -28,7 +28,8 @@ def collect_binary_sizes(api, properties): "./tools/build_release", "--json", "--platform=" + str(properties.test_arch), - "--strip", + "--profile", + "chromeos", ], stdout=api.raw_io.output_text(name="Obtain release build output", add_output_log=True), ) diff --git a/tools/build_release b/tools/build_release index 4c87745025..8b4c1d828e 100755 --- a/tools/build_release +++ b/tools/build_release @@ -135,6 +135,9 @@ def main(): help="Output in JSON instead of human readable format.", ) parser.add_argument("--strip", action="store_true", help="Strip output binaries") + parser.add_argument( + "--build-profile", help="Select compile profile, default to release.", default="release" + ) pgo_group = parser.add_mutually_exclusive_group() pgo_group.add_argument( "--profile-generate", @@ -167,7 +170,8 @@ def main(): features = build_target.feature_flag cargo_args = [ - "--release", + "--profile", + args.build_profile, "--features=" + features, f"--target={build_target}", "--workspace",