[llvm] r347636 - [gn build] Create abi-breaking.h, config.h, llvm-config.h, and add a build file for llvm/lib/Support.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 26 21:19:18 PST 2018


Author: nico
Date: Mon Nov 26 21:19:17 2018
New Revision: 347636

URL: http://llvm.org/viewvc/llvm-project?rev=347636&view=rev
Log:
[gn build] Create abi-breaking.h, config.h, llvm-config.h, and add a build file for llvm/lib/Support.

The comments at the top of
llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn and
llvm/utils/gn/build/write_cmake_config.py should explain the main bits
happening in this patch. The main parts here are that these headers are
generated at build time, not gn time, and that currently they don't do any
actual feature checks but just hardcode most things based on the current OS,
which seems to work well enough. If this stops being enough, the feature checks
should each be their own action writing the result to somewhere, and the config
write step should depend on those checks (so that they can run in parallel and
as part of the build) -- utils/llvm/gn/README.rst already has some more words
on that in "Philosophy".

(write_cmake_config.py is also going to be used to write clang's
clang/include/clang/Config/config.h)

This also adds a few files for linking to system libraries in a consistent way
if needed in llvm/utils/gn/build/libs (and moves pthread to that model).0

I'm also adding llvm/utils/gn/secondary/llvm/lib/Target/targets.gni in this
patch because $native_arch is needed for writing llvm-config.h -- the rest of
it will be used later, when the build files for llvm/lib/Target get added. That
file describes how to select which archs to build.

As a demo, also add a build file for llvm-undname and make it the default build
target (it depends on everything that can currently be built).

Differential Revision: https://reviews.llvm.org/D54678

Added:
    llvm/trunk/utils/gn/build/libs/
    llvm/trunk/utils/gn/build/libs/pthread/
    llvm/trunk/utils/gn/build/libs/pthread/BUILD.gn
    llvm/trunk/utils/gn/build/libs/terminfo/
    llvm/trunk/utils/gn/build/libs/terminfo/BUILD.gn
    llvm/trunk/utils/gn/build/libs/terminfo/enable.gni
    llvm/trunk/utils/gn/build/libs/xml/
    llvm/trunk/utils/gn/build/libs/xml/BUILD.gn
    llvm/trunk/utils/gn/build/libs/xml/enable.gni
    llvm/trunk/utils/gn/build/libs/zlib/
    llvm/trunk/utils/gn/build/libs/zlib/BUILD.gn
    llvm/trunk/utils/gn/build/libs/zlib/enable.gni
    llvm/trunk/utils/gn/build/write_cmake_config.py
    llvm/trunk/utils/gn/secondary/llvm/include/
    llvm/trunk/utils/gn/secondary/llvm/include/llvm/
    llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/
    llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
    llvm/trunk/utils/gn/secondary/llvm/lib/Support/
    llvm/trunk/utils/gn/secondary/llvm/lib/Support/BUILD.gn
    llvm/trunk/utils/gn/secondary/llvm/lib/Target/
    llvm/trunk/utils/gn/secondary/llvm/lib/Target/targets.gni
    llvm/trunk/utils/gn/secondary/llvm/tools/
    llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/
    llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/BUILD.gn
    llvm/trunk/utils/gn/secondary/llvm/triples.gni
    llvm/trunk/utils/gn/secondary/llvm/version.gni
Modified:
    llvm/trunk/utils/gn/README.rst
    llvm/trunk/utils/gn/build/BUILD.gn
    llvm/trunk/utils/gn/build/toolchain/BUILD.gn
    llvm/trunk/utils/gn/secondary/BUILD.gn

Modified: llvm/trunk/utils/gn/README.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/README.rst?rev=347636&r1=347635&r2=347636&view=diff
==============================================================================
--- llvm/trunk/utils/gn/README.rst (original)
+++ llvm/trunk/utils/gn/README.rst Mon Nov 26 21:19:17 2018
@@ -78,9 +78,9 @@ for the `gen` command. The full GN refer
 GN has an autoformatter: `git ls-files '*.gn' '*.gni' | xargs -n 1 gn format`
 after making GN build changes is your friend.
 
-To not put `BUILD.gn` into the main tree, they are all below `utils/gn/tree`.
-For example, the build file for `llvm/lib/Support` is in
-`utils/gn/tree/llvm/lib/Support`.
+To not put `BUILD.gn` into the main tree, they are all below
+`utils/gn/secondary`.  For example, the build file for `llvm/lib/Support` is in
+`utils/gn/secondary/llvm/lib/Support`.
 
 .. _Philosophy:
 

