Debian Codegraph @

cocotb_build_libs.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # Copyright cocotb contributors
2 # Licensed under the Revised BSD License, see LICENSE for details.
3 # SPDX-License-Identifier: BSD-3-Clause
4
5 import logging
6 import os
7 import subprocess
8 import sys
9 import sysconfig
10 import textwrap
11 from distutils.ccompiler import get_default_compiler
12 from distutils.file_util import copy_file
13 from typing import List
14
15 from setuptools import Extension
16 from setuptools.command.build_ext import build_ext as _build_ext
17
18 logger = logging.getLogger(__name__)
19 cocotb_share_dir = os.path.abspath(
20 os.path.join(os.path.dirname(__file__), "src", "cocotb", "share")
21 )
22 _base_warns = [
23 "-Wall",
24 "-Wextra",
25 "-Wcast-qual",
26 "-Wwrite-strings",
27 "-Wconversion",
28 # -Wno-missing-field-initializers is required on GCC 4.x to prevent a
29 # spurious warning `error: missing initializer for member ...` when
30 # compiling `PyTypeObject type = {};` in `simulatormodule.cpp`.
31 # (See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750.) This flag can be
32 # removed once we require later GCC versions.
33 "-Wno-missing-field-initializers",
34 "-Werror=shadow",
35 ]
36 _ccx_warns = [*_base_warns, "-Wnon-virtual-dtor", "-Woverloaded-virtual"]
37 _extra_cxx_compile_args = [
38 "-std=c++11",
39 "-fvisibility=hidden",
40 "-fvisibility-inlines-hidden",
41 *_ccx_warns,
42 ]
43 if os.name != "nt":
44 _extra_cxx_compile_args += ["-flto"]
45
46 _extra_cxx_compile_args_msvc = ["/permissive-"]
47
48 # Make PRI* format macros available with C++11 compiler but older libc, e.g. on RHEL6.
49 _extra_defines = [("__STDC_FORMAT_MACROS", "")]
50
51
52 def create_sxs_assembly_manifest(
53 name: str, filename: str, libraries: List[str], dependency_only=False
54 ) -> str:
55 """
56 Create side-by-side (sxs) assembly manifest
57
58 It contains dependencies to other assemblies (in our case the assemblies are equal to the other libraries).
59 For more details see:
60 - https://docs.microsoft.com/en-us/windows/win32/sbscs/assembly-manifests
61 - https://docs.microsoft.com/en-us/windows/win32/sbscs/using-side-by-side-assemblies
62
63 Args:
64 name: The name of the assembly for which the manifest is generated, e.g. ``libcocotbutils``.
65 filename: The filename of the library, e.g. ``libcocotbutils.dll``.
66 libraries: A list of names of dependent manifests, e.g. ``["libgpilog"]``.
67 """
68
69 architecture = "amd64" if sys.maxsize > 2**32 else "x86"
70 dependencies = []
71
72 for lib in libraries:
73 dependencies.append(
74 textwrap.dedent(
75 """\
76 <dependency>
77 <dependentAssembly>
78 <assemblyIdentity name="%s" version="1.0.0.0" type="win32" processorArchitecture="%s" />
79 </dependentAssembly>
80 </dependency>
81 """
82 )
83 % (lib, architecture)
84 )
85
86 if not dependency_only:
87 manifest_body = textwrap.dedent(
88 """\
89 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
90 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
91 <assemblyIdentity name="%s" version="1.0.0.0" type="win32" processorArchitecture="%s" />
92 <file name="%s" />
93 %s
94 </assembly>
95 """
96 ) % (
97 name,
98 architecture,
99 filename,
100 textwrap.indent("".join(dependencies), " ").strip(),
101 )
102 else:
103 manifest_body = textwrap.dedent(
104 """\
105 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
106 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
107 %s
108 </assembly>
109 """
110 ) % (textwrap.indent("".join(dependencies), " ").strip())
111
112 return manifest_body
113
114
115 def create_sxs_appconfig(filename):
116 """
117 Create side-by-side (sxs) application configuration file.
118
119 The application configuration specifies additional search paths for manifests.
120 For more details see: https://docs.microsoft.com/en-us/windows/win32/sbscs/application-configuration-files
121 """
122
123 config_body = textwrap.dedent(
124 """\
125 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
126 <configuration>
127 <windows>
128 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
129 <probing privatePath="libs" />
130 </assemblyBinding>
131 </windows>
132 </configuration>
133 """
134 )
135
136 dirpath = os.path.dirname(filename)
137 os.makedirs(dirpath, exist_ok=True)
138
139 with open(filename + ".2.config", "w", encoding="utf-8") as f:
140 f.write(config_body)
141
142
143 def create_rc_file(rc_filename, name, filename, libraries, runtime_libraries):
144 """
145 Creates windows resource definition script to embed the side-by-side assembly manifest into the libraries.
146
147 For more details see: https://docs.microsoft.com/en-us/windows/win32/menurc/about-resource-files
148 """
149
150 manifest = create_sxs_assembly_manifest(name, filename, libraries)
151
152 # Escape double quotes and put every line between double quotes for embedding into rc file
153 manifest = manifest.replace('"', '""')
154 manifest = "\n".join([f'"{x}\\r\\n"' for x in manifest.splitlines()])
155
156 rc_body = (
157 textwrap.dedent(
158 """\
159 #pragma code_page(65001) // UTF-8
160 #include <Windows.h>
161
162 LANGUAGE 0x00, 0x00
163
164 ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST
165 BEGIN
166 %s
167 END
168 """
169 )
170 % manifest
171 )
172
173 if runtime_libraries is not None:
174 manifest = create_sxs_assembly_manifest(
175 name, filename, runtime_libraries, dependency_only=True
176 )
177
178 # Escape double quotes and put every line between double quotes for embedding into rc file
179 manifest = manifest.replace('"', '""')
180 manifest = "\n".join([f'"{x}\\r\\n"' for x in manifest.splitlines()])
181
182 rc_body += (
183 textwrap.dedent(
184 """\
185 1000 RT_MANIFEST
186 BEGIN
187 %s
188 END
189 """
190 )
191 % manifest
192 )
193
194 with open(rc_filename, "w", encoding="utf-8") as f:
195 f.write(rc_body)
196
197
198 def _get_lib_ext_name():
199 """Get name of default library file extension on given OS."""
200
201 if os.name == "nt":
202 ext_name = "dll"
203 else:
204 ext_name = "so"
205
206 return ext_name
207
208
209 class build_ext(_build_ext):
210 def _uses_msvc(self):
211 if self.compiler == "msvc":
212 return True
213 if self.compiler is None:
214 return get_default_compiler() == "msvc"
215 else:
216 return getattr(self.compiler, "compiler_type", None) == "msvc"
217
218 def run(self):
219 if os.name == "nt":
220 create_sxs_appconfig(
221 self.get_ext_fullpath(os.path.join("cocotb", "simulator"))
222 )
223
224 super().run()
225
226 def build_extensions(self):
227 if os.name == "nt":
228 if self._uses_msvc():
229 # Initialize the compiler now so that compiler/linker flags are populated
230 if not self.compiler.initialized:
231 self.compiler.initialize()
232
233 # Setuptools defaults to activate automatic manifest generation for msvc,
234 # disable it here as we manually generate it to also support mingw on windows
235 for k, ldflags in self.compiler._ldflags.items():
236 self.compiler._ldflags[k] = [
237 x for x in ldflags if not x.startswith("/MANIFEST")
238 ] + ["/MANIFEST:NO"]
239
240 self.compiler.compile_options = [
241 x for x in self.compiler.compile_options if not x.startswith("/W")
242 ] + ["/W4"]
243
244 ext_names = {os.path.split(ext.name)[-1] for ext in self.extensions}
245 for ext in self.extensions:
246 fullname = self.get_ext_fullname(ext.name)
247 filename = self.get_ext_filename(fullname)
248 name = os.path.split(fullname)[-1]
249 filename = os.path.split(filename)[-1]
250 libraries = {"lib" + lib for lib in ext.libraries}.intersection(
251 ext_names
252 )
253 rc_filename = name + ".rc"
254 runtime_libraries = None
255
256 # Add the runtime dependency on libcocotb to libembed
257 if name == "libembed":
258 runtime_libraries = ["libcocotb"]
259
260 # Strip lib prefix for msvc
261 if self._uses_msvc():
262 name = name[3:] if name.startswith("lib") else name
263 libraries = {
264 (lib[3:] if lib.startswith("lib") else lib) for lib in libraries
265 }
266 if runtime_libraries is not None:
267 runtime_libraries = {
268 (lib[3:] if lib.startswith("lib") else lib)
269 for lib in runtime_libraries
270 }
271 create_rc_file(
272 rc_filename, name, filename, libraries, runtime_libraries
273 )
274
275 def_dir = os.path.join(cocotb_share_dir, "def")
276 self._gen_import_libs(def_dir)
277
278 for e in self.extensions:
279 e.library_dirs += [def_dir]
280
281 super().build_extensions()
282
283 def build_extension(self, ext):
284 """Build each extension in its own temp directory to make gcov happy.
285
286 A normal PEP 517 install still works as the temp directories are discarded anyway.
287 """
288 lib_name = os.path.split(ext.name)[-1]
289
290 if self._uses_msvc():
291 ext.extra_compile_args += _extra_cxx_compile_args_msvc
292 else:
293 ext.extra_compile_args += _extra_cxx_compile_args
294
295 if os.name == "nt":
296 # Align behavior of gcc with msvc and export only symbols marked with __declspec(dllexport)
297 ext.extra_link_args += ["-Wl,--exclude-all-symbols"]
298 else:
299 ext.extra_link_args += ["-flto"]
300
301 rpaths = []
302 if lib_name == "simulator":
303 rpaths += ["$ORIGIN/libs"]
304 install_name = None
305 else:
306 rpaths += ["$ORIGIN"]
307 install_name = lib_name
308
309 if sys.platform == "darwin":
310 rpaths = [
311 rpath.replace("$ORIGIN", "@loader_path") for rpath in rpaths
312 ]
313 if install_name is not None:
314 ext.extra_link_args += [
315 f"-Wl,-install_name,@rpath/{install_name}.so"
316 ]
317
318 if sys.platform == "linux":
319 # Avoid a runtime dependency on libstdc++. Some simulators
320 # ship a version of libstdc++6.so which is older than the
321 # one cocotb has been compiled with, which will then lead to
322 # load-time errors like "libstdc++.so.6: version
323 # `GLIBCXX_3.4.29' not found (required by
324 # /path/to/libcocotbvhpi_modelsim.so)."
325 ext.extra_link_args += ["-static-libstdc++"]
326
327 ext.extra_link_args += [f"-Wl,-rpath,{rpath}" for rpath in rpaths]
328
329 # vpi_user.h and vhpi_user.h require that WIN32 is defined
330 if os.name == "nt":
331 ext.define_macros += [("WIN32", "")]
332
333 if lib_name == "libembed":
334 if self._uses_msvc():
335 embed_lib_name = "cocotb"
336 else:
337 embed_lib_name = "libcocotb"
338 ext.define_macros += [
339 ("EMBED_IMPL_LIB", embed_lib_name + "." + _get_lib_ext_name())
340 ]
341
342 old_build_temp = self.build_temp
343 self.build_temp = os.path.join(self.build_temp, ext.name)
344 super().build_extension(ext)
345 self.build_temp = old_build_temp
346
347 # Needed for Windows to not assume python module (generate interface in def file)
348 def get_export_symbols(self, ext):
349 return None
350
351 # For proper cocotb library naming, based on https://github.com/cython/cython/issues/1740
352 def get_ext_filename(self, ext_name):
353 """
354 Like the base class method, but for libraries that are not python extension:
355 - removes the ``.cpython-36m-x86_64-linux-gnu.`` or ``-cpython-36m.`` part before the extension
356 - replaces ``.pyd`` with ``.dll`` on windows.
357 """
358
359 filename = _build_ext.get_ext_filename(self, ext_name)
360
361 # for the simulator python extension library, leaving suffix in place
362 if os.path.split(ext_name)[-1] == "simulator":
363 return filename
364
365 head, tail = os.path.split(filename)
366 tail_split = tail.split(".")
367
368 # mingw on msys2 uses `-` as separator
369 tail_split = tail_split[0].split("-")
370
371 # strip lib prefix if msvc is used
372 if self._uses_msvc() and tail_split[0].startswith("lib"):
373 tail_split[0] = tail_split[0][3:]
374
375 filename_short = os.path.join(head, tail_split[0] + "." + _get_lib_ext_name())
376
377 # icarus requires vpl extension
378 filename_short = filename_short.replace(
379 "libcocotbvpi_icarus.so", "libcocotbvpi_icarus.vpl"
380 )
381 filename_short = filename_short.replace(
382 "libcocotbvpi_icarus.dll", "libcocotbvpi_icarus.vpl"
383 )
384 filename_short = filename_short.replace(
385 "cocotbvpi_icarus.dll", "cocotbvpi_icarus.vpl"
386 )
387
388 return filename_short
389
390 def finalize_options(self):
391 """Like the base class method,but add extra library_dirs path."""
392
393 super().finalize_options()
394
395 for ext in self.extensions:
396 ext.library_dirs.append(os.path.join(self.build_lib, "cocotb", "libs"))
397
398 def copy_extensions_to_source(self):
399 """Like the base class method, but copy libs into proper directory in develop."""
400
401 build_py = self.get_finalized_command("build_py")
402 for ext in self.extensions:
403 fullname = self.get_ext_fullname(ext.name)
404 filename = self.get_ext_filename(fullname)
405 modpath = fullname.split(".")
406 package = ".".join(modpath[:-1])
407 package_dir = build_py.get_package_dir(package)
408 # unlike the method from `setuptools`, we do not call `os.path.basename` here
409 dest_filename = os.path.join(package_dir, filename)
410 src_filename = os.path.join(self.build_lib, filename)
411
412 os.makedirs(os.path.dirname(dest_filename), exist_ok=True)
413
414 copy_file(
415 src_filename, dest_filename, verbose=self.verbose, dry_run=self.dry_run
416 )
417 if ext._needs_stub:
418 self.write_stub(package_dir or os.curdir, ext, True)
419
420 def _gen_import_libs(self, def_dir):
421 """
422 On Windows generate import libraries that contains the code required to
423 load the DLL (.a) based on module definition files (.def)
424 """
425
426 for sim in ["icarus", "modelsim", "aldec", "ghdl", "nvcvhpi"]:
427 if self._uses_msvc():
428 subprocess.run(
429 [
430 self.compiler.lib,
431 "/def:" + os.path.join(def_dir, sim + ".def"),
432 "/out:" + os.path.join(def_dir, sim + ".lib"),
433 "/machine:" + ("X64" if sys.maxsize > 2**32 else "X86"),
434 ],
435 check=True,
436 )
437 else:
438 subprocess.run(
439 [
440 "dlltool",
441 "-d",
442 os.path.join(def_dir, sim + ".def"),
443 "-l",
444 os.path.join(def_dir, "lib" + sim + ".a"),
445 ],
446 check=True,
447 )
448
449
450 def _get_python_lib_link():
451 """Get name of python library used for linking"""
452
453 if sys.platform == "darwin":
454 ld_library = sysconfig.get_config_var("LIBRARY")
455 else:
456 ld_library = sysconfig.get_config_var("LDLIBRARY")
457
458 if ld_library is not None:
459 python_lib_link = os.path.splitext(ld_library)[0][3:]
460 else:
461 python_version = sysconfig.get_python_version().replace(".", "")
462 python_lib_link = "python" + python_version
463
464 return python_lib_link
465
466
467 def _get_python_lib():
468 """Get the library for embedded the python interpreter"""
469
470 if os.name == "nt":
471 python_lib = _get_python_lib_link() + "." + _get_lib_ext_name()
472 elif sys.platform == "darwin":
473 python_lib = os.path.join(
474 sysconfig.get_config_var("LIBDIR"), "lib" + _get_python_lib_link() + "."
475 )
476 if os.path.exists(python_lib + "dylib"):
477 python_lib += "dylib"
478 else:
479 python_lib += "so"
480 else:
481 python_lib = "lib" + _get_python_lib_link() + "." + _get_lib_ext_name()
482
483 return python_lib
484
485
486 def _get_common_lib_ext(include_dirs, share_lib_dir):
487 """
488 Defines common libraries.
489
490 All libraries go into the same directory to enable loading without modifying the library path (e.g. LD_LIBRARY_PATH).
491 """
492
493 #
494 # libcocotbutils
495 #
496 libcocotbutils_sources = [os.path.join(share_lib_dir, "utils", "cocotb_utils.cpp")]
497 if os.name == "nt":
498 libcocotbutils_sources += ["libcocotbutils.rc"]
499 libcocotbutils_libraries = ["gpilog"]
500 if sys.platform.startswith(("linux", "darwin", "cygwin", "msys")):
501 libcocotbutils_libraries.append("dl") # dlopen, dlerror, dlsym
502 libcocotbutils = Extension(
503 os.path.join("cocotb", "libs", "libcocotbutils"),
504 define_macros=[("COCOTBUTILS_EXPORTS", ""), *_extra_defines],
505 include_dirs=include_dirs,
506 libraries=libcocotbutils_libraries,
507 sources=libcocotbutils_sources,
508 )
509
510 #
511 # libgpilog
512 #
513 python_lib_dirs = []
514 if sys.platform == "darwin":
515 python_lib_dirs = [sysconfig.get_config_var("LIBDIR")]
516
517 libgpilog_sources = [os.path.join(share_lib_dir, "gpi_log", "gpi_logging.cpp")]
518 if os.name == "nt":
519 libgpilog_sources += ["libgpilog.rc"]
520 libgpilog = Extension(
521 os.path.join("cocotb", "libs", "libgpilog"),
522 define_macros=[("GPILOG_EXPORTS", ""), *_extra_defines],
523 include_dirs=include_dirs,
524 sources=libgpilog_sources,
525 )
526
527 #
528 # libpygpilog
529 #
530 libpygpilog_sources = [
531 os.path.join(share_lib_dir, "py_gpi_log", "py_gpi_logging.cpp")
532 ]
533 if os.name == "nt":
534 libpygpilog_sources += ["libpygpilog.rc"]
535 libpygpilog = Extension(
536 os.path.join("cocotb", "libs", "libpygpilog"),
537 define_macros=[("PYGPILOG_EXPORTS", ""), *_extra_defines],
538 include_dirs=include_dirs,
539 libraries=["gpilog"],
540 sources=libpygpilog_sources,
541 )
542
543 #
544 # libembed
545 #
546 libembed_sources = [os.path.join(share_lib_dir, "embed", "embed.cpp")]
547 if os.name == "nt":
548 libembed_sources += ["libembed.rc"]
549 libembed = Extension(
550 os.path.join("cocotb", "libs", "libembed"),
551 define_macros=[
552 ("COCOTB_EMBED_EXPORTS", ""),
553 ("PYTHON_LIB", _get_python_lib()),
554 *_extra_defines,
555 ],
556 include_dirs=include_dirs,
557 libraries=["gpilog", "cocotbutils"],
558 sources=libembed_sources,
559 )
560
561 #
562 # libcocotb
563 #
564 libcocotb_sources = [os.path.join(share_lib_dir, "embed", "gpi_embed.cpp")]
565 if os.name == "nt":
566 libcocotb_sources += ["libcocotb.rc"]
567 libcocotb = Extension(
568 os.path.join("cocotb", "libs", "libcocotb"),
569 define_macros=_extra_defines,
570 include_dirs=include_dirs,
571 libraries=["gpilog", "cocotbutils", "pygpilog", "gpi"],
572 sources=libcocotb_sources,
573 )
574
575 #
576 # libgpi
577 #
578 libgpi_sources = [
579 os.path.join(share_lib_dir, "gpi", "GpiCbHdl.cpp"),
580 os.path.join(share_lib_dir, "gpi", "GpiCommon.cpp"),
581 ]
582 if os.name == "nt":
583 libgpi_sources += ["libgpi.rc"]
584 libgpi = Extension(
585 os.path.join("cocotb", "libs", "libgpi"),
586 define_macros=[
587 ("GPI_EXPORTS", ""),
588 ("LIB_EXT", _get_lib_ext_name()),
589 ("SINGLETON_HANDLES", ""),
590 *_extra_defines,
591 ],
592 include_dirs=include_dirs,
593 libraries=["cocotbutils", "gpilog", "embed"],
594 sources=libgpi_sources,
595 )
596
597 #
598 # simulator
599 #
600 simulator_sources = [
601 os.path.join(share_lib_dir, "simulator", "simulatormodule.cpp"),
602 ]
603 if os.name == "nt":
604 simulator_sources += ["simulator.rc"]
605 libsim = Extension(
606 os.path.join("cocotb", "simulator"),
607 define_macros=_extra_defines,
608 include_dirs=include_dirs,
609 libraries=["cocotbutils", "gpilog", "gpi", "pygpilog"],
610 library_dirs=python_lib_dirs,
611 sources=simulator_sources,
612 )
613
614 # The libraries in this list are compiled in order of their appearance.
615 # If there is a linking dependency on one library to another,
616 # the linked library must be built first.
617 return [libgpilog, libpygpilog, libcocotbutils, libembed, libgpi, libcocotb, libsim]
618
619
620 def _get_vpi_lib_ext(
621 include_dirs, share_lib_dir, sim_define, extra_lib=[], extra_lib_dir=[]
622 ):
623 lib_name = "libcocotbvpi_" + sim_define.lower()
624 libcocotbvpi_sources = [
625 os.path.join(share_lib_dir, "vpi", "VpiImpl.cpp"),
626 os.path.join(share_lib_dir, "vpi", "VpiCbHdl.cpp"),
627 os.path.join(share_lib_dir, "vpi", "VpiObj.cpp"),
628 os.path.join(share_lib_dir, "vpi", "VpiIterator.cpp"),
629 os.path.join(share_lib_dir, "vpi", "VpiSignal.cpp"),
630 ]
631 if os.name == "nt":
632 libcocotbvpi_sources += [lib_name + ".rc"]
633 libcocotbvpi = Extension(
634 os.path.join("cocotb", "libs", lib_name),
635 define_macros=[("COCOTBVPI_EXPORTS", ""), (sim_define, ""), *_extra_defines],
636 include_dirs=include_dirs,
637 libraries=["gpi", "gpilog", *extra_lib],
638 library_dirs=extra_lib_dir,
639 sources=libcocotbvpi_sources,
640 )
641
642 return libcocotbvpi
643
644
645 def _get_vhpi_lib_ext(
646 include_dirs, share_lib_dir, sim_define, extra_lib=[], extra_lib_dir=[]
647 ):
648 lib_name = "libcocotbvhpi_" + sim_define.lower()
649 libcocotbvhpi_sources = [
650 os.path.join(share_lib_dir, "vhpi", "VhpiImpl.cpp"),
651 os.path.join(share_lib_dir, "vhpi", "VhpiCbHdl.cpp"),
652 ]
653 if os.name == "nt":
654 libcocotbvhpi_sources += [lib_name + ".rc"]
655 libcocotbvhpi = Extension(
656 os.path.join("cocotb", "libs", lib_name),
657 include_dirs=include_dirs,
658 define_macros=[("COCOTBVHPI_EXPORTS", ""), (sim_define, ""), *_extra_defines],
659 libraries=["gpi", "gpilog", *extra_lib],
660 library_dirs=extra_lib_dir,
661 sources=libcocotbvhpi_sources,
662 )
663
664 return libcocotbvhpi
665
666
667 def get_ext():
•668 cfg_vars = sysconfig.get_config_vars()
669
670 if sys.platform == "darwin":
671 cfg_vars["LDSHARED"] = cfg_vars["LDSHARED"].replace("-bundle", "-dynamiclib")
672 cfg_vars["LDCXXSHARED"] = cfg_vars["LDSHARED"].replace("-bundle", "-dynamiclib")
673
674 share_lib_dir = os.path.relpath(os.path.join(cocotb_share_dir, "lib"))
675 include_dirs = [
676 os.path.relpath(os.path.join(cocotb_share_dir, "include")),
677 os.path.relpath(os.path.join(os.path.dirname(__file__), "src", "cocotb")),
678 ]
679
680 ext = []
681
682 logger.info("Compiling interface libraries for cocotb ...")
683
684 ext += _get_common_lib_ext(include_dirs, share_lib_dir)
685
686 #
687 # Icarus Verilog
688 #
689 icarus_extra_lib = []
690 logger.info("Compiling libraries for Icarus Verilog")
691 if os.name == "nt":
692 icarus_extra_lib = ["icarus"]
693
694 icarus_vpi_ext = _get_vpi_lib_ext(
695 include_dirs=include_dirs,
696 share_lib_dir=share_lib_dir,
697 sim_define="ICARUS",
698 extra_lib=icarus_extra_lib,
699 )
700 ext.append(icarus_vpi_ext)
701
702 #
703 # Modelsim/Questa
704 #
705 modelsim_extra_lib = []
706 logger.info("Compiling libraries for Modelsim/Questa")
707 if os.name == "nt":
708 modelsim_extra_lib = ["modelsim"]
709
710 modelsim_vpi_ext = _get_vpi_lib_ext(
711 include_dirs=include_dirs,
712 share_lib_dir=share_lib_dir,
713 sim_define="MODELSIM",
714 extra_lib=modelsim_extra_lib,
715 )
716 ext.append(modelsim_vpi_ext)
717
718 modelsim_vhpi_ext = _get_vhpi_lib_ext(
719 include_dirs=include_dirs,
720 share_lib_dir=share_lib_dir,
721 sim_define="MODELSIM",
722 extra_lib=modelsim_extra_lib,
723 )
724 ext.append(modelsim_vhpi_ext)
725
726 lib_name = "libcocotbfli_modelsim"
727 fli_sources = [
728 os.path.join(share_lib_dir, "fli", "FliImpl.cpp"),
729 os.path.join(share_lib_dir, "fli", "FliCbHdl.cpp"),
730 os.path.join(share_lib_dir, "fli", "FliObjHdl.cpp"),
731 ]
732 if os.name == "nt":
733 fli_sources += [lib_name + ".rc"]
734 fli_ext = Extension(
735 os.path.join("cocotb", "libs", lib_name),
736 define_macros=[("COCOTBFLI_EXPORTS", ""), *_extra_defines],
737 include_dirs=include_dirs,
738 libraries=["gpi", "gpilog", *modelsim_extra_lib],
739 sources=fli_sources,
740 )
741
742 ext.append(fli_ext)
743
744 #
745 # GHDL
746 #
747 ghdl_extra_lib = []
748 logger.info("Compiling libraries for GHDL")
749 if os.name == "nt":
750 ghdl_extra_lib = ["ghdl"]
751
752 ghdl_vpi_ext = _get_vpi_lib_ext(
753 include_dirs=include_dirs,
754 share_lib_dir=share_lib_dir,
755 sim_define="GHDL",
756 extra_lib=ghdl_extra_lib,
757 )
758 ext.append(ghdl_vpi_ext)
759
760 #
761 # IUS
762 #
763 if os.name == "posix":
764 logger.info("Compiling libraries for Incisive/Xcelium")
765 ius_vpi_ext = _get_vpi_lib_ext(
766 include_dirs=include_dirs, share_lib_dir=share_lib_dir, sim_define="IUS"
767 )
768 ext.append(ius_vpi_ext)
769
770 ius_vhpi_ext = _get_vhpi_lib_ext(
771 include_dirs=include_dirs, share_lib_dir=share_lib_dir, sim_define="IUS"
772 )
773 ext.append(ius_vhpi_ext)
774
775 #
776 # VCS
777 #
778 if os.name == "posix":
779 logger.info("Compiling libraries for VCS")
780 vcs_vpi_ext = _get_vpi_lib_ext(
781 include_dirs=include_dirs, share_lib_dir=share_lib_dir, sim_define="VCS"
782 )
783 ext.append(vcs_vpi_ext)
784
785 #
786 # Aldec Riviera Pro
787 #
788 aldec_extra_lib = []
789 logger.info("Compiling libraries for Riviera")
790 if os.name == "nt":
791 aldec_extra_lib = ["aldec"]
792
793 aldec_vpi_ext = _get_vpi_lib_ext(
794 include_dirs=include_dirs,
795 share_lib_dir=share_lib_dir,
796 sim_define="ALDEC",
797 extra_lib=aldec_extra_lib,
798 )
799 ext.append(aldec_vpi_ext)
800
801 aldec_vhpi_ext = _get_vhpi_lib_ext(
802 include_dirs=include_dirs,
803 share_lib_dir=share_lib_dir,
804 sim_define="ALDEC",
805 extra_lib=aldec_extra_lib,
806 )
807 ext.append(aldec_vhpi_ext)
808
809 #
810 # Verilator
811 #
812 if os.name == "posix":
813 logger.info("Compiling libraries for Verilator")
814 verilator_vpi_ext = _get_vpi_lib_ext(
815 include_dirs=include_dirs,
816 share_lib_dir=share_lib_dir,
817 sim_define="VERILATOR",
818 )
819 ext.append(verilator_vpi_ext)
820
821 #
822 # NVC
823 #
824 nvc_extra_lib = []
825 if os.name == "nt":
826 nvc_extra_lib = ["nvcvhpi"]
827 logger.info("Compiling libraries for NVC")
828 nvc_vhpi_ext = _get_vhpi_lib_ext(
829 include_dirs=include_dirs,
830 share_lib_dir=share_lib_dir,
831 sim_define="NVC",
832 extra_lib=nvc_extra_lib,
833 )
834 ext.append(nvc_vhpi_ext)
835
836 #
837 # DSim
838 #
839 if os.name == "posix":
840 logger.info("Compiling libraries for DSim")
841 dsim_vpi_ext = _get_vpi_lib_ext(
842 include_dirs=include_dirs, share_lib_dir=share_lib_dir, sim_define="DSim"
843 )
844 ext.append(dsim_vpi_ext)
845
846 return ext