MCPcopy Index your code
hub / github.com/python/mypy / get_cflags

Function get_cflags

mypyc/build.py:660–747  ·  view source on GitHub ↗

Get C compiler flags for the given configuration. Args: compiler_type: Compiler type, e.g. "unix" or "msvc". If None, detected automatically. opt_level: Optimization level as string ("0", "1", "2", or "3"). debug_level: Debug level as string ("0", "1", "2", or "3").

(
    *,
    compiler_type: str | None = None,
    opt_level: str = "3",
    debug_level: str = "1",
    multi_file: bool = False,
    experimental_features: bool = False,
    log_trace: bool = False,
)

Source from the content-addressed store, hash-verified

658
659
660def get_cflags(
661 *,
662 compiler_type: str | None = None,
663 opt_level: str = "3",
664 debug_level: str = "1",
665 multi_file: bool = False,
666 experimental_features: bool = False,
667 log_trace: bool = False,
668) -> list[str]:
669 """Get C compiler flags for the given configuration.
670
671 Args:
672 compiler_type: Compiler type, e.g. "unix" or "msvc". If None, detected automatically.
673 opt_level: Optimization level as string ("0", "1", "2", or "3").
674 debug_level: Debug level as string ("0", "1", "2", or "3").
675 multi_file: Whether multi-file compilation mode is enabled.
676 experimental_features: Whether experimental features are enabled.
677 log_trace: Whether trace logging is enabled.
678
679 Returns:
680 List of compiler flags.
681 """
682 if compiler_type is None:
683 compiler: Any = ccompiler.new_compiler()
684 sysconfig.customize_compiler(compiler)
685 compiler_type = compiler.compiler_type
686
687 cflags: list[str] = []
688 if compiler_type == "unix":
689 cflags += [
690 f"-O{opt_level}",
691 f"-g{debug_level}",
692 "-Werror",
693 "-Wno-unused-function",
694 "-Wno-unused-label",
695 "-Wno-unreachable-code",
696 "-Wno-unused-variable",
697 "-Wno-unused-command-line-argument",
698 "-Wno-unknown-warning-option",
699 "-Wno-unused-but-set-variable",
700 "-Wno-ignored-optimization-argument",
701 # GCC at -O3 false-positives on struct hack (items[1]) in vec buffers
702 "-Wno-array-bounds",
703 "-Wno-stringop-overread",
704 "-Wno-stringop-overflow",
705 # Disables C Preprocessor (cpp) warnings
706 # See https://github.com/mypyc/mypyc/issues/956
707 "-Wno-cpp",
708 "-Wno-array-bounds",
709 "-Wno-stringop-overread",
710 "-Wno-stringop-overflow",
711 ]
712 if log_trace:
713 cflags.append("-DMYPYC_LOG_TRACE")
714 if experimental_features:
715 cflags.append("-DMYPYC_EXPERIMENTAL")
716 if opt_level == "0":
717 cflags.append("-UNDEBUG")

Callers 3

_generate_setup_pyFunction · 0.90
mypycifyFunction · 0.85

Calls 1

appendMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…