Modified: llvm/trunk/utils/gn/build/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/BUILD.gn?rev=347636&r1=347635&r2=347636&view=diff
==============================================================================
--- llvm/trunk/utils/gn/build/BUILD.gn (original)
+++ llvm/trunk/utils/gn/build/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -1,7 +1,6 @@
 import("//llvm/utils/gn/build/buildflags.gni")
 import("//llvm/utils/gn/build/mac_sdk.gni")
 import("//llvm/utils/gn/build/toolchain/compiler.gni")
-import("//llvm/utils/gn/build/enable_threads.gni")
 
 config("compiler_defaults") {
   # FIXME: Don't define this globally here.
@@ -140,14 +139,3 @@ config("warn_covered_switch_default") {
     cflags = [ "-Wcovered-switch-default" ]
   }
 }
-
-config("pthread_config") {
-  visibility = [ ":pthread" ]
-  libs = [ "pthread" ]
-}
-
-group("pthread") {
-  if (llvm_enable_threads && host_os != "win") {
-    public_configs = [ ":pthread_config" ]
-  }
-}

Added: llvm/trunk/utils/gn/build/libs/pthread/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/pthread/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/pthread/BUILD.gn (added)
+++ llvm/trunk/utils/gn/build/libs/pthread/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,12 @@
+import("//llvm/utils/gn/build/libs/pthread/enable.gni")
+
+config("pthread_config") {
+  visibility = [ ":pthread" ]
+  libs = [ "pthread" ]
+}
+
+group("pthread") {
+  if (llvm_enable_threads && host_os != "win") {
+    public_configs = [ ":pthread_config" ]
+  }
+}

Added: llvm/trunk/utils/gn/build/libs/terminfo/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/terminfo/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/terminfo/BUILD.gn (added)
+++ llvm/trunk/utils/gn/build/libs/terminfo/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,12 @@
+import("//llvm/utils/gn/build/libs/terminfo/enable.gni")
+
+config("terminfo_config") {
+  visibility = [ ":terminfo" ]
+  libs = [ "ncurses" ]
+}
+
+group("terminfo") {
+  if (llvm_enable_terminfo) {
+    public_configs = [ ":terminfo_config" ]
+  }
+}

Added: llvm/trunk/utils/gn/build/libs/terminfo/enable.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/terminfo/enable.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/terminfo/enable.gni (added)
+++ llvm/trunk/utils/gn/build/libs/terminfo/enable.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,4 @@
+declare_args() {
+  # Whether to link against terminfo.
+  llvm_enable_terminfo = false
+}

Added: llvm/trunk/utils/gn/build/libs/xml/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/xml/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/xml/BUILD.gn (added)
+++ llvm/trunk/utils/gn/build/libs/xml/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,19 @@
+import("//llvm/utils/gn/build/libs/xml/enable.gni")
+import("//llvm/utils/gn/build/mac_sdk.gni")
+
+config("xml_config") {
+  visibility = [ ":xml" ]
+  defines = [ "LLVM_LIBXML2_ENABLED" ]
+  libs = [ "xml2" ]
+  if (host_os == "mac") {
+    include_dirs = [ "$mac_sdk/usr/include/libxml2" ]
+  } else {
+    include_dirs = [ "/usr/include/libxml2" ]
+  }
+}
+
+group("xml") {
+  if (llvm_enable_libxml2) {
+    public_configs = [ ":xml_config" ]
+  }
+}

Added: llvm/trunk/utils/gn/build/libs/xml/enable.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/xml/enable.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/xml/enable.gni (added)
+++ llvm/trunk/utils/gn/build/libs/xml/enable.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,4 @@
+declare_args() {
+  # Whether to include code that links against libxml2.
+  llvm_enable_libxml2 = host_os != "win"
+}

Added: llvm/trunk/utils/gn/build/libs/zlib/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/zlib/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/zlib/BUILD.gn (added)
+++ llvm/trunk/utils/gn/build/libs/zlib/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,12 @@
+import("//llvm/utils/gn/build/libs/zlib/enable.gni")
+
+config("zlib_config") {
+  visibility = [ ":zlib" ]
+  libs = [ "z" ]
+}
+
+group("zlib") {
+  if (llvm_enable_zlib) {
+    public_configs = [ ":zlib_config" ]
+  }
+}

Added: llvm/trunk/utils/gn/build/libs/zlib/enable.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/libs/zlib/enable.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/libs/zlib/enable.gni (added)
+++ llvm/trunk/utils/gn/build/libs/zlib/enable.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,4 @@
+declare_args() {
+  # Whether to include code that links against zlib.
+  llvm_enable_zlib = host_os != "win"
+}

