From cee579b8539884cd119eca92e7f0c7fc9f70c413 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Thu, 26 Feb 2026 08:57:48 -0800 Subject: [PATCH 1/2] Use `swig` from BCR, allowing to remove last dep on `WORKSPACE` Signed-off-by: Henner Zeller --- MODULE.bazel | 5 +++-- WORKSPACE | 33 --------------------------------- bazel/python_wrap_cc.bzl | 2 +- bazel/tcl_wrap_cc.bzl | 2 +- 4 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 WORKSPACE diff --git a/MODULE.bazel b/MODULE.bazel index 01e4d94ab0e..b7f0beaee22 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,14 +7,15 @@ module( bazel_dep(name = "abc", version = "0.62-yosyshq") bazel_dep(name = "abseil-cpp", version = "20260107.0") +bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "coin-or-lemon", version = "1.3.1") bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_bison", version = "0.3.1") bazel_dep(name = "rules_cc", version = "0.1.2") bazel_dep(name = "rules_flex", version = "0.3.1") -bazel_dep(name = "rules_bison", version = "0.3.1") bazel_dep(name = "rules_jvm_external", version = "6.4") bazel_dep(name = "rules_shell", version = "0.6.1") +bazel_dep(name = "swig", version = "4.3.0") bazel_dep(name = "rules_scala") git_override( module_name = "rules_scala", diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index b0732c83f95..00000000000 --- a/WORKSPACE +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2025-2025, The OpenROAD Authors - -# TODO: this file should eventually be empty. Right now it still pulls in a few -# dependencies via bazel_rules_hdl. - -workspace(name = "openroad") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -rules_hdl_git_hash = "8cc8977cc305ed94ec7852495ed576fcbde1c18d" - -rules_hdl_git_sha256 = "046193f4a0b006f43bd5f9615c218d2171d0169e231028a22d8d9c011c675ad6" - -http_archive( - name = "rules_hdl", - sha256 = rules_hdl_git_sha256, - strip_prefix = "bazel_rules_hdl-%s" % rules_hdl_git_hash, - urls = [ - "https://github.com/hdl/bazel_rules_hdl/archive/%s.tar.gz" % rules_hdl_git_hash, - ], -) - -# Direct dependencies needed in openroad, and others that these in turn need. -# This essentially reads as a TODO list of what needs to be upstreamed to BCR -load("@rules_hdl//dependency_support/org_pcre_ftp:org_pcre_ftp.bzl", "org_pcre_ftp") -load("@rules_hdl//dependency_support/org_swig:org_swig.bzl", "org_swig") - -# Swig exists in BCR, but in a newer version where we need to test how to make -# it to work with TCL. -org_swig() - -org_pcre_ftp() # there is a newer pcre2 in BCR diff --git a/bazel/python_wrap_cc.bzl b/bazel/python_wrap_cc.bzl index 9af088824c7..867b7f3410e 100644 --- a/bazel/python_wrap_cc.bzl +++ b/bazel/python_wrap_cc.bzl @@ -130,7 +130,7 @@ python_wrap_cc = rule( doc = "args to pass directly to the swig binary", ), "_swig": attr.label( - default = "@org_swig//:swig_stable", + default = "@swig", allow_files = True, cfg = "exec", ), diff --git a/bazel/tcl_wrap_cc.bzl b/bazel/tcl_wrap_cc.bzl index 6f3943a313e..654db9fb8b2 100644 --- a/bazel/tcl_wrap_cc.bzl +++ b/bazel/tcl_wrap_cc.bzl @@ -149,7 +149,7 @@ tcl_wrap_cc = rule( doc = "args to pass directly to the swig binary", ), "_swig": attr.label( - default = "@org_swig//:swig_stable", + default = "@swig", allow_files = True, cfg = "exec", ), From b02bdbf6e32901a4d24c5d3213531b785d479176 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Thu, 26 Feb 2026 08:57:48 -0800 Subject: [PATCH 2/2] Use `swig` from BCR, allowing to remove last dep on `WORKSPACE` Signed-off-by: Henner Zeller --- MODULE.bazel | 4 ++-- MODULE.bazel.lock | 6 ++++-- bazel/python_wrap_cc.bzl | 18 ++++++++++++++++-- bazel/tcl_wrap_cc.bzl | 34 ++++++++++++++++++++++++---------- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b7f0beaee22..2d80e4c9d72 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,8 +14,6 @@ bazel_dep(name = "rules_bison", version = "0.3.1") bazel_dep(name = "rules_cc", version = "0.1.2") bazel_dep(name = "rules_flex", version = "0.3.1") bazel_dep(name = "rules_jvm_external", version = "6.4") -bazel_dep(name = "rules_shell", version = "0.6.1") -bazel_dep(name = "swig", version = "4.3.0") bazel_dep(name = "rules_scala") git_override( module_name = "rules_scala", @@ -23,7 +21,9 @@ git_override( remote = "https://github.com/bazelbuild/rules_scala", ) +bazel_dep(name = "rules_shell", version = "0.6.1") bazel_dep(name = "rules_verilator", version = "0.1.0") +bazel_dep(name = "swig", version = "4.3.0.bcr.2") bazel_dep(name = "verilator", version = "5.036.bcr.3") BOOST_VERSION = "1.89.0.bcr.2" diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 11630af7e17..20ff80597b0 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -491,12 +491,13 @@ "https://bcr.bazel.build/modules/rules_cc/0.1.4/MODULE.bazel": "bb03a452a7527ac25a7518fb86a946ef63df860b9657d8323a0c50f8504fb0b9", "https://bcr.bazel.build/modules/rules_cc/0.1.5/MODULE.bazel": "88dfc9361e8b5ae1008ac38f7cdfd45ad738e4fa676a3ad67d19204f045a1fd8", "https://bcr.bazel.build/modules/rules_cc/0.2.0/MODULE.bazel": "b5c17f90458caae90d2ccd114c81970062946f49f355610ed89bebf954f5783c", + "https://bcr.bazel.build/modules/rules_cc/0.2.11/MODULE.bazel": "e94f24f065bf2191dba2dace951814378b66a94bb3bcc48077492fe0508059b5", + "https://bcr.bazel.build/modules/rules_cc/0.2.11/source.json": "4d555dc20c9c135b21b2e403cf0ce8393fb65711b2305979ce053df4ee3e78de", "https://bcr.bazel.build/modules/rules_cc/0.2.2/MODULE.bazel": "a0656c5a8ff7f76bb1319ebf301bab9d94da5b48894cac25a14ed115f9dd0884", "https://bcr.bazel.build/modules/rules_cc/0.2.3/MODULE.bazel": "07d7f5a97bcf2fc97bcefbee82abf4372cb07451949c81f575de94b51ec4852a", "https://bcr.bazel.build/modules/rules_cc/0.2.4/MODULE.bazel": "1ff1223dfd24f3ecf8f028446d4a27608aa43c3f41e346d22838a4223980b8cc", "https://bcr.bazel.build/modules/rules_cc/0.2.8/MODULE.bazel": "f1df20f0bf22c28192a794f29b501ee2018fa37a3862a1a2132ae2940a23a642", "https://bcr.bazel.build/modules/rules_cc/0.2.9/MODULE.bazel": "34263f1dca62ea664265438cef714d7db124c03e1ed55ebb4f1dc860164308d1", - "https://bcr.bazel.build/modules/rules_cc/0.2.9/source.json": "4e49b40effcbd14fbfb233eb929de42dfff7b66538b4ffda310ad501638e7986", "https://bcr.bazel.build/modules/rules_flex/0.3.1/MODULE.bazel": "5aea738f59e47769d219f972fc8426c53693c262895787efafa71fe9795bd7e3", "https://bcr.bazel.build/modules/rules_flex/0.4/MODULE.bazel": "543edf994d2c044f3d723374e50eaa739ed7ee9d82b8185adb8413bce269dcf3", "https://bcr.bazel.build/modules/rules_flex/0.4/source.json": "98bc56c2139b6ed6387dbabd06f625e82500bed8ba1689a5f4f3c9e8c3289f82", @@ -632,8 +633,9 @@ "https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216", "https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.1/MODULE.bazel": "5e463fbfba7b1701d957555ed45097d7f984211330106ccd1352c6e0af0dcf91", "https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.1/source.json": "32bd87e5f4d7acc57c5b2ff7c325ae3061d5e242c0c4c214ae87e0f1c13e54cb", + "https://bcr.bazel.build/modules/swig/4.3.0.bcr.2/MODULE.bazel": "fc4cc6b19261a479fd909b9de667e386fbcf89f9933e95d6c075d7464db3ab59", + "https://bcr.bazel.build/modules/swig/4.3.0.bcr.2/source.json": "00a177a1251f178736b74aacee0312578c8f7034c18f615284960a2f8840ae95", "https://bcr.bazel.build/modules/swig/4.3.0/MODULE.bazel": "51619e147172c5380869cc90460b1c7fecfe21d6f566e97bc7ecf61244bdc7b8", - "https://bcr.bazel.build/modules/swig/4.3.0/source.json": "ea8dac67896e3a623cd92c48573a351c4bab1537f5aeb210c1c1e049994dd599", "https://bcr.bazel.build/modules/systemc/3.0.2/MODULE.bazel": "7c4283e827307eb8eedfcba74f500f114e248916d948a2cdc45971818f3fde0d", "https://bcr.bazel.build/modules/systemc/3.0.2/source.json": "47370abd3ed04ce3c1a65a5b87c973e3e80e7e10e6b1dca2f15076f612d86d4c", "https://bcr.bazel.build/modules/tcl_lang/8.6.16.bcr.1/MODULE.bazel": "1fc27ececc903378b88ad5a0b92d2675b54fe3add9bcc27d612195bd823c2f2d", diff --git a/bazel/python_wrap_cc.bzl b/bazel/python_wrap_cc.bzl index 867b7f3410e..b259082da8f 100644 --- a/bazel/python_wrap_cc.bzl +++ b/bazel/python_wrap_cc.bzl @@ -50,6 +50,8 @@ def _python_wrap_cc_impl(ctx): if len(ctx.files.srcs) > 1 and not ctx.attr.root_swig_src: fail("If multiple src files are provided, root_swig_src must be specified.") + swig_lib_dir = ctx.file._swig_swg.dirname + root_file = ctx.file.root_swig_src or ctx.files.srcs[0] cc_outfile_name = ctx.attr.out or (ctx.attr.name + ".cc") @@ -85,8 +87,9 @@ def _python_wrap_cc_impl(ctx): outputs = [cc_output_file, py_output_file], inputs = src_inputs, arguments = [args], - tools = ctx.files._swig, - executable = ([file for file in ctx.files._swig if file.basename == "swig"][0]), + env = {"SWIG_LIB": swig_lib_dir}, + tools = ctx.files._swig_lib, + executable = ctx.executable._swig, ) return [ DefaultInfo(files = depset([cc_output_file, py_output_file])), @@ -133,6 +136,17 @@ python_wrap_cc = rule( default = "@swig", allow_files = True, cfg = "exec", + executable = True, + ), + "_swig_lib": attr.label( + default = "@swig//:lib_python", + allow_files = True, + ), + "_swig_swg": attr.label( + default = "@swig//:swig_swg", + allow_single_file = True, + doc = "SWIG swig.swg library file used for determining SWIG_LIB " + + "env variable (internal attribute).", ), }, ) diff --git a/bazel/tcl_wrap_cc.bzl b/bazel/tcl_wrap_cc.bzl index 654db9fb8b2..571c097f712 100644 --- a/bazel/tcl_wrap_cc.bzl +++ b/bazel/tcl_wrap_cc.bzl @@ -42,6 +42,7 @@ def _tcl_wrap_cc_impl(ctx): if len(ctx.files.srcs) > 1 and not ctx.attr.root_swig_src: fail("If multiple src files are provided, root_swig_src must be specified.") + swig_lib_dir = ctx.file._swig_swg.dirname root_file = ctx.file.root_swig_src or ctx.files.srcs[0] outfile_name = ctx.attr.out or (ctx.attr.name + ".cc") @@ -68,18 +69,19 @@ def _tcl_wrap_cc_impl(ctx): args.add("-namespace") args.add("-prefix") args.add(ctx.attr.namespace_prefix) - args.add_all(swig_options.to_list()) - args.add_all(includes_paths.to_list(), format_each = "-I%s") - args.add("-o") - args.add(output_file.path) - args.add(root_file.path) + args.add_all(swig_options.to_list()) + args.add_all(includes_paths.to_list(), format_each = "-I%s") + args.add("-o") + args.add(output_file.path) + args.add(root_file.path) ctx.actions.run( outputs = [output_file], inputs = src_inputs, arguments = [args], - tools = ctx.files._swig, - executable = ([file for file in ctx.files._swig if file.basename == "swig"][0]), + env = {"SWIG_LIB": swig_lib_dir}, + tools = ctx.files._swig_lib, + executable = ctx.executable._swig, ) output_files = [output_file] @@ -92,10 +94,11 @@ def _tcl_wrap_cc_impl(ctx): runtime_args.add(runtime_header) ctx.actions.run( outputs = [runtime_header], - inputs = [], + inputs = depset(ctx.files._swig_lib), arguments = [runtime_args], - tools = [ctx.attr._swig.files_to_run], - executable = ([file for file in ctx.files._swig if file.basename == "swig"][0]), + env = {"SWIG_LIB": swig_lib_dir}, + executable = ctx.executable._swig, + tools = ctx.files._swig_lib, toolchain = None, ) output_files.append(runtime_header) @@ -150,8 +153,19 @@ tcl_wrap_cc = rule( ), "_swig": attr.label( default = "@swig", + executable = True, allow_files = True, cfg = "exec", ), + "_swig_lib": attr.label( + default = "@swig//:lib_tcl", + allow_files = True, + ), + "_swig_swg": attr.label( + default = "@swig//:swig_swg", + allow_single_file = True, + doc = "SWIG swig.swg library file used for determining SWIG_LIB " + + "env variable (internal attribute).", + ), }, )