From 07793a641d91adcfb1e840071220153515fb8e9e Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Tue, 17 Dec 2024 20:19:43 -0500 Subject: [PATCH 1/2] start, add 'manual' option for rust/settings/lto --- rust/private/lto.bzl | 8 +++++++- test/unit/lto/lto_test_suite.bzl | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rust/private/lto.bzl b/rust/private/lto.bzl index 3f5c16264a..6cb04b8846 100644 --- a/rust/private/lto.bzl +++ b/rust/private/lto.bzl @@ -3,6 +3,8 @@ load("//rust/private:utils.bzl", "is_exec_configuration") _LTO_MODES = [ + # Do nothing, let the user manually handle LTO. + "manual", # Default. No mode has been explicitly set, rustc will do "thin local" LTO # between the codegen units of a single crate. "unspecified", @@ -94,8 +96,12 @@ def construct_lto_arguments(ctx, toolchain, crate_info): list: A list of strings that are valid flags for 'rustc'. """ mode = toolchain._lto.mode - format = _determine_lto_object_format(ctx, toolchain, crate_info) + # The user is handling LTO on their own, don't add any arguments. + if mode == "manual": + return [] + + format = _determine_lto_object_format(ctx, toolchain, crate_info) args = [] if mode in ["thin", "fat", "off"] and not is_exec_configuration(ctx): diff --git a/test/unit/lto/lto_test_suite.bzl b/test/unit/lto/lto_test_suite.bzl index d70d3bce24..46c0b3172f 100644 --- a/test/unit/lto/lto_test_suite.bzl +++ b/test/unit/lto/lto_test_suite.bzl @@ -46,6 +46,14 @@ _lto_level_default_test = analysistest.make( config_settings = {}, ) +def _lto_level_manual(ctx): + return _lto_test_impl(ctx, None, None, False) + +_lto_level_manual_test = analysistest.make( + _lto_level_manual, + config_settings = {str(Label("//rust/settings:lto")): "manual"}, +) + def _lto_level_off(ctx): return _lto_test_impl(ctx, "off", "no", False) @@ -97,6 +105,11 @@ def lto_test_suite(name): target_under_test = ":lib", ) + _lto_level_manual_test( + name = "lto_level_manual_test", + target_under_test = ":lib", + ) + _lto_level_off_test( name = "lto_level_off_test", target_under_test = ":lib", @@ -116,6 +129,7 @@ def lto_test_suite(name): name = name, tests = [ ":lto_level_default_test", + ":lto_level_manual_test", ":lto_level_off_test", ":lto_level_thin_test", ":lto_level_fat_test", From 7e293d9596d29e3cf83b7137c512ec48137f54ad Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Wed, 18 Dec 2024 12:55:20 -0500 Subject: [PATCH 2/2] cleanup implementation * remove commented out line * remove 'format' references that are no longer possible --- rust/private/lto.bzl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rust/private/lto.bzl b/rust/private/lto.bzl index 6cb04b8846..04c271750d 100644 --- a/rust/private/lto.bzl +++ b/rust/private/lto.bzl @@ -66,8 +66,6 @@ def _determine_lto_object_format(ctx, toolchain, crate_info): return "only_object" perform_linking = crate_info.type in ["bin", "staticlib", "cdylib"] - - # is_linkable = crate_info.type in ["lib", "rlib", "dylib", "proc-macro"] is_dynamic = crate_info.type in ["dylib", "cdylib", "proc-macro"] needs_object = perform_linking or is_dynamic @@ -107,10 +105,10 @@ def construct_lto_arguments(ctx, toolchain, crate_info): if mode in ["thin", "fat", "off"] and not is_exec_configuration(ctx): args.append("lto={}".format(mode)) - if format in ["unspecified", "object_and_bitcode"]: + if format == "object_and_bitcode": # Embedding LLVM bitcode in object files is `rustc's` default. args.extend([]) - elif format in ["off", "only_object"]: + elif format == "only_object": args.extend(["embed-bitcode=no"]) elif format == "only_bitcode": args.extend(["linker-plugin-lto"])