[llvm] r350977 - gn build: Create a template for unix toolchains.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 11 14:57:57 PST 2019


Author: pcc
Date: Fri Jan 11 14:57:57 2019
New Revision: 350977

URL: http://llvm.org/viewvc/llvm-project?rev=350977&view=rev
Log:
gn build: Create a template for unix toolchains.

Also change the toolchain description to use current_os instead of
host_os so that the template can be used for cross builds, and add
a current_os to the win toolchain to match the unix toolchain.

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

Modified:
    llvm/trunk/utils/gn/build/toolchain/BUILD.gn

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=350977&r1=350976&r2=350977&view=diff
==============================================================================
--- llvm/trunk/utils/gn/build/toolchain/BUILD.gn (original)
+++ llvm/trunk/utils/gn/build/toolchain/BUILD.gn Fri Jan 11 14:57:57 2019
@@ -9,119 +9,131 @@ declare_args() {
   }
 }
 
-toolchain("unix") {
-  cc = "cc"
-  cxx = "c++"
+template("unix_toolchain") {
+  toolchain(target_name) {
+    forward_variables_from(invoker, "*")
+
+    tool("cc") {
+      depfile = "{{output}}.d"
+      command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
+      depsformat = "gcc"
+      description = "CC {{output}}"
+      outputs = [
+        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+      ]
+    }
 
-  if (clang_base_path != "") {
-    cc = "$clang_base_path/bin/clang"
-    cxx = "$clang_base_path/bin/clang++"
-  }
+    tool("cxx") {
+      depfile = "{{output}}.d"
+      command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
+      depsformat = "gcc"
+      description = "CXX {{output}}"
+      outputs = [
+        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
+      ]
+    }
 
-  ld = cxx  # Don't use goma wrapper for linking.
-  if (use_goma) {
-    cc = "$goma_dir/gomacc $cc"
-    cxx = "$goma_dir/gomacc $cxx"
-  }
+    tool("alink") {
+      if (current_os == "mac") {
+        command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
+      } else {
+        # Remove the output file first so that ar doesn't try to modify the
+        # existing file.
+        command = "rm -f {{output}} && $ar rcsDT {{arflags}} {{output}} {{inputs}}"
+      }
+      description = "AR {{output}}"
+      outputs = [
+        "{{output_dir}}/{{target_output_name}}.a",
+      ]
+      output_prefix = "lib"
+      default_output_dir = "{{root_out_dir}}/lib"
+    }
 
-  tool("cc") {
-    depfile = "{{output}}.d"
-    command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
-    depsformat = "gcc"
-    description = "CC {{output}}"
-    outputs = [
-      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
-    ]
-  }
+    tool("solink") {
+      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+      if (current_os == "mac") {
+        command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
+        default_output_extension = ".dylib"
+      } else {
+        command =
+            "$ld -shared {{ldflags}} -Wl,-z,defs -o $outfile {{libs}} {{inputs}}"
+        default_output_extension = ".so"
+      }
+      description = "SOLINK $outfile"
+      outputs = [
+        outfile,
+      ]
+      lib_switch = "-l"
+      output_prefix = "lib"
+      default_output_dir = "{{root_out_dir}}/lib"
+    }
 
-  tool("cxx") {
-    depfile = "{{output}}.d"
-    command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
-    depsformat = "gcc"
-    description = "CXX {{output}}"
-    outputs = [
-      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
-    ]
-  }
+    tool("solink_module") {
+      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+      if (current_os == "mac") {
+        command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
+        default_output_extension = ".dylib"
+      } else {
+        command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
+        default_output_extension = ".so"
+      }
+      description = "SOLINK $outfile"
+      outputs = [
+        outfile,
+      ]
+      lib_switch = "-l"
+      default_output_dir = "{{root_out_dir}}/lib"
+    }
 
-  tool("alink") {
-    if (host_os == "mac") {
-      command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
-    } else {
-      # Remove the output file first so that ar doesn't try to modify the
-      # existing file.
-      command = "rm -f {{output}} && ar rcsDT {{arflags}} {{output}} {{inputs}}"
+    tool("link") {
+      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+      if (current_os == "mac") {
+        command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
+      } else {
+        command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
+      }
+      description = "LINK $outfile"
+      outputs = [
+        outfile,
+      ]
+      lib_switch = "-l"
+
+      # Setting this allows targets to override the default executable output by
+      # setting output_dir.
+      default_output_dir = "{{root_out_dir}}/bin"
     }
-    description = "AR {{output}}"
-    outputs = [
-      "{{output_dir}}/{{target_output_name}}.a",
-    ]
-    output_prefix = "lib"
-    default_output_dir = "{{root_out_dir}}/lib"
-  }
 
-  tool("solink") {
-    outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
-    if (host_os == "mac") {
-      command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
-      default_output_extension = ".dylib"
-    } else {
-      command =
-          "$ld -shared {{ldflags}} -Wl,-z,defs -o $outfile {{libs}} {{inputs}}"
-      default_output_extension = ".so"
+    tool("copy") {
+      command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
+      description = "COPY {{source}} {{output}}"
     }
-    description = "SOLINK $outfile"
-    outputs = [
-      outfile,
-    ]
-    lib_switch = "-l"
-    output_prefix = "lib"
-    default_output_dir = "{{root_out_dir}}/lib"
-  }
 
-  tool("solink_module") {
-    outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
-    if (host_os == "mac") {
-      command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
-      default_output_extension = ".dylib"
-    } else {
-      command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
-      default_output_extension = ".so"
+    tool("stamp") {
+      command = "touch {{output}}"
+      description = "STAMP {{output}}"
     }
-    description = "SOLINK $outfile"
-    outputs = [
-      outfile,
-    ]
-    lib_switch = "-l"
-    default_output_dir = "{{root_out_dir}}/lib"
   }
+}
 
-  tool("link") {
-    outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
-    if (host_os == "mac") {
-      command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
-    } else {
-      command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
-    }
-    description = "LINK $outfile"
-    outputs = [
-      outfile,
-    ]
-    lib_switch = "-l"
+unix_toolchain("unix") {
+  cc = "cc"
+  cxx = "c++"
 
-    # Setting this allows targets to override the default executable output by
-    # setting output_dir.
-    default_output_dir = "{{root_out_dir}}/bin"
+  if (clang_base_path != "") {
+    cc = "$clang_base_path/bin/clang"
+    cxx = "$clang_base_path/bin/clang++"
   }
 
-  tool("copy") {
-    command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
-    description = "COPY {{source}} {{output}}"
+  ld = cxx  # Don't use goma wrapper for linking.
+  if (use_goma) {
+    cc = "$goma_dir/gomacc $cc"
+    cxx = "$goma_dir/gomacc $cxx"
   }
 
-  tool("stamp") {
-    command = "touch {{output}}"
-    description = "STAMP {{output}}"
+  ar = "ar"
+
+  toolchain_args = {
+    current_os = host_os
   }
 }
 
@@ -228,4 +240,8 @@ toolchain("win") {
     command = "cmd /c type nul > {{output}}"
     description = "STAMP {{output}}"
   }
+
+  toolchain_args = {
+    current_os = "win"
+  }
 }




More information about the llvm-commits mailing list