4242from mypyc .namegen import exported_name
4343from mypyc .options import CompilerOptions
4444
45+ LIBRT_MODULES = [("librt.internal" , "librt_internal.c" )]
46+
4547try :
4648 # Import setuptools so that it monkey-patch overrides distutils
4749 import setuptools
@@ -492,8 +494,8 @@ def mypycify(
492494 strict_dunder_typing : bool = False ,
493495 group_name : str | None = None ,
494496 log_trace : bool = False ,
495- depends_on_native_internal : bool = False ,
496- install_native_libs : bool = False ,
497+ depends_on_librt_internal : bool = False ,
498+ install_librt : bool = False ,
497499) -> list [Extension ]:
498500 """Main entry point to building using mypyc.
499501
@@ -544,11 +546,11 @@ def mypycify(
544546 mypyc_trace.txt (derived from executed operations). This is
545547 useful for performance analysis, such as analyzing which
546548 primitive ops are used the most and on which lines.
547- depends_on_native_internal : This is True only for mypy itself.
548- install_native_libs : If True, also build the native extension modules. Normally,
549- those are build and published on PyPI separately, but during
550- tests, we want to use their development versions (i.e. from
551- current commit).
549+ depends_on_librt_internal : This is True only for mypy itself.
550+ install_librt : If True, also build the librt extension modules. Normally,
551+ those are build and published on PyPI separately, but during
552+ tests, we want to use their development versions (i.e. from
553+ current commit).
552554 """
553555
554556 # Figure out our configuration
@@ -562,7 +564,7 @@ def mypycify(
562564 strict_dunder_typing = strict_dunder_typing ,
563565 group_name = group_name ,
564566 log_trace = log_trace ,
565- depends_on_native_internal = depends_on_native_internal ,
567+ depends_on_librt_internal = depends_on_librt_internal ,
566568 )
567569
568570 # Generate all the actual important C code
@@ -661,21 +663,25 @@ def mypycify(
661663 build_single_module (group_sources , cfilenames + shared_cfilenames , cflags )
662664 )
663665
664- if install_native_libs :
665- for name in ["native_internal.c" ] + RUNTIME_C_FILES :
666+ if install_librt :
667+ os .makedirs ("librt" , exist_ok = True )
668+ for name in RUNTIME_C_FILES :
666669 rt_file = os .path .join (build_dir , name )
667670 with open (os .path .join (include_dir (), name ), encoding = "utf-8" ) as f :
668671 write_file (rt_file , f .read ())
669- extensions .append (
670- get_extension ()(
671- "native_internal" ,
672- sources = [
673- os .path .join (build_dir , file )
674- for file in ["native_internal.c" ] + RUNTIME_C_FILES
675- ],
676- include_dirs = [include_dir ()],
677- extra_compile_args = cflags ,
672+ for mod , file_name in LIBRT_MODULES :
673+ rt_file = os .path .join (build_dir , file_name )
674+ with open (os .path .join (include_dir (), file_name ), encoding = "utf-8" ) as f :
675+ write_file (rt_file , f .read ())
676+ extensions .append (
677+ get_extension ()(
678+ mod ,
679+ sources = [
680+ os .path .join (build_dir , file ) for file in [file_name ] + RUNTIME_C_FILES
681+ ],
682+ include_dirs = [include_dir ()],
683+ extra_compile_args = cflags ,
684+ )
678685 )
679- )
680686
681687 return extensions
0 commit comments