Index: llvm/utils/gn/secondary/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/BUILD.gn +++ llvm/utils/gn/secondary/BUILD.gn @@ -1,6 +1,7 @@ group("default") { deps = [ ":lld", + "//clang/lib/Basic", "//llvm/tools/llc", "//llvm/tools/llvm-ar:symlinks", "//llvm/tools/llvm-as", Index: llvm/utils/gn/secondary/clang/include/clang/Basic/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/include/clang/Basic/BUILD.gn @@ -0,0 +1,109 @@ +import("//clang/utils/TableGen/clang_tablegen.gni") +import("//llvm/version.gni") + +# Version header. + +action("version") { + script = "//llvm/utils/gn/build/write_cmake_config.py" + + sources = [ + "Version.inc.in", + ] + outputs = [ + "$root_gen_dir/clang/include/clang/Basic/Version.inc", + ] + args = [ + "-o", + rebase_path(outputs[0], root_out_dir), + rebase_path(sources[0], root_out_dir), + + "CLANG_VERSION=$llvm_version", + "CLANG_VERSION_MAJOR=$llvm_version_major", + "CLANG_VERSION_MINOR=$llvm_version_minor", + "CLANG_VERSION_PATCHLEVEL=$llvm_version_patch", + ] +} + +# Diagnostics. + +diag_groups = [ + "Analysis", + "AST", + "Comment", + "Common", + "CrossTU", + "Driver", + "Frontend", + "Lex", + "Parse", + "Refactoring", + "Sema", + "Serialization", +] +foreach(diag_group, diag_groups) { + clang_tablegen("Diagnostic${diag_group}Kinds") { + args = [ + "-gen-clang-diags-defs", + "-clang-component=${diag_group}", + ] + td_file = "Diagnostic.td" + } +} +group("diags_tablegen") { + # DiagnosticGroups and DiagnosticIndexName are intentionally not part of this + # group. Much of clang depends on the DiagKinds.inc files transitively, + # but almost nothing needs DiagnosticGroups.inc or DiagnosticIndexName.inc. + public_deps = [] + foreach(diag_group, diag_groups) { + public_deps += [ ":Diagnostic${diag_group}Kinds" ] + } +} + +clang_tablegen("DiagnosticGroups") { + args = [ "-gen-clang-diag-groups" ] + td_file = "Diagnostic.td" +} + +clang_tablegen("DiagnosticIndexName") { + args = [ "-gen-clang-diags-index-name" ] + td_file = "Diagnostic.td" +} + +# Attributes + +clang_tablegen("AttrList") { + args = [ + "-gen-clang-attr-list", + "-I", + rebase_path("../..", root_out_dir), + ] + td_file = "Attr.td" +} + +clang_tablegen("AttrSubMatchRulesList") { + args = [ + "-gen-clang-attr-subject-match-rule-list", + "-I", + rebase_path("../..", root_out_dir), + ] + td_file = "Attr.td" +} + +clang_tablegen("AttrHasAttributeImpl") { + args = [ + "-gen-clang-attr-has-attribute-impl", + "-I", + rebase_path("../..", root_out_dir), + ] + td_file = "Attr.td" +} + +# Misc + +clang_tablegen("arm_neon") { + args = [ "-gen-arm-neon-sema" ] +} + +clang_tablegen("arm_fp16") { + args = [ "-gen-arm-neon-sema" ] +} Index: llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn @@ -0,0 +1,84 @@ +import("//clang/lib/ARCMigrate/enable.gni") +import("//clang/lib/StaticAnalyzer/Frontend/enable.gni") +import("//llvm/utils/gn/build/libs/xml/enable.gni") +import("//llvm/version.gni") + +config("Config_config") { + visibility = [ ":Config" ] + include_dirs = [ "$target_gen_dir/clang/include" ] +} + +action("Config") { + script = "//llvm/utils/gn/build/write_cmake_config.py" + + sources = [ + "config.h.cmake", + ] + outputs = [ + "$target_gen_dir/config.h", + ] + args = [ + "-o", + rebase_path(outputs[0], root_out_dir), + rebase_path(sources[0], root_out_dir), + + "BUG_REPORT_URL=https://bugs.llvm.org/", + "CLANG_DEFAULT_LINKER=", + "CLANG_DEFAULT_STD_C=", + "CLANG_DEFAULT_STD_CXX=", + "CLANG_DEFAULT_CXX_STDLIB=", + "CLANG_DEFAULT_RTLIB=", + "CLANG_DEFAULT_OBJCOPY=objcopy", + "CLANG_DEFAULT_OPENMP_RUNTIME=libomp", + "CLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_35", + "CLANG_LIBDIR_SUFFIX=", + "CLANG_RESOURCE_DIR=", + "C_INCLUDE_DIRS=", + "CLANG_CONFIG_FILE_SYSTEM_DIR=", + "CLANG_CONFIG_FILE_USER_DIR=", + "DEFAULT_SYSROOT=", + "GCC_INSTALL_PREFIX=", + "CLANG_ANALYZER_WITH_Z3=", + "BACKEND_PACKAGE_STRING=LLVM ${llvm_version}svn", + "ENABLE_LINKER_BUILD_ID=", + "ENABLE_X86_RELAX_RELOCATIONS=", + "ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=", + "CLANG_ENABLE_OBJC_REWRITER=1", # FIXME: flag? + ] + + if (clang_enable_arcmt) { + args += [ "CLANG_ENABLE_ARCMT=1" ] + } else { + args += [ "CLANG_ENABLE_ARCMT=" ] + } + + if (clang_enable_static_analyzer) { + args += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ] + } else { + args += [ "CLANG_ENABLE_STATIC_ANALYZER=" ] + } + + if (host_os != "win") { + args += [ "CLANG_HAVE_RLIMITS=1" ] + } else { + args += [ "CLANG_HAVE_RLIMITS=" ] + } + + if (llvm_enable_libxml2) { + args += [ "CLANG_HAVE_LIBXML=1" ] + } else { + args += [ "CLANG_HAVE_LIBXML=" ] + } + + if (host_os == "mac") { + # FIXME: Hardcoding this isn't great, but assuming that the host ld version + # has anything to do with the ld version where the built clang will run + # isn't either. Probably want to make this a declare_args. + args += [ "HOST_LINK_VERSION=305" ] + } else { + args += [ "HOST_LINK_VERSION=" ] + } + + # Let targets depending on this find the generated file. + public_configs = [ ":Config_config" ] +} Index: llvm/utils/gn/secondary/clang/lib/ARCMigrate/enable.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/lib/ARCMigrate/enable.gni @@ -0,0 +1,4 @@ +declare_args() { + # Whether to include the arc migrate tool in the clang binary. + clang_enable_arcmt = true +} Index: llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn @@ -0,0 +1,80 @@ +static_library("Basic") { + output_name = "clangBasic" + configs += [ "//llvm/utils/gn/build:clang_code" ] + public_deps = [ + # public_dep because public header Version.h includes generated Version.inc. + "//clang/include/clang/Basic:AttrList", + "//clang/include/clang/Basic:AttrSubMatchRulesList", + "//clang/include/clang/Basic:DiagnosticGroups", + "//clang/include/clang/Basic:diags_tablegen", + "//clang/include/clang/Basic:version", + ] + deps = [ + "//clang/include/clang/Basic:AttrHasAttributeImpl", + "//clang/include/clang/Basic:arm_fp16", + "//clang/include/clang/Basic:arm_neon", + "//clang/include/clang/Config", + "//llvm/include/llvm/Config:llvm-config", + "//llvm/lib/IR", + "//llvm/lib/MC", + "//llvm/lib/Support", + ] + include_dirs = [ "." ] + sources = [ + "Attributes.cpp", + "Builtins.cpp", + "CharInfo.cpp", + "Cuda.cpp", + "Diagnostic.cpp", + "DiagnosticIDs.cpp", + "DiagnosticOptions.cpp", + "FileManager.cpp", + "FileSystemStatCache.cpp", + "FixedPoint.cpp", + "IdentifierTable.cpp", + "LangOptions.cpp", + "MemoryBufferCache.cpp", + "Module.cpp", + "ObjCRuntime.cpp", + "OpenMPKinds.cpp", + "OperatorPrecedence.cpp", + "SanitizerBlacklist.cpp", + "SanitizerSpecialCaseList.cpp", + "Sanitizers.cpp", + "SourceLocation.cpp", + "SourceManager.cpp", + "TargetInfo.cpp", + "Targets.cpp", + "Targets/AArch64.cpp", + "Targets/AMDGPU.cpp", + "Targets/ARM.cpp", + "Targets/AVR.cpp", + "Targets/BPF.cpp", + "Targets/Hexagon.cpp", + "Targets/Lanai.cpp", + "Targets/Le64.cpp", + "Targets/MSP430.cpp", + "Targets/Mips.cpp", + "Targets/NVPTX.cpp", + "Targets/Nios2.cpp", + "Targets/OSTargets.cpp", + "Targets/PNaCl.cpp", + "Targets/PPC.cpp", + "Targets/RISCV.cpp", + "Targets/SPIR.cpp", + "Targets/Sparc.cpp", + "Targets/SystemZ.cpp", + "Targets/TCE.cpp", + "Targets/WebAssembly.cpp", + "Targets/X86.cpp", + "Targets/XCore.cpp", + "TokenKinds.cpp", + + # FIXME: This should be in its own target that passes -DHAVE_SVN_VERSION_INC + # and that also depends on a target generating SVNVersion.inc. + "Version.cpp", + "Warnings.cpp", + "XRayInstr.cpp", + "XRayLists.cpp", + ] +} Index: llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/enable.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/enable.gni @@ -0,0 +1,4 @@ +declare_args() { + # Whether to include the static analyzer in the clang binary. + clang_enable_static_analyzer = true +} Index: llvm/utils/gn/secondary/clang/utils/TableGen/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/utils/TableGen/BUILD.gn @@ -0,0 +1,19 @@ +executable("clang-tblgen") { + deps = [ + "//llvm/lib/Support", + "//llvm/lib/TableGen", + ] + sources = [ + "ClangASTNodesEmitter.cpp", + "ClangAttrEmitter.cpp", + "ClangCommentCommandInfoEmitter.cpp", + "ClangCommentHTMLNamedCharacterReferenceEmitter.cpp", + "ClangCommentHTMLTagsEmitter.cpp", + "ClangDataCollectorsEmitter.cpp", + "ClangDiagnosticsEmitter.cpp", + "ClangOptionDocEmitter.cpp", + "ClangSACheckersEmitter.cpp", + "NeonEmitter.cpp", + "TableGen.cpp", + ] +} Index: llvm/utils/gn/secondary/clang/utils/TableGen/clang_tablegen.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang/utils/TableGen/clang_tablegen.gni @@ -0,0 +1,41 @@ +# This file introduces a templates for running clang-tblgen. +# +# Parameters: +# +# args (required) +# [list of strings] Flags to pass to llvm-tblgen. +# +# output_name (optional) +# Basename of the generated output file. +# Defaults to target name with ".inc" appended. +# +# td_file (optional) +# The .td file to pass to llvm-tblgen. +# Defaults to target name with ".td" appended. +# +# visibility (optional) +# GN's regular visibility attribute, see `gn help visibility`. +# +# Example of usage: +# +# clang_tablegen("DiagnosticGroups") { +# args = [ "-gen-clang-diag-groups" ] +# td_file = "Diagnostic.td" +# } + +import("//llvm/utils/TableGen/tablegen.gni") + +template("clang_tablegen") { + tablegen(target_name) { + forward_variables_from(invoker, + [ + "args", + "output_name", + "td_file", + "visibility", + ]) + + # FIXME: In cross builds, this should depend on the host binary. + tblgen_target = "//clang/utils/TableGen:clang-tblgen" + } +} Index: llvm/utils/gn/secondary/lld/include/lld/Common/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/lld/include/lld/Common/BUILD.gn +++ llvm/utils/gn/secondary/lld/include/lld/Common/BUILD.gn @@ -12,7 +12,6 @@ args = [ "-o", rebase_path(outputs[0], root_out_dir), - rebase_path(sources[0], root_out_dir), "LLD_VERSION=$llvm_version", Index: llvm/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni =================================================================== --- llvm/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni +++ llvm/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni @@ -36,8 +36,12 @@ action(target_name) { forward_variables_from(invoker, [ "visibility" ]) - # FIXME: In cross builds, this should depend on the host binary. - tblgen_target = "//llvm/utils/TableGen:llvm-tblgen" + if (defined(invoker.tblgen_target)) { + tblgen_target = invoker.tblgen_target + } else { + # FIXME: In cross builds, this should depend on the host binary. + tblgen_target = "//llvm/utils/TableGen:llvm-tblgen" + } tblgen_executable = get_label_info(tblgen_target, "root_out_dir") + "/bin/" + get_label_info(tblgen_target, "name") deps = [