@@ -46,68 +46,42 @@ async def handler(data, context):
4646 # Exclude testchipip's SimDRAM.cc — our SimDRAM_bb.cc overrides memory_init
4747 csrcs = [f for f in csrcs if not f .endswith ("SimDRAM.cc" ) or "src/csrc" in f ]
4848
49- # Patch fesvr includes out of build/mm.h and build/mm.cc.
50- # These files are auto-copied from testchipip by Verilator as SimDRAM.v
51- # companion sources. They reference fesvr/memif.h which we don't have
52- # (fesvr is removed). The memif_t dependency was only used by SimDRAM.cc's
53- # load_elf — our SimDRAM_bb.cc doesn't use it.
54- for patch_file in [f"{ build_dir } /mm.h" , f"{ build_dir } /mm.cc" ]:
55- if os .path .exists (patch_file ):
56- with open (patch_file , "r" ) as f :
57- content = f .read ()
58- patched = "\n " .join (
59- line for line in content .splitlines ()
60- if "fesvr/memif.h" not in line and "fesvr/elfloader.h" not in line
61- )
62- if patched != content :
63- with open (patch_file , "w" ) as f :
64- f .write (patched )
65- context .logger .info (f"Patched fesvr includes from { patch_file } " )
49+ # Exclude testchipip's TSI/HTIF C++ sources (deleted in verilog step, but guard anyway).
50+ # tsi_tick DPI symbol is provided by tsi_stub.cc in src/csrc instead.
51+ _tsi_htif = {"testchip_tsi.cc" , "testchip_htif.cc" , "SimTSI.cc" }
52+ csrcs = [f for f in csrcs if os .path .basename (f ) not in _tsi_htif ]
6653
6754 topname = "BBSimHarness"
6855
6956 # ==================================================================================
7057 # Build flags
7158 # ==================================================================================
72- dramsim2_dir = f"{ arch_dir } /thirdparty/chipyard/tools/DRAMSim2"
73-
74- # Find readline headers/libs in nix store (not in standard paths under nix)
75- rl_headers = glob .glob ("/nix/store/*readline*-dev/include/readline/readline.h" )
76- readline_inc = os .path .dirname (os .path .dirname (rl_headers [0 ])) if rl_headers else ""
77- rl_libs = glob .glob ("/nix/store/*readline*/lib/libreadline.so" )
78- readline_lib = os .path .dirname (rl_libs [0 ]) if rl_libs else ""
79-
80- # Find zlib headers/libs in nix store
81- zlib_headers = glob .glob ("/nix/store/*zlib*-dev/include/zlib.h" )
82- if not zlib_headers :
83- zlib_headers = glob .glob ("/nix/store/*zlib*/include/zlib.h" )
84- zlib_inc = os .path .dirname (zlib_headers [0 ]) if zlib_headers else ""
85- zlib_libs = glob .glob ("/nix/store/*zlib*/lib/libz.so" )
86- zlib_lib = os .path .dirname (zlib_libs [0 ]) if zlib_libs else ""
87-
88- inc_paths = [
89- dramsim2_dir ,
90- build_dir ,
91- f"{ arch_dir } /src/csrc/include" ,
92- ]
93- if readline_inc :
94- inc_paths .append (readline_inc )
95- if zlib_inc :
96- inc_paths .append (zlib_inc )
97- inc_flags = " " .join ([f"-I{ p } " for p in inc_paths if p ])
59+ result_dir = f"{ bbdir } /result"
60+
61+ def pkg_config (flag , pkg ):
62+ r = subprocess .run (["pkg-config" , flag , pkg ], capture_output = True , text = True )
63+ return r .stdout .strip () if r .returncode == 0 else ""
64+
65+ readline_inc = pkg_config ("--variable=includedir" , "readline" )
66+ readline_lib = pkg_config ("--variable=libdir" , "readline" )
67+ zlib_lib = pkg_config ("--variable=libdir" , "zlib" )
68+
69+ inc_flags = " " .join ([
70+ f"-I{ result_dir } /include" ,
71+ f"-I{ build_dir } " ,
72+ f"-I{ arch_dir } /src/csrc/include" ,
73+ f"-I{ readline_inc } " ,
74+ ])
9875
9976 # -DBBSIM: selects VBBSimHarness in bdb.h / main.cc
10077 cflags = f"{ inc_flags } -DBBSIM -DTOP_NAME='\" V{ topname } \" ' -std=c++17"
10178
10279 ldflags = (
10380 f"-lreadline -ldramsim -lstdc++ -lz "
104- f"-L{ bbdir } /result/lib "
105- f"-L{ dramsim2_dir } "
81+ f"-L{ result_dir } /lib "
82+ f"-L{ readline_lib } -Wl,-rpath,{ readline_lib } "
83+ f"-L{ zlib_lib } -Wl,-rpath,{ zlib_lib } "
10684 )
107- if readline_lib :
108- ldflags += f"-L{ readline_lib } -Wl,-rpath,{ readline_lib } "
109- if zlib_lib :
110- ldflags += f"-L{ zlib_lib } -Wl,-rpath,{ zlib_lib } "
11185
11286 obj_dir = f"{ build_dir } /obj_dir"
11387 subprocess .run (f"rm -rf { obj_dir } " , shell = True )
0 commit comments