Index: llvm/test/tools/llvm-config/booleans.test =================================================================== --- llvm/test/tools/llvm-config/booleans.test +++ llvm/test/tools/llvm-config/booleans.test @@ -18,7 +18,7 @@ CHECK-BUILD-MODE-NOT: warning RUN: llvm-config --build-system 2>&1 | FileCheck --check-prefix=CHECK-BUILD-SYSTEM %s -CHECK-BUILD-SYSTEM: cmake +CHECK-BUILD-SYSTEM: {{cmake|gn}} CHECK-BUILD-SYSTEM-NOT: error: CHECK-BUILD-SYSTEM-NOT: warning Index: llvm/utils/gn/build/write_cmake_config.py =================================================================== --- llvm/utils/gn/build/write_cmake_config.py +++ llvm/utils/gn/build/write_cmake_config.py @@ -53,6 +53,9 @@ values = {} for value in args.values: key, val = value.split('=', 1) + if key in values: + print('duplicate key "%s" in args' % key, file=sys.stderr) + return 1 values[key] = val.replace('\\n', '\n') unused_values = set(values.keys()) Index: llvm/utils/gn/secondary/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/BUILD.gn +++ llvm/utils/gn/secondary/BUILD.gn @@ -5,60 +5,8 @@ deps = [ "//clang/test", "//lld/test", - "//llvm/tools/bugpoint", - "//llvm/tools/dsymutil", - "//llvm/tools/lli", - "//llvm/tools/lli/ChildTarget:lli-child-target", - "//llvm/tools/llvm-c-test", - "//llvm/tools/llvm-cfi-verify", - "//llvm/tools/llvm-cov", - "//llvm/tools/llvm-cvtres", - "//llvm/tools/llvm-cxxdump", - "//llvm/tools/llvm-cxxfilt", - "//llvm/tools/llvm-cxxmap", - "//llvm/tools/llvm-diff", - "//llvm/tools/llvm-dwp", - "//llvm/tools/llvm-exegesis", - "//llvm/tools/llvm-extract", - "//llvm/tools/llvm-isel-fuzzer", - "//llvm/tools/llvm-link", - "//llvm/tools/llvm-mca", - "//llvm/tools/llvm-mt", - "//llvm/tools/llvm-opt-fuzzer", - "//llvm/tools/llvm-opt-report", - "//llvm/tools/llvm-rc", - "//llvm/tools/llvm-rtdyld", - "//llvm/tools/llvm-size", - "//llvm/tools/llvm-split", - "//llvm/tools/llvm-strings", - "//llvm/tools/llvm-undname", - "//llvm/tools/llvm-xray", - "//llvm/tools/sancov", - "//llvm/tools/sanstats", - "//llvm/tools/verify-uselistorder", - "//llvm/utils/yaml-bench", + "//llvm/test", ] - if (clang_enable_arcmt) { - deps += [ - "//clang/tools/arcmt-test", - "//clang/tools/c-arcmt-test", - ] - } - if (clang_enable_static_analyzer) { - deps += [ - "//clang/tools/clang-check", - "//clang/tools/clang-func-mapping", - ] - } - if (host_os != "win") { - # loadable_modules don't work on Windows. - # FIXME: In the CMake build, ENABLE_SHARED makes them work somehow - # (but they're off by default there too). - deps += [ - "//llvm/lib/Transforms/Hello", - "//llvm/tools/bugpoint-passes", - ] - } testonly = true } Index: llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn +++ llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn @@ -6,7 +6,7 @@ # - linking in clangTidyPlugin and clangIncludeFixerPlugin from # clang-tools-extra (which doesn't have any GN build files yet) # - using libclang.exports -# - an build target copying the Python bindings +# - a build target copying the Python bindings # - the GN linux build always builds without -fPIC (as if LLVM_ENABLE_PIC=OFF # in the CMake build), so libclang is always a static library on linux # - the GN build doesn't have LIBCLANG_BUILD_STATIC @@ -78,7 +78,12 @@ ldflags = [ "-Wl,-compatibility_version,1", "-Wl,-current_version,$llvm_version", + + # See llvm_setup_rpath() in CMake. "-Wl,-install_name,@rpath/libclang.dylib", + "-Wl,-rpath,@loader_path/../lib", ] } + + # FIXME: Use libclang.exports } Index: llvm/utils/gn/secondary/llvm/lib/LineEditor/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/lib/LineEditor/BUILD.gn @@ -0,0 +1,15 @@ +static_library("LineEditor") { + output_name = "LLVMLineEditor" + deps = [ + "//llvm/lib/Support", + ] + + sources = [ + "LineEditor.cpp", + ] + + # FIXME: llvm_have_libedit in gni file in this dir; use in Config/BUILD.gn + if (host_os == "mac") { + libs = [ "edit" ] + } +} Index: llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni @@ -0,0 +1,11 @@ +import("//llvm/lib/Target/targets.gni") + +# A single string with all built targets, separated by spaces. +llvm_targets_to_build_string = "" +foreach(target, llvm_targets_to_build) { + if (llvm_targets_to_build_string != "") { + llvm_targets_to_build_string += " " + } + llvm_targets_to_build_string += target +} + Index: llvm/utils/gn/secondary/llvm/lib/Testing/Support/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/lib/Testing/Support/BUILD.gn @@ -0,0 +1,12 @@ +static_library("Support") { + output_name = "LLVMTestingSupport" + deps = [ + "//llvm/lib/Support", + "//llvm/utils/unittest:gtest", + ] + sources = [ + "Error.cpp", + "SupportHelpers.cpp", + ] + testonly = true +} Index: llvm/utils/gn/secondary/llvm/lib/TextAPI/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/lib/TextAPI/BUILD.gn @@ -0,0 +1,12 @@ +static_library("TextAPI") { + output_name = "LLVMTextAPI" + deps = [ + "//llvm/lib/BinaryFormat", + "//llvm/lib/Support", + ] + include_dirs = [ "." ] + sources = [ + "ELF/ELFStub.cpp", + "ELF/TBEHandler.cpp", + ] +} Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -0,0 +1,299 @@ +import("//llvm/lib/DebugInfo/PDB/enable_dia.gni") +import("//llvm/lib/Target/targets_string.gni") +import("//llvm/triples.gni") +import("//llvm/utils/gn/build/buildflags.gni") +import("//llvm/utils/gn/build/libs/pthread/enable.gni") +import("//llvm/utils/gn/build/libs/xar/enable.gni") +import("//llvm/utils/gn/build/libs/xml/enable.gni") +import("//llvm/utils/gn/build/libs/zlib/enable.gni") +import("llvm_lit_site_cfg_files.gni") + +template("write_lit_config") { + action(target_name) { + script = "//llvm/utils/gn/build/write_cmake_config.py" + + sources = [ + invoker.input, + ] + outputs = [ + invoker.output, + ] + args = [ + "-o", + rebase_path(outputs[0], root_out_dir), + rebase_path(sources[0], root_out_dir), + + "LIT_SITE_CFG_IN_HEADER=## Autogenerated from ${sources[0]}, do not edit", + "ENABLE_SHARED=0", + "LLVM_BINARY_DIR=" + + rebase_path(get_label_info("//llvm", "target_out_dir")), + "LLVM_SOURCE_DIR=" + rebase_path("//llvm"), + "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"), + ] + if (host_os == "win") { + # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn + args += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ] + } else { + args += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ] + } + args += invoker.extra_args + } +} + +write_lit_config("lit_site_cfg") { + input = "//llvm/test/lit.site.cfg.py.in" + output = llvm_lit_site_cfg_file + extra_args = [ + "BUILD_SHARED_LIBS=0", + + # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes + # asan and the host OS is macOS. The GN build currently never uses + # LLVM_USE_SANITIZER. (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.) + "HOST_CC=cc", + + # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes + # lsan and the host OS is macOS. The GN build currently never uses + # LLVM_USE_SANITIZER. (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.) + "HOST_CXX=c++", + + # Only used by the Go bindings tests, and for detecting a 32-bit build + # and in a belt-and-suspenders check for detecting 32-bit host builds. + # (That check also checks LLVM_HOST_TRIPLE.) + "HOST_LDFLAGS=", + + "LLVM_ENABLE_FFI=0", + "LLVM_HAVE_OPT_VIEWER_MODULES=0", + "LLVM_HOST_TRIPLE=$llvm_host_triple", + "LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib"), + "LLVM_LINK_LLVM_DYLIB=0", + "LLVM_LIT_TOOLS_DIR=", # Intentionally empty, matches cmake build. + "LLVM_NATIVE_ARCH=$native_target", + "LLVM_TOOL_LTO_BUILD=1", + "LLVM_USE_INTEL_JITEVENTS=0", + "LLVM_USE_SANITIZER=", + "PYTHON_EXECUTABLE=$python_path", + "TARGETS_TO_BUILD=$llvm_targets_to_build_string", + "TARGET_TRIPLE=$llvm_target_triple", + + # No bindings are implemented in the GN build. + "LLVM_BINDINGS=", + + "GO_EXECUTABLE=", + "LLVM_INCLUDE_GO_TESTS=0", + + "HAVE_OCAMLOPT=0", + "HAVE_OCAML_OUNIT=0", + "OCAMLFIND=OCAMLFIND-NOTFOUND", + "OCAMLFLAGS=", + ] + + if (host_cpu == "x64") { + extra_args += [ "HOST_ARCH=x86_64" ] + } else { + assert(false, "unimplemented host_cpu " + host_cpu) + } + + if (host_os == "mac") { + extra_args += [ + "EXEEXT=", + "HOST_OS=Darwin", + "SHLIBEXT=.dylib", + ] + } else if (host_os == "linux") { + extra_args += [ + "EXEEXT=", + "HOST_OS=Linux", + "SHLIBEXT=.so", + ] + } else if (host_os == "win") { + extra_args += [ + "EXEEXT=.exe", + "HOST_OS=Windows", + "SHLIBEXT=.dll", + ] + } else { + assert(false, "unsupported host_os " + host_os) + } + if (host_os == "linux") { + # lit.cfg.py's have_ld_plugin_support() checks for "gold" in --version, + # so just claim that ld is gold on Linux. The function also checks if + # LLVMgold.so exists, but since that target isn't hooked up yet in the GN + # build the LLVMgold.so tests currently don't run anywhere in the GN build. + extra_args += [ "GOLD_EXECUTABLE=ld" ] + } else { + extra_args += [ "GOLD_EXECUTABLE=" ] + } + if (host_os == "mac") { + extra_args += [ "LD64_EXECUTABLE=ld" ] + } else { + extra_args += [ "LD64_EXECUTABLE=" ] + } + + if (llvm_enable_assertions) { + extra_args += [ "ENABLE_ASSERTIONS=1" ] + } else { + extra_args += [ "ENABLE_ASSERTIONS=0" ] # Must be 0. + } + + if (llvm_enable_libxar) { + extra_args += [ "HAVE_LIBXAR=1" ] + } else { + extra_args += [ "HAVE_LIBXAR=0" ] # Must be 0. + } + + if (llvm_enable_dia_sdk) { + extra_args += [ "LLVM_ENABLE_DIA_SDK=1" ] + } else { + extra_args += [ "LLVM_ENABLE_DIA_SDK=0" ] # Must be 0. + } + + if (llvm_enable_libxml2) { + extra_args += [ "LLVM_LIBXML2_ENABLED=1" ] + } else { + extra_args += [ "LLVM_LIBXML2_ENABLED=" ] # Must be empty. + } + + if (llvm_enable_threads) { + extra_args += [ "LLVM_ENABLE_THREADS=1" ] + } else { + extra_args += [ "LLVM_ENABLE_THREADS=0" ] # Must be 0. + } + + if (llvm_enable_zlib) { + extra_args += [ "HAVE_LIBZ=1" ] + } else { + extra_args += [ "HAVE_LIBZ=0" ] # Must be 0. + } +} + +write_lit_config("lit_unit_site_cfg") { + input = "//llvm/test/Unit/lit.site.cfg.py.in" + output = llvm_lit_unit_site_cfg_file + extra_args = [ "LLVM_BUILD_MODE=." ] +} + +# This target should contain all dependencies of check-llvm. +# //:default depends on it, so that ninja's default target builds all +# prerequisites for check-llvm but doesn't run check-llvm itself. +group("test") { + deps = [ + ":lit_site_cfg", + ":lit_unit_site_cfg", + + # Because llvm/tools/llvm-config/BUILD.gn calls llvm-build to generate + # LibraryDependencies.inc, llvm-config expects these libraries to exist + # even though nothing but unittests depends on them. Add explicit + # dependencies to make sure the libaries exist on disk when llvm-config's + # lit tests run. + "//llvm/lib/LineEditor", + "//llvm/lib/Testing/Support", + "//llvm/lib/TextAPI", + "//llvm/tools/bugpoint", + "//llvm/tools/dsymutil", + "//llvm/tools/llc", + "//llvm/tools/lli", + "//llvm/tools/lli/ChildTarget:lli-child-target", + "//llvm/tools/llvm-ar:symlinks", + "//llvm/tools/llvm-as", + "//llvm/tools/llvm-bcanalyzer", + "//llvm/tools/llvm-c-test", + "//llvm/tools/llvm-cat", + "//llvm/tools/llvm-cfi-verify", + "//llvm/tools/llvm-cov", + "//llvm/tools/llvm-cvtres", + "//llvm/tools/llvm-cxxdump", + "//llvm/tools/llvm-cxxfilt", + "//llvm/tools/llvm-cxxmap", + "//llvm/tools/llvm-diff", + "//llvm/tools/llvm-dis", + "//llvm/tools/llvm-dwarfdump", + "//llvm/tools/llvm-dwp", + "//llvm/tools/llvm-extract", + "//llvm/tools/llvm-isel-fuzzer", + "//llvm/tools/llvm-link", + "//llvm/tools/llvm-lto", + "//llvm/tools/llvm-lto2", + "//llvm/tools/llvm-mc", + "//llvm/tools/llvm-mca", + "//llvm/tools/llvm-modextract", + "//llvm/tools/llvm-mt", + "//llvm/tools/llvm-nm", + "//llvm/tools/llvm-objcopy:symlinks", + "//llvm/tools/llvm-objdump", + "//llvm/tools/llvm-opt-fuzzer", + "//llvm/tools/llvm-opt-report", + "//llvm/tools/llvm-pdbutil", + "//llvm/tools/llvm-profdata", + "//llvm/tools/llvm-rc", + "//llvm/tools/llvm-readobj:symlinks", + "//llvm/tools/llvm-rtdyld", + "//llvm/tools/llvm-size", + "//llvm/tools/llvm-split", + "//llvm/tools/llvm-strings", + "//llvm/tools/llvm-symbolizer", + "//llvm/tools/llvm-undname", + "//llvm/tools/llvm-xray", + "//llvm/tools/lto", + "//llvm/tools/obj2yaml", + "//llvm/tools/opt", + "//llvm/tools/sancov", + "//llvm/tools/sanstats", + "//llvm/tools/verify-uselistorder", + "//llvm/tools/yaml2obj", + "//llvm/utils/FileCheck", + "//llvm/utils/TableGen:llvm-tblgen", + "//llvm/utils/count", + "//llvm/utils/not", + + # llvm-config wants libgtest_main.a to exist at runtime when run as in + # its tests, but nothing in the tree depends on them. + "//llvm/utils/unittest/UnitTestMain:gtest_main", + "//llvm/utils/yaml-bench", + ] + if (host_os == "mac") { + deps += [ ] + } + if (host_os != "win") { + # loadable_modules don't work on Windows. + # FIXME: In the CMake build, ENABLE_SHARED makes them work somehow + # (but they're off by default there too). + deps += [ + "//llvm/lib/Transforms/Hello", + "//llvm/tools/bugpoint-passes", + ] + } + + # FIXME: dep on "//llvm/unittests" once it exists + # FIXME: llvm_build_examples + testonly = true +} + +action("check-llvm") { + script = "$root_out_dir/bin/llvm-lit" + if (host_os == "win") { + script += ".py" + } + args = [ + "-sv", + "--param", + "llvm_site_config=" + rebase_path(llvm_lit_site_cfg_file, root_out_dir), + "--param", + "llvm_unit_site_config=" + + rebase_path(llvm_lit_unit_site_cfg_file, root_out_dir), + rebase_path(".", root_out_dir), + ] + outputs = [ + "$target_gen_dir/run-lit", # Non-existing, so that ninja runs it each time. + ] + + # Since check-llvm is always dirty, //:default doesn't depend on it so that + # it's not part of the default ninja target. Hence, check-llvm shouldn't + # have any deps except :test. so that the default target is sure to build + # all the deps. + deps = [ + ":test", + ] + testonly = true + + pool = "//:console" +} Index: llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni @@ -0,0 +1,2 @@ +llvm_lit_site_cfg_file = "$root_gen_dir/llvm/test/lit.site.cfg.py" +llvm_lit_unit_site_cfg_file = "$root_gen_dir/llvm/test/Unit/lit.site.cfg.py" Index: llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn @@ -1,4 +1,4 @@ -import("//llvm/lib/Target/targets.gni") +import("//llvm/lib/Target/targets_string.gni") import("//llvm/utils/gn/build/buildflags.gni") import("//llvm/utils/gn/build/libs/pthread/enable.gni") import("//llvm/utils/gn/build/libs/terminfo/enable.gni") @@ -6,14 +6,6 @@ import("//llvm/utils/gn/build/libs/zlib/enable.gni") import("//llvm/version.gni") -enable_targets = "" -foreach(target, llvm_targets_to_build) { - if (enable_targets != "") { - enable_targets += " " - } - enable_targets += target -} - action("BuildVariables.inc") { script = "//llvm/utils/gn/build/write_cmake_config.py" @@ -91,7 +83,7 @@ "LLVM_CXXFLAGS=.", # FIXME "LLVM_BUILDMODE=$build_mode", "LLVM_LIBDIR_SUFFIX=", - "LLVM_TARGETS_BUILT=$enable_targets", + "LLVM_TARGETS_BUILT=$llvm_targets_to_build_string", "LLVM_SYSTEM_LIBS=$system_libs", "LLVM_BUILD_SYSTEM=gn", "LLVM_HAS_RTTI=0", @@ -108,12 +100,14 @@ # FIXME: It'd be nice to not depend on llvm-build on this, Depending on all the # LLVMBuild.txt files just for this seems a bit overkill. `gn desc` should # have all this information too and could be called at build time. +# When this is removed, update llvm/test/BUILD.gn to no longer have unnecessary +# deps on a couple llvm/lib/ targets. action("LibraryDependencies.inc") { script = "//llvm/utils/llvm-build/llvm-build" output = "$target_gen_dir/LibraryDependencies.inc" args = [ "--native-target=$native_target", - "--enable-targets=$enable_targets", + "--enable-targets=$llvm_targets_to_build_string", "--write-library-table=" + rebase_path(output, root_out_dir), ] outputs = [ Index: llvm/utils/gn/secondary/llvm/tools/lto/BUILD.gn =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/llvm/tools/lto/BUILD.gn @@ -0,0 +1,39 @@ +import("//llvm/version.gni") + +lto_target_type = "loadable_module" +if (host_os == "linux") { + # Linux needs -fPIC to build shared libs but they aren't on by default. + # For now, make libclang a static lib there. + lto_target_type = "static_library" +} + +target(lto_target_type, "lto") { + output_name = "libLTO" + deps = [ + "//llvm/lib/Bitcode/Reader", + "//llvm/lib/IR", + "//llvm/lib/LTO", + "//llvm/lib/MC", + "//llvm/lib/MC/MCDisassembler", + "//llvm/lib/Support", + "//llvm/lib/Target", + "//llvm/lib/Target:TargetsToBuild", + ] + sources = [ + "LTODisassembler.cpp", + "lto.cpp", + ] + + if (host_os == "mac") { + ldflags = [ + "-Wl,-compatibility_version,1", + "-Wl,-current_version,$llvm_version", + + # See llvm_setup_rpath() in CMake. + "-Wl,-install_name,@rpath/libLTO.dylib", + "-Wl,-rpath,@loader_path/../lib", + ] + } + + # FIXME: Use lto.exports +} Index: llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn +++ llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn @@ -1,5 +1,6 @@ import("//clang/test/clang_lit_site_cfg_files.gni") import("//lld/test/lld_lit_site_cfg_files.gni") +import("//llvm/test/llvm_lit_site_cfg_files.gni") action("llvm-lit") { script = "//llvm/utils/gn/build/write_cmake_config.py" @@ -32,6 +33,8 @@ "//clang/test:lit_unit_site_cfg", "//lld/test:lit_site_cfg", "//lld/test:lit_unit_site_cfg", + "//llvm/test:lit_site_cfg", + "//llvm/test:lit_unit_site_cfg", ] # Note: \n is converted into a newline by write_cmake_config.py, not by gn. @@ -43,6 +46,10 @@ rebase_path(lld_lit_site_cfg_file) + "')\n" config_map += "map_config('" + rebase_path("//lld/test/Unit/lit.cfg.py") + "', '" + rebase_path(lld_lit_unit_site_cfg_file) + "')\n" + config_map += "map_config('" + rebase_path("//llvm/test/lit.cfg.py") + + "', '" + rebase_path(llvm_lit_site_cfg_file) + "')\n" + config_map += "map_config('" + rebase_path("//llvm/test/Unit/lit.cfg.py") + + "', '" + rebase_path(llvm_lit_unit_site_cfg_file) + "')\n" args = [ "-o",