@@ -212,3 +212,60 @@ def compile_vhpidirect_nvc_application(run_script_root, vu):
212212 print (proc .stdout )
213213 print (proc .stderr )
214214 raise RuntimeError ("Failed to link NVC VHPIDIRECT application" )
215+
216+ def compile_vhpidirect_ghdl_application (run_script_root , vu ):
217+ """
218+ Compile VHPIDIRECT application for GHDL.
219+ """
220+ #path_to_shared_lib = (run_script_root / "vunit_out" / vu.get_simulator_name() / "libraries").resolve()
221+ path_to_shared_lib = (run_script_root ).resolve ()
222+ if not path_to_shared_lib .exists ():
223+ path_to_shared_lib .mkdir (parents = True , exist_ok = True )
224+ shared_lib = path_to_shared_lib / "python.so"
225+ path_to_python_include = (
226+ Path (sys .executable ).parent .parent .resolve () / "include" / f"python{ sys .version_info [0 ]} .{ sys .version_info [1 ]} "
227+ )
228+ path_to_python_libs = Path (sys .executable ).parent .parent .resolve () / "bin"
229+ python_shared_lib = f"libpython{ sys .version_info [0 ]} .{ sys .version_info [1 ]} "
230+ path_to_python_pkg = Path (__file__ ).parent .resolve () / "vhdl" / "python" / "src"
231+
232+ c_file_names = ["python_pkg_vhpidirect_ghdl.c" , "python_pkg.c" ]
233+
234+ for c_file_name in c_file_names :
235+ args = [
236+ "gcc" ,
237+ "-c" ,
238+ "-I" ,
239+ str (path_to_python_include ),
240+ str (path_to_python_pkg / c_file_name ),
241+ "-o" ,
242+ str (path_to_shared_lib / (c_file_name [:- 1 ] + "o" ))
243+
244+ ]
245+
246+ proc = subprocess .run (args , capture_output = True , text = True , check = False , cwd = str (path_to_shared_lib / ".." ))
247+ if proc .returncode != 0 :
248+ print (proc .stdout )
249+ print (proc .stderr )
250+ raise RuntimeError ("Failed to compile GHDL VHPIDIRECT application" )
251+
252+ args = [
253+ "gcc" ,
254+ "-shared" ,
255+ "-fPIC" ,
256+ "-o" ,
257+ str (shared_lib ),
258+ str (path_to_shared_lib / "python_pkg.o" ),
259+ str (path_to_shared_lib / "python_pkg_vhpidirect_ghdl.o" ),
260+ "-l" ,
261+ python_shared_lib ,
262+ "-L" ,
263+ str (path_to_python_libs ),
264+ ]
265+
266+ proc = subprocess .run (args , capture_output = True , text = True , check = False , cwd = str (path_to_shared_lib / ".." ))
267+ if proc .returncode != 0 :
268+ print (proc .stdout )
269+ print (proc .stderr )
270+ raise RuntimeError ("Failed to link GHDL VHPIDIRECT application" )
271+
0 commit comments