11# SPDX-License-Identifier: BSD-3-Clause
22# Copyright (c) 2025-2025, The OpenROAD Authors
33
4+ load ("@bazel_skylib//rules:build_test.bzl" , "build_test" )
45load ("@bazel_skylib//rules:common_settings.bzl" , "string_flag" )
56load ("@rules_cc//cc:cc_binary.bzl" , "cc_binary" )
67load ("@rules_cc//cc:cc_library.bzl" , "cc_library" )
@@ -98,6 +99,7 @@ OPENROAD_LIBRARY_DEPS = [
9899 "//src/exa:ui" ,
99100 "//src/fin" ,
100101 "//src/gpl" ,
102+ "//src/gpl:ui" ,
101103 "//src/grt" ,
102104 "//src/grt:ui" ,
103105 "//src/ifp" ,
@@ -138,12 +140,7 @@ OPENROAD_LIBRARY_DEPS = [
138140 "//src/web:ui" ,
139141 "@abc" ,
140142 ":ord" ,
141- ] + select (
142- {
143- ":platform_cli" : ["//src/gui" ],
144- ":platform_gui" : ["//src/gui:gui_qt" ],
145- },
146- )
143+ ]
147144
148145# Flags applied to top-level OpenROAD targets only. Flags that apply
149146# globally to every cc_* target (-Wall, -Wextra, -Wno-sign-compare,
@@ -190,46 +187,113 @@ cc_library(
190187 ],
191188)
192189
190+ # Deps shared by :openroad and :openroad-qt. Kept as a Starlark list
191+ # rather than a cc_library wrapper because layering_check is enabled
192+ # package-wide: a deps-only cc_library does not re-export its deps'
193+ # headers to consumers, so direct binary deps are what each Main.cc
194+ # include needs to see.
195+ OPENROAD_MAIN_DEPS = [
196+ ":openroad_version" ,
197+ ":opt_notification" ,
198+ ":ord" ,
199+ ":tcl_readline_setup" ,
200+ "//bazel:tcl_library_init" ,
201+ "//src/cut" ,
202+ "//src/sta:opensta_lib" ,
203+ "//src/utl" ,
204+ "//src/web" ,
205+ "@abseil-cpp//absl/base:no_destructor" ,
206+ "@boost.stacktrace" ,
207+ "@rules_cc//cc/runfiles" , # sets BAZEL_CURRENT_REPOSITORY
208+ "@tcl_lang//:tcl" ,
209+ ]
210+
193211cc_binary (
194212 name = "openroad" ,
195213 srcs = [
196214 "src/Main.cc" ,
197215 ],
198216 copts = OPENROAD_COPTS ,
217+ defines = OPENROAD_DEFINES ,
199218 features = ["-use_header_modules" ],
200219 malloc = select ({
201220 "@platforms//os:linux" : "@tcmalloc//tcmalloc" ,
202221 "@platforms//os:macos" : "@bazel_tools//tools/cpp:malloc" ,
203222 }),
204223 visibility = ["//visibility:public" ],
224+ deps = OPENROAD_MAIN_DEPS + select (
225+ {
226+ ":platform_cli" : [
227+ ":openroad_lib" ,
228+ "//src/gui" ,
229+ "//src/gui:gui_stub" ,
230+ ],
231+ ":platform_gui" : [
232+ ":openroad_lib_qt" ,
233+ "//src/gui:gui_qt" ,
234+ ],
235+ },
236+ ),
237+ )
238+
239+ # Qt GUI variant. Build explicitly when the interactive GUI is wanted:
240+ # bazelisk build //:openroad-qt
241+ # Additive to the existing `--//:platform=gui //:openroad` flag path —
242+ # this target is preferable for ad-hoc GUI builds because it does not
243+ # invalidate `:openroad`'s cache the way flipping the flag does.
244+ cc_binary (
245+ name = "openroad-qt" ,
246+ srcs = [
247+ "src/Main.cc" ,
248+ ],
249+ copts = OPENROAD_COPTS ,
250+ defines = OPENROAD_DEFINES ,
251+ features = ["-use_header_modules" ],
252+ malloc = select ({
253+ "@platforms//os:linux" : "@tcmalloc//tcmalloc" ,
254+ "@platforms//os:macos" : "@bazel_tools//tools/cpp:malloc" ,
255+ }),
256+ visibility = ["//visibility:public" ],
257+ deps = OPENROAD_MAIN_DEPS + [
258+ ":openroad_lib_qt" ,
259+ "//src/gui:gui_qt" ,
260+ ],
261+ )
262+
263+ # CLI variant: the default. What downstream rule libraries pull as a
264+ # build-time tool, and what `bazelisk build //:openroad` produces.
265+ cc_library (
266+ name = "openroad_lib" ,
267+ srcs = [
268+ "src/Design.cc" ,
269+ "src/OpenRoad.cc" ,
270+ "src/Tech.cc" ,
271+ "src/Timing.cc" ,
272+ ":openroad_swig" ,
273+ ":openroad_tcl" ,
274+ ],
275+ copts = OPENROAD_COPTS ,
276+ defines = OPENROAD_DEFINES + ["BUILD_GUI=false" ],
277+ features = ["-use_header_modules" ],
278+ includes = [
279+ "include" ,
280+ ],
281+ visibility = ["//:__subpackages__" ],
205282 deps = [
206- ":openroad_lib" ,
207- ":openroad_version" ,
208- ":opt_notification" ,
209- ":ord" ,
210- ":tcl_readline_setup" ,
211- "//bazel:tcl_library_init" ,
212- "//src/cut" ,
213283 "//src/gui" ,
214284 "//src/sta:opensta_lib" ,
215- "//src/utl" ,
216- "//src/web" ,
217- "@abseil-cpp//absl/base:no_destructor" ,
285+ "@abseil-cpp//absl/base:core_headers" ,
286+ "@abseil-cpp//absl/synchronization" ,
218287 "@boost.stacktrace" ,
219- "@rules_cc//cc/runfiles" , # sets BAZEL_CURRENT_REPOSITORY
220288 "@tcl_lang//:tcl" ,
221- ],
222- )
223-
224- GUI_BUILD_FLAGS = select (
225- {
226- ":platform_cli" : ["BUILD_GUI=false" ],
227- ":platform_gui" : ["BUILD_GUI=true" ],
228- },
289+ ] + OPENROAD_LIBRARY_DEPS ,
229290)
230291
292+ # Qt variant: same sources, linked against the Qt GUI implementation.
293+ # Used by :openroad-qt, and by :openroad when --//:platform=gui is set.
294+ # Compiled separately (different `BUILD_GUI` define + different gui dep).
231295cc_library (
232- name = "openroad_lib " ,
296+ name = "openroad_lib_qt " ,
233297 srcs = [
234298 "src/Design.cc" ,
235299 "src/OpenRoad.cc" ,
@@ -239,13 +303,14 @@ cc_library(
239303 ":openroad_tcl" ,
240304 ],
241305 copts = OPENROAD_COPTS ,
242- defines = OPENROAD_DEFINES + GUI_BUILD_FLAGS ,
306+ defines = OPENROAD_DEFINES + [ "BUILD_GUI=true" ] ,
243307 features = ["-use_header_modules" ],
244308 includes = [
245309 "include" ,
246310 ],
247311 visibility = ["//:__subpackages__" ],
248312 deps = [
313+ "//src/gui:gui_qt" ,
249314 "//src/sta:opensta_lib" ,
250315 "@abseil-cpp//absl/base:core_headers" ,
251316 "@abseil-cpp//absl/synchronization" ,
@@ -347,6 +412,7 @@ cc_binary(
347412 "//src/gpl" ,
348413 "//src/grt" ,
349414 "//src/gui" ,
415+ "//src/gui:gui_stub" ,
350416 "//src/ifp" ,
351417 "//src/odb/src/db" ,
352418 "//src/par" ,
@@ -478,6 +544,14 @@ sh_test(
478544 tags = ["local" ],
479545)
480546
547+ # Make sure the Qt GUI variant keeps building. :openroad is exercised by
548+ # downstream rule libraries that pull it as a tool; :openroad-qt has no
549+ # such consumer in CI, so a build_test pins its compilability.
550+ build_test (
551+ name = "openroad_qt_build_test" ,
552+ targets = [":openroad-qt" ],
553+ )
554+
481555# ---------------------------------------------------------------------------
482556# Lint & tidy targets
483557#
0 commit comments