Skip to content

Commit

Permalink
Make gn DXC build work for Linux and MacOS
Browse files Browse the repository at this point in the history
- 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 <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
  • Loading branch information
amaiorano authored and Dawn LUCI CQ committed Oct 24, 2023
1 parent 89290bb commit 2d123d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
44 changes: 32 additions & 12 deletions third_party/gn/dxc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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=",
Expand Down Expand Up @@ -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=",
Expand All @@ -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 += [
Expand All @@ -281,13 +283,17 @@ 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 += [
"HAVE_MALLOC_H=",
"HAVE_MALLINFO=",
"HAVE_MACH_MACH_H=1",
"HAVE_MACH_O_DYLD_H=1",
"HAVE_MALLOC_MALLOC_H=1",
"HAVE_MALLOC_ZONE_STATISTICS=1",
]
}
}
Expand Down Expand Up @@ -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}",
]
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2d123d0

Please sign in to comment.