| // SPDX-License-Identifier: BSD-3-Clause | |
| // Copyright (c) 2026, The OpenROAD Authors | |
| namespace in_bazel { | |
| static std::optional<std::string> TclLibraryMountPoint(Tcl_Interp* interp) | |
| { | |
| // In tcl9, we can mount an encoded zipfile as //zipfs:/ and read | |
| // libraries from there. | |
| if (TclZipfs_MountBuffer( | |
| interp, kTclResourceZip, sizeof(kTclResourceZip), "/app", 0) | |
| != TCL_OK) { | |
| std::cerr << "[Warning] Failed to mount Tcl zipfs.\n"; | |
| return std::nullopt; | |
| } | |
| return Tcl_GetStringResult(interp); | |
| } | |
| int SetupTclEnvironment(Tcl_Interp* interp) | |
| { | |
| const auto mount_point = TclLibraryMountPoint(interp); | |
| if (!mount_point) { | |
| return TCL_ERROR; | |
| } | |
| // Main tcl library, init.tcl and friends. | |
| const std::string tcl_lib = *mount_point + "/library"; | |
| if (!Tcl_SetVar(interp, "::tcl_library", tcl_lib.c_str(), TCL_GLOBAL_ONLY)) { | |
| std::cerr << "[Warning] could not set ::tcl_library\n"; | |
| return TCL_ERROR; | |
| } | |
| return TCL_OK; | |
| } | |
| } // namespace in_bazel | |