diff --git a/bazel/BUILD b/bazel/BUILD index 4614697cbb..faec6706dd 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,3 +1,4 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@openroad_rules_python//python:pip.bzl", "compile_pip_requirements") load("@rules_cc//cc:cc_library.bzl", "cc_library") @@ -29,3 +30,11 @@ cc_library( ], alwayslink = True, ) + +# small build test to check if "bazel build //src/sta:StaTclInitVar" works +# Run with "bazel test //bazel:sta_tcl_encode_test" +# Tests the tcl_encode_sta.bzl rule +build_test( + name = "sta_tcl_encode_test", + targets = ["//src/sta:StaTclInitVar"], +) diff --git a/bazel/tcl_encode_sta.bzl b/bazel/tcl_encode_sta.bzl index fd5f724ee6..c631a28830 100644 --- a/bazel/tcl_encode_sta.bzl +++ b/bazel/tcl_encode_sta.bzl @@ -18,12 +18,23 @@ def _tcl_encode_sta_impl(ctx): args.add(ctx.attr.char_array_name) args.add_all(ctx.files.srcs) + # Get the Tcl library files (init.tcl...) from tcl_core + tcl_libfiles = ctx.attr._tcl_library_files[DefaultInfo] + + # All tcl_core files live under library/, so split any file's path on + # "/library/" to obtain the library directory for TCL_LIBRARY. + tcl_lib_dir = ctx.files._tcl_library_files[0].path.split("/library/", 1)[0] + "/library" + ctx.actions.run( outputs = [output_file], - inputs = ctx.files.srcs, + inputs = depset( + direct = ctx.files.srcs + [ctx.file._encode_script], + transitive = [tcl_libfiles.files], + ), arguments = [args], - tools = [ctx.executable._tclsh, ctx.file._encode_script], + tools = [ctx.executable._tclsh], executable = ctx.executable._tclsh, + env = {"TCL_LIBRARY": tcl_lib_dir}, ) return [DefaultInfo(files = depset([output_file]))] @@ -46,6 +57,10 @@ tcl_encode_sta = rule( default = "//src/sta:etc/TclEncode.tcl", allow_single_file = True, ), + "_tcl_library_files": attr.label( + default = "@tcl_lang//:tcl_core", + allow_files = True, + ), "_tclsh": attr.label( default = "@tcl_lang//:tclsh", executable = True,