126 lines · plain
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-exception4 5"""Defines variables that use selects to configure LLVM based on platform."""6 7load(8 "//:vars.bzl",9 "LLVM_VERSION_MAJOR",10 "LLVM_VERSION_MINOR",11 "LLVM_VERSION_PATCH",12 "PACKAGE_VERSION",13)14 15def 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 29posix_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_LLVM_EXPORT_ANNOTATIONS=1",36 "LLVM_ENABLE_PLUGINS=1",37 "LLVM_ENABLE_THREADS=1",38 "HAVE_DEREGISTER_FRAME=1",39 "HAVE_LIBPTHREAD=1",40 "HAVE_PTHREAD_GETNAME_NP=1",41 "HAVE_PTHREAD_H=1",42 "HAVE_PTHREAD_SETNAME_NP=1",43 "HAVE_REGISTER_FRAME=1",44 "HAVE_SETENV_R=1",45 "HAVE_STRERROR_R=1",46 "HAVE_SYSEXITS_H=1",47 "HAVE_SYS_IOCTL_H=1",48 "HAVE_UNISTD_H=1",49]50 51linux_defines = posix_defines + [52 "_GNU_SOURCE",53 "HAVE_GETAUXVAL=1",54 "HAVE_MALLINFO=1",55 "HAVE_SBRK=1",56 "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",57]58 59macos_defines = posix_defines + [60 "HAVE_MACH_MACH_H=1",61 "HAVE_MALLOC_MALLOC_H=1",62 "HAVE_MALLOC_ZONE_STATISTICS=1",63 "HAVE_PROC_PID_RUSAGE=1",64 "HAVE_UNW_ADD_DYNAMIC_FDE=1",65]66 67win32_defines = [68 # Windows system library specific defines.69 "_CRT_SECURE_NO_DEPRECATE",70 "_CRT_SECURE_NO_WARNINGS",71 "_CRT_NONSTDC_NO_DEPRECATE",72 "_CRT_NONSTDC_NO_WARNINGS",73 "_SCL_SECURE_NO_DEPRECATE",74 "_SCL_SECURE_NO_WARNINGS",75 "UNICODE",76 "_UNICODE",77 78 # LLVM features79 r'LTDL_SHLIB_EXT=\".dll\"',80 r'LLVM_PLUGIN_EXT=\".dll\"',81]82 83# TODO: We should switch to platforms-based config settings to make this easier84# to express.85os_defines = select({86 "@bazel_tools//src/conditions:windows": win32_defines,87 "@bazel_tools//src/conditions:darwin": macos_defines,88 "@bazel_tools//src/conditions:freebsd": posix_defines,89 "//conditions:default": linux_defines,90})91 92# HAVE_BUILTIN_THREAD_POINTER is true for on Linux (outside of ppc64) for93# all recent toolchains. Add it here by default on Linux as we can't perform a94# configure time check.95builtin_thread_pointer = select({96 "@bazel_tools//src/conditions:linux_ppc64le": [],97 "@bazel_tools//src/conditions:linux": ["HAVE_BUILTIN_THREAD_POINTER"],98 "//conditions:default": [],99})100 101# TODO: We should split out host vs. target here.102llvm_config_defines = os_defines + builtin_thread_pointer + select({103 "@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"),104 "@bazel_tools//src/conditions:darwin_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"),105 "@bazel_tools//src/conditions:darwin_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"),106 "@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"),107 "@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"),108 "@bazel_tools//src/conditions:linux_riscv64": native_arch_defines("RISCV", "riscv64-unknown-linux-gnu"),109 "@bazel_tools//src/conditions:linux_s390x": native_arch_defines("SystemZ", "systemz-unknown-linux_gnu"),110 "//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"),111}) + [112 "LLVM_VERSION_MAJOR={}".format(LLVM_VERSION_MAJOR),113 "LLVM_VERSION_MINOR={}".format(LLVM_VERSION_MINOR),114 "LLVM_VERSION_PATCH={}".format(LLVM_VERSION_PATCH),115 r'LLVM_VERSION_STRING=\"{}\"'.format(PACKAGE_VERSION),116 # Set globally in HandleLLVMOptions.cmake117 # These shouldn't be needed by the C++11 standard, but are for some118 # platforms (e.g. glibc < 2.18. See119 # https://sourceware.org/bugzilla/show_bug.cgi?id=15366). These are also120 # included unconditionally in the CMake build:121 # https://github.com/llvm/llvm-project/blob/cd0dd8ece8e/llvm/cmake/modules/HandleLLVMOptions.cmake#L907-L909122 "__STDC_LIMIT_MACROS",123 "__STDC_CONSTANT_MACROS",124 "__STDC_FORMAT_MACROS",125]126