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/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) diff --git a/bazel/notification.bzl b/bazel/notification.bzl new file mode 100644 index 00000000000..c0adcbb1c5b --- /dev/null +++ b/bazel/notification.bzl @@ -0,0 +1,24 @@ +# 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" + + "=" * 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), + }, +)