[llvm] r350454 - [gn build] Add build files for unittests that load shared libraries

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 4 17:39:18 PST 2019


Author: nico
Date: Fri Jan  4 17:39:18 2019
New Revision: 350454

URL: http://llvm.org/viewvc/llvm-project?rev=350454&view=rev
Log:
[gn build] Add build files for unittests that load shared libraries

This is slightly ugly for three reasons:

- The shlib needs to go next to the binary to be found on all platforms, so the
  build files refer to target_out_dir
- The explicit -fPIC flag needed on the shared lib side, and the -rdynamic flag
  needed on the host side, on Linux 
- Plugins that refer to LLVM code and assume that the host will resolve them
  don't work on Windows -- PluginsTests won't test anything on Windows (but
  DynamicLibraryTests will, since the dll here doesn't call LLVM code)


If we get lots more of these plugin / plugin host targets it might make sense
to add a template for them. But for now, these are the last ones we need.

(We're at 6 plugin hosts, 2 of them tests, and at 6 shared libraries, 2 of them
tests as well. clang is a plugin host by default in the CMake build but not
(yet?) in the GN build.)

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

Added:
    llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/
    llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn
    llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/
    llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn
Modified:
    llvm/trunk/utils/gn/secondary/llvm/unittests/BUILD.gn

Modified: llvm/trunk/utils/gn/secondary/llvm/unittests/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/unittests/BUILD.gn?rev=350454&r1=350453&r2=350454&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/unittests/BUILD.gn (original)
+++ llvm/trunk/utils/gn/secondary/llvm/unittests/BUILD.gn Fri Jan  4 17:39:18 2019
@@ -33,14 +33,10 @@ group("unittests") {
     "ObjectYAML:ObjectYAMLTests",
     "OptRemarks:OptRemarksTests",
     "Option:OptionTests",
-
-    # FIXME: Add.
-    #"Passes:PluginsTests",
+    "Passes:PluginsTests",
     "ProfileData:ProfileDataTests",
     "Support:SupportTests",
-
-    # FIXME: Add.
-    #"Support/DynamicLibrary:DynamicLibraryTests",
+    "Support/DynamicLibrary:DynamicLibraryTests",
     "TextAPI:TextAPITests",
     "Transforms/IPO:IPOTests",
     "Transforms/Scalar:ScalarTests",

Added: llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn?rev=350454&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn Fri Jan  4 17:39:18 2019
@@ -0,0 +1,53 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+# Keyed off LLVM_ENABLE_PLUGINS in the CMake build, which is usually false
+# on Windows and true elsewhere.
+if (host_os != "win") {
+  loadable_module("TestPlugin") {
+    # Put plugin next to the unit test executable.
+    output_dir = target_out_dir
+
+    sources = [
+      "TestPlugin.cpp",
+    ]
+
+    deps = [
+      # TestPlugin doesn't want to link in any LLVM code, it just needs its
+      # headers.
+      "//llvm/include/llvm/IR:public_tablegen",
+    ]
+
+    if (host_os == "linux") {
+      # The GN build currently doesn't globally pass -fPIC, but that's
+      # needed for building .so files on Linux.  Just pass it manually
+      # for loadable_modules for now.
+      cflags = [ "-fPIC" ]
+    }
+  }
+}
+
+unittest("PluginsTests") {
+  deps = [
+    "//llvm/include/llvm/Config:config",
+    "//llvm/lib/IR",
+    "//llvm/lib/Passes",
+    "//llvm/lib/Support",
+    "//llvm/lib/Testing/Support",
+  ]
+  sources = [
+    "PluginsTest.cpp",
+  ]
+
+  # If plugins are disabled, this test will disable itself at runtime.
+  # Otherwise, reconfiguring with plugins disabled will leave behind a stale
+  # executable.
+  if (host_os != "win") {
+    deps += [ ":TestPlugin" ]
+    defines = [ "LLVM_ENABLE_PLUGINS" ]
+  }
+
+  if (host_os == "linux") {
+    # Corresponds to export_executable_symbols() in cmake.
+    ldflags = [ "-rdynamic" ]
+  }
+}

Added: llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn?rev=350454&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn Fri Jan  4 17:39:18 2019
@@ -0,0 +1,49 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+# FIXME: If we add -Wl,-z,nodelete to the global ldflags, we need to remove
+# it again for these tests (cf CMake).
+
+template("dynlib_add_module") {
+  not_needed(invoker, "*")
+
+  loadable_module(target_name) {
+    # Put plugin next to the unit test executable.
+    # This assumes that unittest() puts tests in target_out_dir.
+    output_dir = target_out_dir
+
+    sources = [
+      "PipSqueak.cpp",
+    ]
+
+    if (host_os == "linux") {
+      # The GN build currently doesn't globally pass -fPIC, but that's
+      # needed for building .so files on Linux.  Just pass it manually
+      # for loadable_modules for now.
+      cflags = [ "-fPIC" ]
+    }
+  }
+}
+
+dynlib_add_module("PipSqueak") {
+}
+
+dynlib_add_module("SecondLib") {
+}
+
+unittest("DynamicLibraryTests") {
+  deps = [
+    ":PipSqueak",
+    ":SecondLib",
+    "//llvm/include/llvm/Config:config",
+    "//llvm/lib/Support",
+  ]
+  sources = [
+    "DynamicLibraryTest.cpp",
+    "ExportedFuncs.cpp",
+  ]
+
+  if (host_os == "linux") {
+    # Corresponds to export_executable_symbols() in cmake.
+    ldflags = [ "-rdynamic" ]
+  }
+}




More information about the llvm-commits mailing list