1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 """Defines variables that use selects to configure LLVM based on platform."""
15 def native_arch_defines(arch, triple):
17 r'LLVM_NATIVE_ARCH=\"{}\"'.format(arch),
18 "LLVM_NATIVE_ASMPARSER=LLVMInitialize{}AsmParser".format(arch),
19 "LLVM_NATIVE_ASMPRINTER=LLVMInitialize{}AsmPrinter".format(arch),
20 "LLVM_NATIVE_DISASSEMBLER=LLVMInitialize{}Disassembler".format(arch),
21 "LLVM_NATIVE_TARGET=LLVMInitialize{}Target".format(arch),
22 "LLVM_NATIVE_TARGETINFO=LLVMInitialize{}TargetInfo".format(arch),
23 "LLVM_NATIVE_TARGETMC=LLVMInitialize{}TargetMC".format(arch),
24 "LLVM_NATIVE_TARGETMCA=LLVMInitialize{}TargetMCA".format(arch),
25 r'LLVM_HOST_TRIPLE=\"{}\"'.format(triple),
26 r'LLVM_DEFAULT_TARGET_TRIPLE=\"{}\"'.format(triple),
32 "BACKTRACE_HEADER=<execinfo.h>",
33 r'LTDL_SHLIB_EXT=\".so\"',
34 r'LLVM_PLUGIN_EXT=\".so\"',
35 "LLVM_ENABLE_THREADS=1",
36 "HAVE_DEREGISTER_FRAME=1",
38 "HAVE_PTHREAD_GETNAME_NP=1",
40 "HAVE_PTHREAD_SETNAME_NP=1",
41 "HAVE_REGISTER_FRAME=1",
48 linux_defines = posix_defines + [
53 "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
56 macos_defines = posix_defines + [
58 "HAVE_MALLOC_MALLOC_H=1",
59 "HAVE_MALLOC_ZONE_STATISTICS=1",
60 "HAVE_PROC_PID_RUSAGE=1",
61 "HAVE_UNW_ADD_DYNAMIC_FDE=1",
65 # Windows system library specific defines.
66 "_CRT_SECURE_NO_DEPRECATE",
67 "_CRT_SECURE_NO_WARNINGS",
68 "_CRT_NONSTDC_NO_DEPRECATE",
69 "_CRT_NONSTDC_NO_WARNINGS",
70 "_SCL_SECURE_NO_DEPRECATE",
71 "_SCL_SECURE_NO_WARNINGS",
76 r'LTDL_SHLIB_EXT=\".dll\"',
77 r'LLVM_PLUGIN_EXT=\".dll\"',
80 # TODO: We should switch to platforms-based config settings to make this easier
83 "@bazel_tools//src/conditions:windows": win32_defines,
84 "@bazel_tools//src/conditions:darwin": macos_defines,
85 "@bazel_tools//src/conditions:freebsd": posix_defines,
86 "//conditions:default": linux_defines,
89 # TODO: We should split out host vs. target here.
90 llvm_config_defines = os_defines + select({
91 "@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"),
92 "@bazel_tools//src/conditions:darwin_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"),
93 "@bazel_tools//src/conditions:darwin_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"),
94 "@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"),
95 "@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"),
96 "@bazel_tools//src/conditions:linux_s390x": native_arch_defines("SystemZ", "systemz-unknown-linux_gnu"),
97 "//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"),
99 "LLVM_VERSION_MAJOR={}".format(LLVM_VERSION_MAJOR),
100 "LLVM_VERSION_MINOR={}".format(LLVM_VERSION_MINOR),
101 "LLVM_VERSION_PATCH={}".format(LLVM_VERSION_PATCH),
102 r'LLVM_VERSION_STRING=\"{}git\"'.format(LLVM_VERSION),
103 # These shouldn't be needed by the C++11 standard, but are for some
104 # platforms (e.g. glibc < 2.18. See
105 # https://sourceware.org/bugzilla/show_bug.cgi?id=15366). These are also
106 # included unconditionally in the CMake build:
107 # https://github.com/llvm/llvm-project/blob/cd0dd8ece8e/llvm/cmake/modules/HandleLLVMOptions.cmake#L907-L909
108 "__STDC_LIMIT_MACROS",
109 "__STDC_CONSTANT_MACROS",
110 "__STDC_FORMAT_MACROS",