[llvm] e5ce1d3 - [gn] Move write_target_def_file to its own .gni file

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 05:42:10 PST 2025


Author: Nico Weber
Date: 2025-02-18T08:41:17-05:00
New Revision: e5ce1d3a56676a18d1c7659f6190efcbfbb51ddd

URL: https://github.com/llvm/llvm-project/commit/e5ce1d3a56676a18d1c7659f6190efcbfbb51ddd
DIFF: https://github.com/llvm/llvm-project/commit/e5ce1d3a56676a18d1c7659f6190efcbfbb51ddd.diff

LOG: [gn] Move write_target_def_file to its own .gni file

Added: 
    llvm/utils/gn/secondary/llvm/lib/Target/write_target_def_file.gni

Modified: 
    llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index c9f3af65a4565..5a13545a15b13 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -1,10 +1,10 @@
 import("//llvm/include/llvm/Config/config.gni")
 import("//llvm/lib/DebugInfo/PDB/enable_dia.gni")
-import("//llvm/lib/Target/targets.gni")
 import("//llvm/lib/Target/targets_with_asm_parsers.gni")
 import("//llvm/lib/Target/targets_with_disassemblers.gni")
 import("//llvm/lib/Target/targets_with_exegesis.gni")
 import("//llvm/lib/Target/targets_with_mcas.gni")
+import("//llvm/lib/Target/write_target_def_file.gni")
 import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/buildflags.gni")
 import("//llvm/utils/gn/build/libs/curl/enable.gni")
@@ -477,65 +477,41 @@ write_cmake_config("llvm-config") {
 ##############################################################################
 # .def files used by llvm/lib/Target
 
-template("write_target_def_file") {
-  assert(defined(invoker.key), "must set 'key' in $target_name")
-  assert(defined(invoker.value), "must set 'value' in $target_name")
-
-  write_cmake_config(target_name) {
-    visibility = [ ":write_target_def_files" ]
-    input = "$target_name.in"
-    output = "$target_gen_dir/$target_name"
-
-    if (defined(invoker.all_targets)) {
-      all_targets = invoker.all_targets
-    } else {
-      all_targets = llvm_targets_to_build
-    }
-
-    # Build something like
-    # `LLVM_ENUM_ASM_PARSERS=LLVM_ASM_PARSER(ARM)\nLLVM_ASM_PARSER(X86)\n`. Note
-    # that \n is a literal '\' followed by a literal 'n', not a newline
-    # character.  (write_cmake_config.py replaces that with a real newline).
-    value = ""
-    foreach(target, all_targets) {
-      value = "$value${invoker.value}($target)\n"
-    }
-    if (all_targets == []) {
-      not_needed(invoker, [ "value" ])
-    }
-    values = [ "${invoker.key}=$value" ]
-  }
-}
-
 write_target_def_file("AsmParsers.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_ASM_PARSERS"
   value = "LLVM_ASM_PARSER"
   all_targets = targets_with_asm_parsers
 }
 
 write_target_def_file("AsmPrinters.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_ASM_PRINTERS"
   value = "LLVM_ASM_PRINTER"
 }
 
 write_target_def_file("Disassemblers.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_DISASSEMBLERS"
   value = "LLVM_DISASSEMBLER"
   all_targets = targets_with_disassemblers
 }
 
 write_target_def_file("Targets.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_TARGETS"
   value = "LLVM_TARGET"
 }
 
 write_target_def_file("TargetMCAs.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_TARGETMCAS"
   value = "LLVM_TARGETMCA"
   all_targets = targets_with_mcas
 }
 
 write_target_def_file("TargetExegesis.def") {
+  visibility = [ ":write_target_def_files" ]
   key = "LLVM_ENUM_EXEGESIS"
   value = "LLVM_EXEGESIS"
   all_targets = targets_with_exegesis

diff  --git a/llvm/utils/gn/secondary/llvm/lib/Target/write_target_def_file.gni b/llvm/utils/gn/secondary/llvm/lib/Target/write_target_def_file.gni
new file mode 100644
index 0000000000000..8ff5edeb41f3d
--- /dev/null
+++ b/llvm/utils/gn/secondary/llvm/lib/Target/write_target_def_file.gni
@@ -0,0 +1,36 @@
+import("//llvm/lib/Target/targets.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+
+template("write_target_def_file") {
+  assert(defined(invoker.key), "must set 'key' in $target_name")
+  assert(defined(invoker.value), "must set 'value' in $target_name")
+
+  write_cmake_config(target_name) {
+    input = "$target_name.in"
+    output = "$target_gen_dir/$target_name"
+
+    if (defined(invoker.all_targets)) {
+      all_targets = invoker.all_targets
+    } else {
+      all_targets = llvm_targets_to_build
+    }
+
+    if (defined(invoker.visibility)) {
+      visibility = invoker.visibility
+    }
+
+    # Build something like
+    # `LLVM_ENUM_ASM_PARSERS=LLVM_ASM_PARSER(ARM)\nLLVM_ASM_PARSER(X86)\n`. Note
+    # that \n is a literal '\' followed by a literal 'n', not a newline
+    # character.  (write_cmake_config.py replaces that with a real newline).
+    value = ""
+    foreach(target, all_targets) {
+      value = "$value${invoker.value}($target)\n"
+    }
+    if (all_targets == []) {
+      not_needed(invoker, [ "value" ])
+    }
+    values = [ "${invoker.key}=$value" ]
+  }
+}
+


        


More information about the llvm-commits mailing list