Modified: llvm/trunk/utils/gn/build/toolchain/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/toolchain/BUILD.gn?rev=347636&r1=347635&r2=347636&view=diff
==============================================================================
--- llvm/trunk/utils/gn/build/toolchain/BUILD.gn (original)
+++ llvm/trunk/utils/gn/build/toolchain/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -50,7 +50,8 @@ toolchain("unix") {
     } else {
       # Remove the output file first so that ar doesn't try to modify the
       # existing file.
-      command = "rm -f {{output}} && ar rcsDT {{arflags}} -o {{output}} {{inputs}}"
+      command =
+          "rm -f {{output}} && ar rcsDT {{arflags}} -o {{output}} {{inputs}}"
     }
     description = "AR {{output}}"
     outputs = [

Added: llvm/trunk/utils/gn/build/write_cmake_config.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/write_cmake_config.py?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/write_cmake_config.py (added)
+++ llvm/trunk/utils/gn/build/write_cmake_config.py Mon Nov 26 21:19:17 2018
@@ -0,0 +1,109 @@
+"""Processes a foo.h.cmake file and writes foo.h.
+
+Takes a list of KEY=VALUE pairs (where VALUE can be empty).
+
+Handles these types of lines (note that FOO= sets the value of FOO to the empty
+string, which is falsy, but FOO=0 sets it to '0' which is truthy):
+
+1.) #cmakedefine01 FOO
+    Checks if key FOO is set to a truthy value, and depending on that prints
+    one of the following two lines:
+
+        #define FOO 1
+        #define FOO 0
+
+2.) #cmakedefine FOO
+    Checks if key FOO is set to a truthy in value, and depending on that prints
+    one of the following two lines:
+
+        #define FOO
+        /* #undef FOO */
+
+3.) #cmakedefine FOO asdf${BAR}jkl
+    Checks if key FOO is set to a truthy values, and if so replaces all
+    variable references in `asdf${BAR}jkl` with their value and prints that
+    (else it prints the same undef line as the previous form):
+
+        #define FOO asdfBAR_VALjkl
+        /* #undef FOO */
+
+4.) #define FOO asdf{BAR}jkl
+    Always gets its variable values filled in, independent of FOO's value being
+    set:
+
+        #define FOO asdfBAR_VALjkl
+
+Fails if any of the KEY=VALUE arguments aren't needed for processing the
+.h.cmake file, or if the .h.cmake file has unreplaces ${VAR} references after
+processing all values.
+"""
+
+import argparse
+import os
+import re
+import sys
+
+
+def main():
+    parser = argparse.ArgumentParser(
+                 epilog=__doc__,
+                 formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument('input', help='input file')
+    parser.add_argument('values', nargs='*', help='several KEY=VALUE pairs')
+    parser.add_argument('-o', '--output', required=True,
+                        help='output file')
+    args = parser.parse_args()
+
+    values = {}
+    for value in args.values:
+        key, val = value.split('=', 1)
+        values[key] = val
+    unused_values = set(values.keys())
+
+    # Matches e.g. '${CLANG_FOO}' and captures CLANG_FOO in group 1.
+    var_re = re.compile(r'\$\{([^}]*)\}')
+
+    in_lines = open(args.input).readlines()
+    out_lines = []
+    for in_line in in_lines:
+        def repl(m):
+            unused_values.discard(m.group(1))
+            return values[m.group(1)]
+        if in_line.startswith('#cmakedefine01 '):
+            _, var = in_line.split()
+            out_lines.append('#define %s %d\n' % (var, 1 if values[var] else 0))
+            unused_values.discard(var)
+        elif in_line.startswith('#cmakedefine '):
+            _, var = in_line.split(None, 1)
+            try:
+                var, val = var.split(None, 1)
+            except:
+                var, val = var.rstrip(), '\n'
+            if values[var]:
+                out_lines.append('#define %s %s' % (var,
+                                                    var_re.sub(repl, val)))
+            else:
+                out_lines.append('/* #undef %s */\n' % var)
+            unused_values.discard(var)
+        else:
+            # In particular, handles `#define FOO ${FOO}` lines.
+            out_lines.append(var_re.sub(repl, in_line))
+
+    if unused_values:
+        print >>sys.stderr, 'Unused --values args:'
+        print >>sys.stderr, '    ', '\n    '.join(unused_values)
+        return 1
+
+    output = ''.join(out_lines)
+
+    leftovers = var_re.findall(output)
+    if leftovers:
+        print >>sys.stderr, 'unprocessed values:\n', '\n'.join(leftovers)
+        return 1
+
+    if not os.path.exists(args.output) or open(args.output).read() != output:
+        open(args.output, 'w').write(output)
+
+
+if __name__ == '__main__':
+    sys.exit(main())

Modified: llvm/trunk/utils/gn/secondary/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/BUILD.gn?rev=347636&r1=347635&r2=347636&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/BUILD.gn (original)
+++ llvm/trunk/utils/gn/secondary/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -1,6 +1,6 @@
 group("default") {
   deps = [
-    "//llvm/lib/Demangle",
+    "//llvm/tools/llvm-undname",
   ]
 }
 

Added: llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,354 @@
+import("//llvm/lib/Target/targets.gni")
+import("//llvm/triples.gni")
+import("//llvm/utils/gn/build/buildflags.gni")
+import("//llvm/utils/gn/build/libs/pthread/enable.gni")
+import("//llvm/utils/gn/build/libs/terminfo/enable.gni")
+import("//llvm/utils/gn/build/libs/xml/enable.gni")
+import("//llvm/utils/gn/build/libs/zlib/enable.gni")
+import("//llvm/version.gni")
+
+# Contains actions to create config.h, llvm-config.h and abi-breaking.h.
+# Other than in the cmake build, these are created at build time, not at
+# config time. That way, they can run in parallel, and this pattern means that
+# e.g. creating the clang config header (which happens in another gn file)
+# doesn't block building lld.
+
+# The headers are created by processing the foo.h.cmake files as input,
+# to keep the gn build close to the cmake build.
+
+# Other than in the cmake build, header generation doesn't do any feature
+# checking. See also "Philosophy" in llvm/utils/gn/README.rst.
+
+# FIXME: Several of the config settings go in a global config header but
+# are only used in a single translation unit -- so toggling that value
+# causes a full rebuild when it really only has to rebuild a single file.
+# Instead monolithing config headers, investigate using something like
+# https://is.gd/buildflag_header_gni instead (needs to be done in both the
+# cmake build and here).
+
+# FIXME: This hardcodes a bunch of settings I never use; some of them should
+# become declare_args if anyone wants to set them.
+
+declare_args() {
+  # Enable additional checks that alter the LLVM C++ ABI.
+  llvm_enable_abi_breaking_checks = llvm_enable_assertions
+
+  # Iterate unordered llvm containers in reverse.
+  llvm_enable_reverse_iteration = false
+}
+
+action("abi-breaking") {
+  script = "//llvm/utils/gn/build/write_cmake_config.py"
+
+  sources = [
+    "abi-breaking.h.cmake",
+  ]
+  outputs = [
+    "$target_gen_dir/abi-breaking.h",
+  ]
+  args = [
+    "-o",
+    rebase_path(outputs[0], root_out_dir),
+
+    rebase_path(sources[0], root_out_dir),
+  ]
+
+  if (llvm_enable_abi_breaking_checks) {
+    args += [ "LLVM_ENABLE_ABI_BREAKING_CHECKS=1" ]
+  } else {
+    args += [ "LLVM_ENABLE_ABI_BREAKING_CHECKS=" ]
+  }
+
+  if (llvm_enable_reverse_iteration) {
+    args += [ "LLVM_ENABLE_REVERSE_ITERATION=1" ]
+  } else {
+    args += [ "LLVM_ENABLE_REVERSE_ITERATION=" ]
+  }
+}
+
+action("config") {
+  script = "//llvm/utils/gn/build/write_cmake_config.py"
+
+  public_deps = [
+    ":llvm-config",
+  ]
+
+  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/",
+    "ENABLE_BACKTRACES=1",
+    "ENABLE_CRASH_OVERRIDES=1",
+    "BACKTRACE_HEADER=execinfo.h",
+    "HAVE_CRASHREPORTERCLIENT_H=",
+    "HAVE_DECL_FE_ALL_EXCEPT=1",
+    "HAVE_DECL_FE_INEXACT=1",
+    "LLVM_ENABLE_DIA_SDK=",
+    "LLVM_ENABLE_CRASH_DUMPS=",
+    "HAVE_ERRNO_H=1",
+    "HAVE_FCNTL_H=1",
+    "HAVE_FENV_H=1",
+    "HAVE_FFI_CALL=",
+    "HAVE_FFI_FFI_H=",
+    "HAVE_FFI_H=",
+    "HAVE_LIBPFM=",
+    "HAVE_LIBPSAPI=",
+    "HAVE_MALLCTL=",
+    "HAVE_SIGNAL_H=1",
+    "HAVE_STRERROR=1",
+    "HAVE_SYS_STAT_H=1",
+    "HAVE_SYS_TYPES_H=1",
+    "HAVE__ALLOCA=",
+    "HAVE___ALLOCA=",
+    "HAVE___ASHLDI3=",
+    "HAVE___ASHRDI3=",
+    "HAVE___CHKSTK=",
+    "HAVE___CHKSTK_MS=",
+    "HAVE___CMPDI2=",
+    "HAVE___DIVDI3=",
+    "HAVE___FIXDFDI=",
+    "HAVE___FIXSFDI=",
+    "HAVE___FLOATDIDF=",
+    "HAVE___LSHRDI3=",
+    "HAVE___MAIN=",
+    "HAVE___MODDI3=",
+    "HAVE___UDIVDI3=",
+    "HAVE___UMODDI3=",
+    "HAVE____CHKSTK=",
+    "HAVE____CHKSTK_MS=",
+    "HOST_LINK_VERSION=",
+    "LLVM_TARGET_TRIPLE_ENV=",
+    "LLVM_VERSION_INFO=",
+    "LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=1",
+    "PACKAGE_BUGREPORT=https://bugs.llvm.org/",
+    "PACKAGE_NAME=LLVM",
+    "PACKAGE_STRING=LLVM ${llvm_version}svn",
+    "PACKAGE_VERSION=${llvm_version}svn",
+    "PACKAGE_VENDOR=",
+    "RETSIGTYPE=void",
+    "LLVM_GISEL_COV_ENABLED=",
+    "LLVM_GISEL_COV_PREFIX=",
+
+    # This is both in llvm-config.h and config.h; llvm-config.h doesn't
+    # define it if it's not set while config.h defines it to empty in that case.
+    "LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple",
+  ]
+
+  if (host_os == "linux") {
+    args += [
+      "HAVE_FUTIMENS=1",
+      "HAVE_LINK_H=1",
+      "HAVE_LSEEK64=1",
+      "HAVE_MALLINFO=1",
+      "HAVE_POSIX_FALLOCATE=1",
+      "HAVE_SCHED_GETAFFINITY=1",
+      "HAVE_CPU_COUNT=1",
+      "HAVE_VALGRIND_VALGRIND_H=1",
+    ]
+  } else {
+    args += [
+      "HAVE_FUTIMENS=",
+      "HAVE_LINK_H=",
+      "HAVE_LSEEK64=",
+      "HAVE_MALLINFO=",
+      "HAVE_POSIX_FALLOCATE=",
+      "HAVE_SCHED_GETAFFINITY=",
+      "HAVE_CPU_COUNT=",
+      "HAVE_VALGRIND_VALGRIND_H=",
+    ]
+  }
+
+  if (host_os == "mac") {
+    args += [
+      "HAVE_CRASHREPORTER_INFO=1",
+      "HAVE_DECL_ARC4RANDOM=1",
+      "HAVE_DLADDR=1",
+      "HAVE_LIBEDIT=1",
+      "HAVE_MALLOC_H=",
+      "HAVE_MACH_MACH_H=1",
+      "HAVE_MALLOC_MALLOC_H=1",
+      "HAVE_MALLOC_ZONE_STATISTICS=1",
+      "HAVE_LIBXAR=1",
+    ]
+  } else {
+    args += [
+      "HAVE_CRASHREPORTER_INFO=",
+      "HAVE_DECL_ARC4RANDOM=",
+      "HAVE_DLADDR=",
+      "HAVE_LIBEDIT=",
+      "HAVE_MACH_MACH_H=",
+      "HAVE_MALLOC_H=1",
+      "HAVE_MALLOC_MALLOC_H=",
+      "HAVE_MALLOC_ZONE_STATISTICS=",
+      "HAVE_LIBXAR=",
+    ]
+  }
+
+  if (host_os == "win") {
+    args += [
+      "HAVE_BACKTRACE=",
+      "HAVE_DECL_STRERROR_S=1",
+      "HAVE_DLFCN_H=",
+      "HAVE_DLOPEN=",
+      "HAVE_FUTIMES=",
+      "HAVE_GETPAGESIZE=",
+      "HAVE_GETRLIMIT=",
+      "HAVE_GETRUSAGE=",
+      "HAVE_ISATTY=",
+      "HAVE_LIBPTHREAD=",
+      "HAVE_PTHREAD_GETNAME_NP=",
+      "HAVE_PTHREAD_SETNAME_NP=",
+      "HAVE_LIBZ=",
+      "HAVE_POSIX_SPAWN=",
+      "HAVE_PREAD=",
+      "HAVE_PTHREAD_GETSPECIFIC=",
+      "HAVE_PTHREAD_H=",
+      "HAVE_PTHREAD_MUTEX_LOCK=",
+      "HAVE_PTHREAD_RWLOCK_INIT=",
+      "HAVE_REALPATH=",
+      "HAVE_SBRK=",
+      "HAVE_SETENV=",
+      "HAVE_SETRLIMIT=",
+      "HAVE_SIGALTSTACK=",
+      "HAVE_STRERROR_R=",
+      "HAVE_SYSCONF=",
+      "HAVE_SYS_IOCTL_H=",
+      "HAVE_SYS_MMAN_H=",
+      "HAVE_SYS_PARAM_H=",
+      "HAVE_SYS_RESOURCE_H=",
+      "HAVE_SYS_TIME_H=",
+      "HAVE_TERMIOS_H=",
+      "HAVE_UNISTD_H=",
+      "HAVE_ZLIB_H=",
+      "HAVE__CHSIZE_S=1",
+      "HAVE__UNWIND_BACKTRACE=",
+      "stricmp=_stricmp",
+      "strdup=_strdup",
+    ]
+  } else {
+    # POSIX-y system defaults.
+    args += [
+      "HAVE_BACKTRACE=1",
+      "HAVE_DECL_STRERROR_S=",
+      "HAVE_DLFCN_H=1",
+      "HAVE_DLOPEN=1",
+      "HAVE_FUTIMES=1",
+      "HAVE_GETPAGESIZE=1",
+      "HAVE_GETRLIMIT=1",
+      "HAVE_GETRUSAGE=1",
+      "HAVE_ISATTY=1",
+      "HAVE_LIBPTHREAD=1",
+      "HAVE_PTHREAD_GETNAME_NP=1",
+      "HAVE_PTHREAD_SETNAME_NP=1",
+      "HAVE_LIBZ=1",
+      "HAVE_POSIX_SPAWN=1",
+      "HAVE_PREAD=1",
+      "HAVE_PTHREAD_GETSPECIFIC=1",
+      "HAVE_PTHREAD_H=1",
+      "HAVE_PTHREAD_MUTEX_LOCK=1",
+      "HAVE_PTHREAD_RWLOCK_INIT=1",
+      "HAVE_REALPATH=1",
+      "HAVE_SBRK=1",
+      "HAVE_SETENV=1",
+      "HAVE_SETRLIMIT=1",
+      "HAVE_SIGALTSTACK=1",
+      "HAVE_STRERROR_R=1",
+      "HAVE_SYSCONF=1",
+      "HAVE_SYS_IOCTL_H=1",
+      "HAVE_SYS_MMAN_H=1",
+      "HAVE_SYS_PARAM_H=1",
+      "HAVE_SYS_RESOURCE_H=1",
+      "HAVE_SYS_TIME_H=1",
+      "HAVE_TERMIOS_H=1",
+      "HAVE_UNISTD_H=1",
+      "HAVE_ZLIB_H=1",
+      "HAVE__CHSIZE_S=",
+      "HAVE__UNWIND_BACKTRACE=1",
+      "stricmp=",
+      "strdup=",
+    ]
+  }
+
+  if (host_os == "linux") {
+    args += [ "LTDL_SHLIB_EXT=.so" ]
+  } else if (host_os == "mac") {
+    args += [ "LTDL_SHLIB_EXT=.dylib" ]
+  } else if (host_os == "win") {
+    args += [ "LTDL_SHLIB_EXT=.dll" ]
+  }
+
+  if (llvm_enable_terminfo) {
+    args += [ "HAVE_TERMINFO=1" ]
+  } else {
+    args += [ "HAVE_TERMINFO=" ]
+  }
+
+  if (llvm_enable_zlib) {
+    args += [ "LLVM_ENABLE_ZLIB=1" ]
+  } else {
+    args += [ "LLVM_ENABLE_ZLIB=" ]
+  }
+
+  if (llvm_enable_libxml2) {
+    args += [ "LLVM_LIBXML2_ENABLED=1" ]
+  } else {
+    args += [ "LLVM_LIBXML2_ENABLED=" ]
+  }
+}
+
+action("llvm-config") {
+  script = "//llvm/utils/gn/build/write_cmake_config.py"
+
+  sources = [
+    "llvm-config.h.cmake",
+  ]
+  outputs = [
+    "$target_gen_dir/llvm-config.h",
+  ]
+  args = [
+    "-o",
+    rebase_path(outputs[0], root_out_dir),
+    rebase_path(sources[0], root_out_dir),
+
+    "LLVM_ENABLE_DUMP=",
+    "LINK_POLLY_INTO_TOOLS=",
+    "LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple",
+    "LLVM_HAS_ATOMICS=1",
+    "LLVM_HOST_TRIPLE=$llvm_host_triple",
+    "LLVM_NATIVE_ARCH=$native_target",
+    "LLVM_NATIVE_ASMPARSER=1",
+    "LLVM_NATIVE_ASMPRINTER=1",
+    "LLVM_NATIVE_DISASSEMBLER=1",
+    "LLVM_NATIVE_TARGET=1",
+    "LLVM_NATIVE_TARGETINFO=1",
+    "LLVM_NATIVE_TARGETMC=1",
+    "LLVM_USE_INTEL_JITEVENTS=",
+    "LLVM_USE_OPROFILE=",
+    "LLVM_USE_PERF=",
+    "LLVM_VERSION_MAJOR=$llvm_version_major",
+    "LLVM_VERSION_MINOR=$llvm_version_minor",
+    "LLVM_VERSION_PATCH=$llvm_version_patch",
+    "PACKAGE_VERSION=${llvm_version}svn",
+    "LLVM_FORCE_ENABLE_STATS=",
+  ]
+
+  if (host_os == "win") {
+    args += [ "LLVM_ON_UNIX=" ]
+  } else {
+    args += [ "LLVM_ON_UNIX=1" ]
+  }
+
+  if (llvm_enable_threads) {
+    args += [ "LLVM_ENABLE_THREADS=1" ]
+  } else {
+    args += [ "LLVM_ENABLE_THREADS=" ]
+  }
+}

Added: llvm/trunk/utils/gn/secondary/llvm/lib/Support/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/Support/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/Support/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/Support/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,155 @@
+static_library("Support") {
+  output_name = "LLVMSupport"
+  deps = [
+    "//llvm/include/llvm/Config:config",
+    "//llvm/lib/Demangle",
+    "//llvm/utils/gn/build/libs/pthread",
+    "//llvm/utils/gn/build/libs/terminfo",
+    "//llvm/utils/gn/build/libs/zlib",
+  ]
+
+  # public_deps are used for depending on targets that generate headers
+  # which are included in public headers of this target. public_deps means
+  # that targets depending on Support will implicitly be built only after
+  # abi-breaking and llvm-config have been built.
+  public_deps = [
+    # abi-breaking.h is also include by public headers in ADT, but ADT has
+    # no target in the gn build.  Since everything depends on Support, this
+    # public_dep does double duty of abi-breaking.h uses in public headers of
+    # both Support and ADT.
+    "//llvm/include/llvm/Config:abi-breaking",
+    "//llvm/include/llvm/Config:llvm-config",
+  ]
+  include_dirs = [
+    "Unix",
+    "Windows",
+  ]
+  sources = [
+    "AMDGPUMetadata.cpp",
+    "APFloat.cpp",
+    "APInt.cpp",
+    "APSInt.cpp",
+    "ARMAttributeParser.cpp",
+    "ARMBuildAttrs.cpp",
+    "ARMWinEH.cpp",
+    "Allocator.cpp",
+    "BinaryStreamError.cpp",
+    "BinaryStreamReader.cpp",
+    "BinaryStreamRef.cpp",
+    "BinaryStreamWriter.cpp",
+    "BlockFrequency.cpp",
+    "BranchProbability.cpp",
+    "COM.cpp",
+    "CachePruning.cpp",
+    "Chrono.cpp",
+    "CodeGenCoverage.cpp",
+    "CommandLine.cpp",
+    "Compression.cpp",
+    "ConvertUTF.cpp",
+    "ConvertUTFWrapper.cpp",
+    "CrashRecoveryContext.cpp",
+    "DAGDeltaAlgorithm.cpp",
+    "DJB.cpp",
+    "DataExtractor.cpp",
+    "Debug.cpp",
+    "DebugCounter.cpp",
+    "DeltaAlgorithm.cpp",
+    "Error.cpp",
+    "ErrorHandling.cpp",
+    "FileCheck.cpp",
+    "FileOutputBuffer.cpp",
+    "FileUtilities.cpp",
+    "FoldingSet.cpp",
+    "FormatVariadic.cpp",
+    "FormattedStream.cpp",
+    "GlobPattern.cpp",
+    "GraphWriter.cpp",
+    "Hashing.cpp",
+    "InitLLVM.cpp",
+    "IntEqClasses.cpp",
+    "IntervalMap.cpp",
+    "ItaniumManglingCanonicalizer.cpp",
+    "JSON.cpp",
+    "JamCRC.cpp",
+    "KnownBits.cpp",
+    "LEB128.cpp",
+    "LineIterator.cpp",
+    "Locale.cpp",
+    "LockFileManager.cpp",
+    "LowLevelType.cpp",
+    "MD5.cpp",
+    "ManagedStatic.cpp",
+    "MathExtras.cpp",
+    "MemoryBuffer.cpp",
+    "NativeFormatting.cpp",
+    "Options.cpp",
+    "Parallel.cpp",
+    "PluginLoader.cpp",
+    "PrettyStackTrace.cpp",
+    "RandomNumberGenerator.cpp",
+    "Regex.cpp",
+    "SHA1.cpp",
+    "ScaledNumber.cpp",
+    "ScopedPrinter.cpp",
+    "SmallPtrSet.cpp",
+    "SmallVector.cpp",
+    "SourceMgr.cpp",
+    "SpecialCaseList.cpp",
+    "Statistic.cpp",
+    "StringExtras.cpp",
+    "StringMap.cpp",
+    "StringPool.cpp",
+    "StringRef.cpp",
+    "StringSaver.cpp",
+    "SymbolRemappingReader.cpp",
+    "SystemUtils.cpp",
+    "TarWriter.cpp",
+    "TargetParser.cpp",
+    "ThreadPool.cpp",
+    "Timer.cpp",
+    "ToolOutputFile.cpp",
+    "TrigramIndex.cpp",
+    "Triple.cpp",
+    "Twine.cpp",
+    "Unicode.cpp",
+    "UnicodeCaseFold.cpp",
+    "VersionTuple.cpp",
+    "WithColor.cpp",
+    "YAMLParser.cpp",
+    "YAMLTraits.cpp",
+    "circular_raw_ostream.cpp",
+    "raw_os_ostream.cpp",
+    "raw_ostream.cpp",
+    "regcomp.c",
+    "regerror.c",
+    "regexec.c",
+    "regfree.c",
+    "regstrlcpy.c",
+    "xxhash.cpp",
+
+    # System
+    "Atomic.cpp",
+    "DynamicLibrary.cpp",
+    "Errno.cpp",
+    "Host.cpp",
+    "Memory.cpp",
+    "Mutex.cpp",
+    "Path.cpp",
+    "Process.cpp",
+    "Program.cpp",
+    "RWMutex.cpp",
+    "Signals.cpp",
+    "TargetRegistry.cpp",
+    "ThreadLocal.cpp",
+    "Threading.cpp",
+    "Valgrind.cpp",
+    "VirtualFileSystem.cpp",
+    "Watchdog.cpp",
+  ]
+
+  libs = []
+
+  if (host_os == "linux") {
+    libs += [ "dl" ]
+  }
+}

Added: llvm/trunk/utils/gn/secondary/llvm/lib/Target/targets.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/Target/targets.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/Target/targets.gni (added)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/Target/targets.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,54 @@
+declare_args() {
+  # The target archs LLVM should support. Defaults to the host arch.
+  # Set to a list, e.g. `llvm_targets_to_build = [ "X86", "ARM" ]`,
+  # or to the string "all" to get all known targets.
+  llvm_targets_to_build = "host"
+}
+
+if (llvm_targets_to_build == "host") {
+  if (host_cpu == "x86" || host_cpu == "x64") {
+    llvm_targets_to_build = [ "X86" ]
+  } else if (host_cpu == "arm") {
+    llvm_targets_to_build = [ "ARM" ]
+  } else if (host_cpu == "arm64") {
+    llvm_targets_to_build = [ "AArch64" ]
+  } else {
+    assert(false, "add your host_cpu above")
+  }
+} else if (llvm_targets_to_build == "all") {
+  # FIXME: Port the remaining targets.
+  llvm_targets_to_build = [
+    "AArch64",
+    "ARM",
+    "X86",
+  ]
+}
+
+# Validate that llvm_targets_to_build is set to a list of valid targets,
+# and remember which targets are built.
+llvm_build_AArch64 = false
+llvm_build_ARM = false
+llvm_build_X86 = false
+foreach(target, llvm_targets_to_build) {
+  if (target == "AArch64") {
+    llvm_build_AArch64 = true
+  } else if (target == "ARM") {
+    llvm_build_ARM = true
+  } else if (target == "X86") {
+    llvm_build_X86 = true
+  } else {
+    #FIXME : Port the remaining targets.
+    assert(false, "Unknown target '$target'.")
+  }
+}
+
+# FIXME: This should be based off target_cpu once cross compiles work.
+if (host_cpu == "x86" || host_cpu == "x64") {
+  native_target = "X86"
+} else if (host_cpu == "arm") {
+  native_target = "ARM"
+} else if (host_cpu == "arm64") {
+  native_target = "AArch64"
+} else {
+  assert(false, "Unsuppored host_cpu '$host_cpu'.")
+}

Added: llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/BUILD.gn?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/tools/llvm-undname/BUILD.gn Mon Nov 26 21:19:17 2018
@@ -0,0 +1,9 @@
+executable("llvm-undname") {
+  deps = [
+    "//llvm/lib/Demangle",
+    "//llvm/lib/Support",
+  ]
+  sources = [
+    "llvm-undname.cpp",
+  ]
+}

Added: llvm/trunk/utils/gn/secondary/llvm/triples.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/triples.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/triples.gni (added)
+++ llvm/trunk/utils/gn/secondary/llvm/triples.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,12 @@
+if (host_os == "linux") {
+  llvm_host_triple = "x86_64-unknown-linux-gnu"
+} else if (host_os == "mac") {
+  llvm_host_triple = "x86_64-apple-darwin"
+} else if (host_os == "win") {
+  llvm_host_triple = "x86_64-pc-windows"
+}
+
+declare_args() {
+  # The default target triple.
+  llvm_target_triple = llvm_host_triple
+}

Added: llvm/trunk/utils/gn/secondary/llvm/version.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/version.gni?rev=347636&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/version.gni (added)
+++ llvm/trunk/utils/gn/secondary/llvm/version.gni Mon Nov 26 21:19:17 2018
@@ -0,0 +1,4 @@
+llvm_version_major = 8
+llvm_version_minor = 0
+llvm_version_patch = 0
+llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch"




More information about the llvm-commits mailing list