[llvm] 642df18 - [gn build] Support compiler-rt/profile on Windows

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu May 6 10:26:14 PDT 2021


Author: Arthur Eubanks
Date: 2021-05-06T10:20:52-07:00
New Revision: 642df18f1437b1fffea2343fa471aebfff128c6e

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

LOG: [gn build] Support compiler-rt/profile on Windows

Reviewed By: thakis

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

Added: 
    

Modified: 
    llvm/utils/gn/build/toolchain/BUILD.gn
    llvm/utils/gn/secondary/BUILD.gn
    llvm/utils/gn/secondary/compiler-rt/BUILD.gn
    llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
    llvm/utils/gn/secondary/compiler-rt/target.gni

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index e1aaae2c35e25..63e61db2d16b6 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -239,113 +239,137 @@ if (host_os == "mac") {
   }
 }
 
-toolchain("win") {
-  cl = "cl"
-  link = "link"
-
-  if (clang_base_path != "") {
-    cl = rebase_path(clang_base_path, root_build_dir) + "/bin/clang-cl"
-    if (use_lld) {
-      link = rebase_path(clang_base_path, root_build_dir) + "/bin/lld-link"
+template("win_toolchain") {
+  toolchain(target_name) {
+    # https://groups.google.com/a/chromium.org/d/msg/gn-dev/F_lv5T-tNDM
+    forward_variables_from(invoker.toolchain_args, "*")
+    not_needed("*")
+
+    forward_variables_from(invoker, "*")
+
+    cl = "cl"
+    link = "link"
+
+    if (clang_base_path != "") {
+      cl = rebase_path(clang_base_path, root_build_dir) + "/bin/clang-cl"
+      if (use_lld) {
+        link = rebase_path(clang_base_path, root_build_dir) + "/bin/lld-link"
+      }
     }
-  }
 
-  if (use_goma) {
-    cl = "$goma_dir/gomacc $cl"
-  }
+    if (use_goma) {
+      cl = "$goma_dir/gomacc $cl"
+    }
 
-  tool("cc") {
-    command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
-    depsformat = "msvc"
-    description = "CC {{output}}"
-    outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
-  }
+    tool("cc") {
+      command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
+      depsformat = "msvc"
+      description = "CC {{output}}"
+      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
+    }
 
-  tool("cxx") {
-    command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
-    depsformat = "msvc"
-    description = "CXX {{output}}"
-    outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
-  }
+    tool("cxx") {
+      command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
+      depsformat = "msvc"
+      description = "CXX {{output}}"
+      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
+    }
 
-  tool("alink") {
-    command = "$link /lib /nologo {{arflags}} /out:{{output}} {{inputs}}"
-    description = "LIB {{output}}"
-    outputs = [ "{{output_dir}}/{{target_output_name}}.lib" ]
-    default_output_dir = "{{root_out_dir}}/lib"
-  }
+    tool("alink") {
+      command = "$link /lib /nologo {{arflags}} /out:{{output}} {{inputs}}"
+      description = "LIB {{output}}"
+      outputs = [ "{{output_dir}}/{{target_output_name}}.lib" ]
+      default_output_dir = "{{root_out_dir}}/lib"
+    }
 
-  tool("solink") {
-    outprefix = "{{output_dir}}/{{target_output_name}}"
-    dllfile = "$outprefix{{output_extension}}"
-    libfile = "$outprefix.lib"
-    pdbfile = "$outprefix.pdb"
-    command = "$link /nologo /dll {{ldflags}} /out:$dllfile /implib:$libfile /pdb:$pdbfile {{inputs}} {{libs}} "
-    description = "LINK $dllfile"
-    link_output = libfile
-    depend_output = libfile
-    runtime_outputs = [ dllfile ]
-    outputs = [
-      dllfile,
-      libfile,
-    ]
-    lib_switch = ""
-    default_output_extension = ".dll"
-    restat = true
-
-    # Put dlls next to the executables in bin/ on Windows, since Windows
-    # doesn't have a configurable rpath. This matches initialization of
-    # module_dir to bin/ in AddLLVM.cmake's set_output_directory().
-    default_output_dir = "{{root_out_dir}}/bin"
-  }
+    tool("solink") {
+      outprefix = "{{output_dir}}/{{target_output_name}}"
+      dllfile = "$outprefix{{output_extension}}"
+      libfile = "$outprefix.lib"
+      pdbfile = "$outprefix.pdb"
+      command = "$link /nologo /dll {{ldflags}} /out:$dllfile /implib:$libfile /pdb:$pdbfile {{inputs}} {{libs}} "
+      description = "LINK $dllfile"
+      link_output = libfile
+      depend_output = libfile
+      runtime_outputs = [ dllfile ]
+      outputs = [
+        dllfile,
+        libfile,
+      ]
+      lib_switch = ""
+      default_output_extension = ".dll"
+      restat = true
+
+      # Put dlls next to the executables in bin/ on Windows, since Windows
+      # doesn't have a configurable rpath. This matches initialization of
+      # module_dir to bin/ in AddLLVM.cmake's set_output_directory().
+      default_output_dir = "{{root_out_dir}}/bin"
+    }
 
-  # Plugins for opt and clang and so on don't work in LLVM's Windows build
-  # since the code doesn't have export annotations, but there are a few
-  # standalone loadable modules used for unit-testing LLVM's dynamic library
-  # loading code.
-  tool("solink_module") {
-    outprefix = "{{output_dir}}/{{target_output_name}}"
-    dllfile = "$outprefix{{output_extension}}"
-    pdbfile = "$outprefix.pdb"
-    command = "$link /nologo /dll {{ldflags}} /out:$dllfile /pdb:$pdbfile {{inputs}} {{libs}} "
-    description = "LINK_MODULE $dllfile"
-    outputs = [ dllfile ]
-    lib_switch = ""
-    runtime_outputs = outputs
-    default_output_extension = ".dll"
-
-    # No default_output_dir, all clients set output_dir.
-  }
+    # Plugins for opt and clang and so on don't work in LLVM's Windows build
+    # since the code doesn't have export annotations, but there are a few
+    # standalone loadable modules used for unit-testing LLVM's dynamic library
+    # loading code.
+    tool("solink_module") {
+      outprefix = "{{output_dir}}/{{target_output_name}}"
+      dllfile = "$outprefix{{output_extension}}"
+      pdbfile = "$outprefix.pdb"
+      command = "$link /nologo /dll {{ldflags}} /out:$dllfile /pdb:$pdbfile {{inputs}} {{libs}} "
+      description = "LINK_MODULE $dllfile"
+      outputs = [ dllfile ]
+      lib_switch = ""
+      runtime_outputs = outputs
+      default_output_extension = ".dll"
+
+      # No default_output_dir, all clients set output_dir.
+    }
 
-  tool("link") {
-    outprefix = "{{output_dir}}/{{target_output_name}}"
-    outfile = "$outprefix{{output_extension}}"
-    pdbfile = "$outprefix.pdb"
-    command = "$link /nologo {{ldflags}} /out:$outfile /pdb:$pdbfile {{inputs}} {{libs}}"
-    description = "LINK $outfile"
-    outputs = [ outfile ]
-    lib_switch = ""
-    default_output_extension = ".exe"
-
-    # Setting this allows targets to override the default executable output by
-    # setting output_dir.
-    default_output_dir = "{{root_out_dir}}/bin"
-  }
+    tool("link") {
+      outprefix = "{{output_dir}}/{{target_output_name}}"
+      outfile = "$outprefix{{output_extension}}"
+      pdbfile = "$outprefix.pdb"
+      command = "$link /nologo {{ldflags}} /out:$outfile /pdb:$pdbfile {{inputs}} {{libs}}"
+      description = "LINK $outfile"
+      outputs = [ outfile ]
+      lib_switch = ""
+      default_output_extension = ".exe"
 
-  tool("copy") {
-    # GN hands out slash-using paths, but cmd's copy needs backslashes.
-    # Use cmd's %foo:a=b% substitution feature to convert.
-    command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
-    description = "COPY {{source}} {{output}}"
-  }
+      # Setting this allows targets to override the default executable output by
+      # setting output_dir.
+      default_output_dir = "{{root_out_dir}}/bin"
+    }
 
-  tool("stamp") {
-    command = "cmd /c type nul > {{output}}"
-    description = "STAMP {{output}}"
+    tool("copy") {
+      # GN hands out slash-using paths, but cmd's copy needs backslashes.
+      # Use cmd's %foo:a=b% substitution feature to convert.
+      command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
+      description = "COPY {{source}} {{output}}"
+    }
+
+    tool("stamp") {
+      command = "cmd /c type nul > {{output}}"
+      description = "STAMP {{output}}"
+    }
   }
+}
 
+win_toolchain("win") {
   toolchain_args = {
     current_os = "win"
     current_cpu = host_cpu
   }
 }
+
+win_toolchain("stage2_win") {
+  toolchain_args = {
+    current_os = host_os
+    current_cpu = host_cpu
+
+    clang_base_path = root_build_dir
+    use_goma = false
+  }
+  deps = [
+    "//:clang($host_toolchain)",
+    "//:lld($host_toolchain)",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn
index 95afb4e7c11bd..50f1c4f26d6bb 100644
--- a/llvm/utils/gn/secondary/BUILD.gn
+++ b/llvm/utils/gn/secondary/BUILD.gn
@@ -8,14 +8,12 @@ group("default") {
     "//clang-tools-extra/test",
     "//clang/test",
     "//clang/tools/scan-build",
+    "//compiler-rt",
     "//compiler-rt/include",
     "//compiler-rt/lib/scudo",
     "//lld/test",
     "//llvm/test",
   ]
-  if (current_os == "linux" || current_os == "mac") {
-    deps += [ "//compiler-rt" ]
-  }
   if (current_os == "linux") {
     deps += [
       "//libcxx",

diff  --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
index 31c3c7266e4d3..6d7b54fdd01e8 100644
--- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
@@ -5,7 +5,11 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 # In the GN build, compiler-rt is always built by just-built clang and lld.
 # FIXME: For macOS and iOS builds, depend on lib in all needed target arch
 # toolchains and then lipo them together for the final output.
-supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
+if (current_os == "win") {
+  supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_win" ]
+} else {
+  supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
+}
 if (android_ndk_path != "") {
   supported_toolchains += [
     "//llvm/utils/gn/build/toolchain:stage2_android_aarch64",

diff  --git a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
index 8eae2cdb3972f..b98b85e3b77c7 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
@@ -1,8 +1,10 @@
 group("lib") {
-  deps = [
-    "//compiler-rt/lib/asan",
-    "//compiler-rt/lib/builtins",
-    "//compiler-rt/lib/profile",
-    "//compiler-rt/lib/tsan",
-  ]
+  deps = [ "//compiler-rt/lib/profile" ]
+  if (current_os != "win") {
+    deps += [
+      "//compiler-rt/lib/asan",
+      "//compiler-rt/lib/builtins",
+      "//compiler-rt/lib/tsan",
+    ]
+  }
 }

diff  --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni
index ead515fa50149..ac273372cee60 100644
--- a/llvm/utils/gn/secondary/compiler-rt/target.gni
+++ b/llvm/utils/gn/secondary/compiler-rt/target.gni
@@ -28,6 +28,9 @@ if (clang_enable_per_target_runtime_dir) {
   }
 } else if (current_os == "ios" || current_os == "mac") {
   crt_current_out_dir = "$clang_resource_dir/lib/darwin"
+} else if (current_os == "win") {
+  crt_current_out_dir = "$clang_resource_dir/lib/windows"
+  crt_current_target_suffix = "-$crt_current_target_arch"
 } else {
   assert(false, "unimplemented current_os " + current_os)
 }


        


More information about the llvm-commits mailing list