| 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 |
| 4 |
|
| 5 |
"""Defines variables that use selects to configure LLVM based on platform.""" |
| 6 |
|
| 7 |
load( |
| 8 |
"//:vars.bzl", |
| 9 |
"LLVM_VERSION", |
| 10 |
"LLVM_VERSION_MAJOR", |
| 11 |
"LLVM_VERSION_MINOR", |
| 12 |
"LLVM_VERSION_PATCH", |
| 13 |
) |
| 14 |
|
| 15 |
def native_arch_defines(arch, triple): |
| 16 |
return [ |
| 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), |
| 27 |
] |
| 28 |
|
| 29 |
posix_defines = [ |
| 30 |
"LLVM_ON_UNIX=1", |
| 31 |
"HAVE_BACKTRACE=1", |
| 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", |
| 37 |
"HAVE_LIBPTHREAD=1", |
| 38 |
"HAVE_PTHREAD_GETNAME_NP=1", |
| 39 |
"HAVE_PTHREAD_H=1", |
| 40 |
"HAVE_PTHREAD_SETNAME_NP=1", |
| 41 |
"HAVE_REGISTER_FRAME=1", |
| 42 |
"HAVE_SETENV_R=1", |
| 43 |
"HAVE_STRERROR_R=1", |
| 44 |
"HAVE_SYSEXITS_H=1", |
| 45 |
"HAVE_UNISTD_H=1", |
| 46 |
] |
| 47 |
|
| 48 |
linux_defines = posix_defines + [ |
| 49 |
"_GNU_SOURCE", |
| 50 |
"HAVE_LINK_H=1", |
| 51 |
"HAVE_LSEEK64=1", |
| 52 |
"HAVE_MALLINFO=1", |
| 53 |
"HAVE_SBRK=1", |
| 54 |
"HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1", |
| 55 |
] |
| 56 |
|
| 57 |
macos_defines = posix_defines + [ |
| 58 |
"HAVE_MACH_MACH_H=1", |
| 59 |
"HAVE_MALLOC_MALLOC_H=1", |
| 60 |
"HAVE_MALLOC_ZONE_STATISTICS=1", |
| 61 |
"HAVE_PROC_PID_RUSAGE=1", |
| 62 |
"HAVE_UNW_ADD_DYNAMIC_FDE=1", |
| 63 |
] |
| 64 |
|
| 65 |
win32_defines = [ |
| 66 |
# Windows system library specific defines. |
| 67 |
"_CRT_SECURE_NO_DEPRECATE", |
| 68 |
"_CRT_SECURE_NO_WARNINGS", |
| 69 |
"_CRT_NONSTDC_NO_DEPRECATE", |
| 70 |
"_CRT_NONSTDC_NO_WARNINGS", |
| 71 |
"_SCL_SECURE_NO_DEPRECATE", |
| 72 |
"_SCL_SECURE_NO_WARNINGS", |
| 73 |
"UNICODE", |
| 74 |
"_UNICODE", |
| 75 |
|
| 76 |
# LLVM features |
| 77 |
r'LTDL_SHLIB_EXT=\".dll\"', |
| 78 |
r'LLVM_PLUGIN_EXT=\".dll\"', |
| 79 |
] |
| 80 |
|
| 81 |
# TODO: We should switch to platforms-based config settings to make this easier |
| 82 |
# to express. |
| 83 |
os_defines = select({ |
| 84 |
"@bazel_tools//src/conditions:windows": win32_defines, |
| 85 |
"@bazel_tools//src/conditions:darwin": macos_defines, |
| 86 |
"@bazel_tools//src/conditions:freebsd": posix_defines, |
| 87 |
"//conditions:default": linux_defines, |
| 88 |
}) |
| 89 |
|
| 90 |
# TODO: We should split out host vs. target here. |
| 91 |
llvm_config_defines = os_defines + select({ |
| 92 |
"@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"), |
| 93 |
"@bazel_tools//src/conditions:darwin_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"), |
| 94 |
"@bazel_tools//src/conditions:darwin_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"), |
| 95 |
"@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"), |
| 96 |
"@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"), |
| 97 |
"@bazel_tools//src/conditions:linux_s390x": native_arch_defines("SystemZ", "systemz-unknown-linux_gnu"), |
| 98 |
"//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"), |
| 99 |
}) + [ |
| 100 |
"LLVM_VERSION_MAJOR={}".format(LLVM_VERSION_MAJOR), |
| 101 |
"LLVM_VERSION_MINOR={}".format(LLVM_VERSION_MINOR), |
| 102 |
"LLVM_VERSION_PATCH={}".format(LLVM_VERSION_PATCH), |
| 103 |
r'LLVM_VERSION_STRING=\"{}git\"'.format(LLVM_VERSION), |
| 104 |
# These shouldn't be needed by the C++11 standard, but are for some |
| 105 |
# platforms (e.g. glibc < 2.18. See |
| 106 |
# https://sourceware.org/bugzilla/show_bug.cgi?id=15366). These are also |
| 107 |
# included unconditionally in the CMake build: |
| 108 |
# https://github.com/llvm/llvm-project/blob/cd0dd8ece8e/llvm/cmake/modules/HandleLLVMOptions.cmake#L907-L909 |
| 109 |
"__STDC_LIMIT_MACROS", |
| 110 |
"__STDC_CONSTANT_MACROS", |
| 111 |
"__STDC_FORMAT_MACROS", |
| 112 |
] |