[gn build] Reorganize libcxx/include/BUILD.gn a bit
authorNico Weber <thakis@chromium.org>
Wed, 13 Jan 2021 02:10:55 +0000 (21:10 -0500)
committerNico Weber <thakis@chromium.org>
Wed, 13 Jan 2021 02:30:06 +0000 (21:30 -0500)
- Merge 6706342f48bea80 -- no more libcxx_needs_site_config, we now
  always need it
- Since it was always off in practice, write_config bitrot. Unbitrot
  it so that it works
- Remove copy step and let concat step write to final location
  immediately -- and fix copy destination directory

As a side effect, libcxx/include/BUILD.gn now has only a single
sources list, which means the cmake sync script should be able to
automatically sync additions and removals of .h files. On the flipside,
this means this file now must be updated after most changes to
libcxx/include/__config_site.in, and looking through the last few months
of changes this looks like it's going to be a wash.

llvm/utils/gn/secondary/libcxx/include/BUILD.gn

index f1f1f37..4d7cdbe 100644 (file)
@@ -1,52 +1,68 @@
-import("//clang/resource_dir.gni")
 import("//libcxx/config.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 
-libcxx_needs_site_config =
-    libcxx_abi_version != 1 || libcxx_abi_namespace != "" || libcxx_abi_unstable
+write_cmake_config("write_config") {
+  input = "__config_site.in"
+  output = "$target_gen_dir/__config_site"
 
-if (libcxx_needs_site_config) {
-  write_cmake_config("write_config") {
-    input = "__config_site.in"
-    output = "$target_gen_dir/__config_site"
-
-    values = []
-    if (libcxx_abi_version != 1) {
-      values += [ "_LIBCPP_ABI_VERSION=$libcxx_abi_version" ]
-    }
-    if (libcxx_abi_namespace != "") {
-      values += [ "_LIBCPP_ABI_NAMESPACE=$libcxx_abi_namespace" ]
-    }
-    if (libcxx_abi_unstable) {
-      values += [ "_LIBCPP_ABI_UNSTABLE=1" ]
-    }
+  values = [
+    "_LIBCPP_ABI_FORCE_ITANIUM=",
+    "_LIBCPP_ABI_FORCE_MICROSOFT=",
+    "_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT=",
+    "_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE=",
+    "_LIBCPP_HAS_NO_STDIN=",
+    "_LIBCPP_HAS_NO_STDOUT=",
+    "_LIBCPP_HAS_NO_THREADS=",
+    "_LIBCPP_HAS_NO_MONOTONIC_CLOCK=",
+    "_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS=",
+    "_LIBCPP_HAS_MUSL_LIBC=",
+    "_LIBCPP_HAS_THREAD_API_PTHREAD=",
+    "_LIBCPP_HAS_THREAD_API_EXTERNAL=",
+    "_LIBCPP_HAS_THREAD_API_WIN32=",
+    "_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL=",
+    "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=",
+    "_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS=1",
+    "_LIBCPP_NO_VCRUNTIME=",
+    "_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=",
+    "_LIBCPP_ABI_NAMESPACE=",
+    "_LIBCPP_HAS_PARALLEL_ALGORITHMS=",
+    "_LIBCPP_HAS_NO_RANDOM_DEVICE=",
+    "_LIBCPP_HAS_NO_LOCALIZATION=",
+    "_LIBCPP_ABI_DEFINES=",
+  ]
+  if (libcxx_abi_version != 1) {
+    values += [ "_LIBCPP_ABI_VERSION=$libcxx_abi_version" ]
+  } else {
+    values += [ "_LIBCPP_ABI_VERSION=" ]
   }
-
-  # Generate a custom __config header. The new header is created
-  # by prepending __config_site to the current __config header.
-  action("concat_config") {
-    script = "//libcxx/utils/cat_files.py"
-    inputs = [
-      "$target_gen_dir/__config_site",
-      "__config",
-    ]
-    outputs = [ "$target_gen_dir/__config" ]
-    args = [
-      "$target_gen_dir/__config_site",
-      "__config",
-      "-o",
-      "$target_gen_dir/__config",
-    ]
-    deps = [ ":write_config" ]
+  if (libcxx_abi_namespace != "") {
+    values += [ "_LIBCPP_ABI_NAMESPACE=$libcxx_abi_namespace" ]
   }
-
-  copy("copy_config") {
-    sources = [ "$target_gen_dir/__config" ]
-    outputs = [ "$clang_resource_dir/include/c++/v1/{{source_file_part}}" ]
-    deps = [ ":concat_config" ]
+  if (libcxx_abi_unstable) {
+    values += [ "_LIBCPP_ABI_UNSTABLE=1" ]
+  } else {
+    values += [ "_LIBCPP_ABI_UNSTABLE=" ]
   }
 }
 
+# Generate a custom __config header. The new header is created
+# by prepending __config_site to the current __config header.
+action("concat_config") {
+  script = "//libcxx/utils/cat_files.py"
+  inputs = [
+    "$target_gen_dir/__config_site",
+    "__config",
+  ]
+  outputs = [ "$root_build_dir/include/c++/v1/__config" ]
+  args = [
+    rebase_path("$target_gen_dir/__config_site", root_build_dir),
+    rebase_path("__config", root_build_dir),
+    "-o",
+    rebase_path(outputs[0], root_build_dir)
+  ]
+  deps = [ ":write_config" ]
+}
+
 copy("include") {
   sources = [
     "__availability",
@@ -235,7 +251,7 @@ copy("include") {
     "wchar.h",
     "wctype.h",
   ]
-  deps = []
+  deps = [ ":concat_config" ]
   if (target_os != "mac" && target_os != "win") {
     # libcxx/cmake/Modules/HandleLibCXXABI.cmake sets
     # LIBCXX_CXX_ABI_HEADER_TARGET if the libcxx abi library either of
@@ -247,10 +263,5 @@ copy("include") {
     # don't get copied on macOS due to that.
     deps += [ "//libcxxabi/include" ]
   }
-  if (!libcxx_needs_site_config) {
-    sources += [ "__config" ]
-  } else {
-    deps += [ ":copy_config" ]
-  }
   outputs = [ "$root_build_dir/include/c++/v1/{{source_target_relative}}" ]
 }