From 2d123d0dfdc67af1dcbabd178be8073726b67524 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Tue, 24 Oct 2023 15:39:38 +0000 Subject: [PATCH] Make gn DXC build work for Linux and MacOS - Do not build ASTMerge.cpp. This code is unused, and is expected to be stripped by the linker, but isn't in debug Linux builds. - Add explicit rpath for MacOS build so that the dxc executable can be run from any directory, otherwise it fails to load dxcompiler.so. - Make the 'dxc' target visible on the three main platforms when the target_cpu is x64. Bug: dawn:1862 Change-Id: I0bd79a151ed930048dfdeeca350c0911c0425a2b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/157300 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Antonio Maiorano --- BUILD.gn | 3 +++ third_party/gn/dxc/BUILD.gn | 44 +++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 4155a658842..7493734db1b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -61,6 +61,9 @@ group("cmds") { "src/dawn/samples", "src/tint:cmds", ] + if (target_cpu == "x64" && (is_win || is_linux || is_mac)) { + deps += [ "third_party/gn/dxc:dxc" ] + } } group("all") { diff --git a/third_party/gn/dxc/BUILD.gn b/third_party/gn/dxc/BUILD.gn index 27444c3e58b..5909ce704ed 100644 --- a/third_party/gn/dxc/BUILD.gn +++ b/third_party/gn/dxc/BUILD.gn @@ -27,7 +27,9 @@ import("../../../scripts/dawn_overrides_with_defaults.gni") -import("//build/config/win/visual_studio_version.gni") +if (is_win) { + import("//build/config/win/visual_studio_version.gni") +} import("${dawn_root}/scripts/dawn_features.gni") import("build/add_hlsl_hctgen.gni") @@ -193,8 +195,6 @@ cmake_configure_file("config-header") { "HAVE_LONGJMP=", "HAVE_MALLCTL=", "HAVE_MALLINFO2=", - "HAVE_MALLOC_MALLOC_H=", - "HAVE_MALLOC_ZONE_STATISTICS=", "HAVE_MKDTEMP=", "HAVE_MKSTEMP=", "HAVE_MKTEMP=", @@ -246,7 +246,6 @@ cmake_configure_file("config-header") { "HAVE_FUTIMES=", "HAVE_GETPAGESIZE=", "HAVE_GETRUSAGE=", - "HAVE_MALLINFO=", "HAVE_SYS_MMAN_H=", "HAVE_SYS_PARAM_H=", "HAVE_SYS_RESOURCE_H=", @@ -258,6 +257,9 @@ cmake_configure_file("config-header") { "HAVE_MACH_MACH_H=", "HAVE_MACH_O_DYLD_H=", "HAVE_MALLOC_H=1", + "HAVE_MALLINFO=", + "HAVE_MALLOC_MALLOC_H=", + "HAVE_MALLOC_ZONE_STATISTICS=", ] } else if (is_linux || is_mac) { values += [ @@ -281,6 +283,8 @@ cmake_configure_file("config-header") { "HAVE_MALLINFO=1", "HAVE_MACH_MACH_H=", "HAVE_MACH_O_DYLD_H=", + "HAVE_MALLOC_MALLOC_H=", + "HAVE_MALLOC_ZONE_STATISTICS=", ] } else { values += [ @@ -288,6 +292,8 @@ cmake_configure_file("config-header") { "HAVE_MALLINFO=", "HAVE_MACH_MACH_H=1", "HAVE_MACH_O_DYLD_H=1", + "HAVE_MALLOC_MALLOC_H=1", + "HAVE_MALLOC_ZONE_STATISTICS=1", ] } } @@ -399,11 +405,19 @@ cmake_configure_file("Disassemblers-def") { cmake_configure_file("SharedLibAffix-h") { input = "$dawn_dxc_dir/lib/DxcSupport/SharedLibAffix.inc" output = "$target_gen_dir/include/dxc/Support/SharedLibAffix.h" + shared_library_prefix = "" + if (is_linux) { + shared_library_prefix = "lib" + } + shared_library_suffix = "" + if (is_win) { + shared_library_suffix = ".dll" + } else { + shared_library_suffix = ".so" + } values = [ - "CMAKE_SHARED_LIBRARY_PREFIX=", - - # TODO(amaiorano): .dll for Win32, .so for Linux, .dylib for MacOS? - "CMAKE_SHARED_LIBRARY_SUFFIX=.dll", + "CMAKE_SHARED_LIBRARY_PREFIX=${shared_library_prefix}", + "CMAKE_SHARED_LIBRARY_SUFFIX=${shared_library_suffix}", ] } @@ -1952,7 +1966,6 @@ dxcompiler_sourceset("clang_lib_frontend") { target_type = "static_library" # Ensure unused globals are stripped sources = [ "$dawn_dxc_dir/tools/clang/lib/Frontend/ASTConsumers.cpp", - "$dawn_dxc_dir/tools/clang/lib/Frontend/ASTMerge.cpp", "$dawn_dxc_dir/tools/clang/lib/Frontend/ASTUnit.cpp", "$dawn_dxc_dir/tools/clang/lib/Frontend/CacheTokens.cpp", "$dawn_dxc_dir/tools/clang/lib/Frontend/ChainedDiagnosticConsumer.cpp", @@ -2322,9 +2335,16 @@ executable("dxc") { data_deps = [ ":dxcompiler" ] - include_dirs = [ - "$visual_studio_path/DIA SDK/include", # Required for msvc builds - ] + # Set rpath to executable_path to be able to find dxcompiler.so on MacOS + if (is_mac) { + ldflags = [ "-Wl,-rpath,@executable_path" ] + } + + if (is_win) { + include_dirs = [ + "$visual_studio_path/DIA SDK/include", # Required for msvc builds + ] + } sources = [ "$dawn_dxc_dir/tools/clang/tools/dxc/dxcmain.cpp",