From 6ee24cc0a29d4e64455c8c8ec341b10bfe4a27f7 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Thu, 22 Jan 2026 15:38:32 +0900 Subject: [PATCH 1/3] build: Fix typo and enable LTO on-by-default for CMake Signed-off-by: Jaehyun Kim --- CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f573c41c36c..de6a3cb4721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,13 +21,6 @@ cmake_policy(SET CMP0077 NEW) # Let AUTOMOC and AUTOUIC process GENERATED files. cmake_policy(SET CMP0071 NEW) -# Interfers with Qt so off by default. -option(LINK_TIME_OPTIMIZATION "Flag to control link time optimization: off by default" OFF) - -if (LINK_TIME_OPTIMIZATION) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) -endif() - # Allow to use external shared boost libraries option(USE_SYSTEM_BOOST "Use system shared Boost libraries" OFF) From a4939948904d8eebae0be05e7695be70215f848f Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Fri, 23 Jan 2026 17:42:08 +0900 Subject: [PATCH 2/3] buid: Add notification message to set `--config=opt` to enable LTO. Note that the default build `bazel build //:openroad` does not use LTO. Signed-off-by: Jaehyun Kim --- .bazelrc | 6 +++--- BUILD.bazel | 18 ++++++++++++++++++ bazel/notification.bzl | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 bazel/notification.bzl diff --git a/.bazelrc b/.bazelrc index 7a9689bd462..0498d4300da 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,11 +16,11 @@ build --cxxopt "-std=c++20" --host_cxxopt "-std=c++20" build --cxxopt "-xc++" --host_cxxopt "-xc++" build --cxxopt "-DBAZEL_BUILD" --host_cxxopt "-DBAZEL_BUILD" -# Default to optimized build (-c opt), O3 +# Default to optimized build (-c opt) build -c opt -build:opt --copt=-O3 -# Enable Full-LTO (Link Time Optimization) +# Settings for --config=opt build: Enable -O3 and Full-LTO for performance +build:opt --copt=-O3 build:opt --copt=-flto build:opt --linkopt=-flto diff --git a/BUILD.bazel b/BUILD.bazel index 05a9b5639b8..8aa8304c8c7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -5,6 +5,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@openroad_rules_python//python:defs.bzl", "py_library") load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("//bazel:notification.bzl", "notification_rule") load("//bazel:python_wrap_cc.bzl", "PYTHON_STABLE_API_DEFINE", "python_wrap_cc") load("//bazel:tcl_encode_or.bzl", "tcl_encode") load("//bazel:tcl_wrap_cc.bzl", "tcl_wrap_cc") @@ -18,6 +19,22 @@ package( ], ) +# Notification target to notify user if --config=opt (with LTO) is not used. +notification_rule( + name = "opt_notification", + is_opt = select( + { + ":lto_on": True, + "//conditions:default": False, + }, + ), +) + +config_setting( + name = "lto_on", + values = {"copt": "-flto"}, +) + exports_files([ "LICENSE", "src/Design.i", @@ -153,6 +170,7 @@ cc_binary( deps = [ ":openroad_lib", ":openroad_version", + ":opt_notification", ":ord", "//bazel:runfiles", "//src/cut", diff --git a/bazel/notification.bzl b/bazel/notification.bzl new file mode 100644 index 00000000000..66cf9efec87 --- /dev/null +++ b/bazel/notification.bzl @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2025, Precision Innovations Inc. + +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") + +def _notification_impl(ctx): + if not ctx.attr.is_opt: + print("\n" + "=" * 80 + "\n" + + " NOTIFICATION: Use --config=opt to build with LTO (Link Time Optimization)\n" + + " and get better performance at the expense of longer build time.\n" + + "=" * 80 + "\n") + return [CcInfo()] + +notification_rule = rule( + implementation = _notification_impl, + attrs = { + # Set to True when the build configuration enables LTO (via --config=opt). + # When True, the notification message is suppressed. + "is_opt": attr.bool(default = False), + }, +) From 723ecfaffb75a87c4fa0e0cab408788db0adc242 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Fri, 23 Jan 2026 18:09:17 +0900 Subject: [PATCH 3/3] build: Resolve buildifier issue Signed-off-by: Jaehyun Kim --- bazel/notification.bzl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bazel/notification.bzl b/bazel/notification.bzl index 66cf9efec87..c0adcbb1c5b 100644 --- a/bazel/notification.bzl +++ b/bazel/notification.bzl @@ -1,10 +1,13 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2025, Precision Innovations Inc. +"""Rule to provide build-time notifications.""" + load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") def _notification_impl(ctx): if not ctx.attr.is_opt: + # buildifier: disable=print print("\n" + "=" * 80 + "\n" + " NOTIFICATION: Use --config=opt to build with LTO (Link Time Optimization)\n" + " and get better performance at the expense of longer build time.\n" +