Enable building without the proto library.
When using Dawn as library with CMake the user may not have the required
proto libraries checked out. This CL adds more guards to the proto code
in order to disable the build if desired.
Change-Id: I2b3a8a9cb67500db80d025aff4011e7593381863
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/192381
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 287738c..8bdae2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -192,6 +192,7 @@
option(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
option(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF)
option(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
+option(DAWN_BUILD_PROTOBUF "Build the protobuf dependencies" OFF)
option(DAWN_WERROR "Build with -Werror (or equivalent)" OFF)
option(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
@@ -543,7 +544,7 @@
################################################################################
# Run on all subdirectories
################################################################################
-if (EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
+if (DAWN_BUILD_PROTOBUF AND EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32)
set(protobuf_HAVE_BUILTIN_ATOMICS 1)
endif()
diff --git a/scripts/tint_overrides_with_defaults.gni b/scripts/tint_overrides_with_defaults.gni
index 82d6f8c..8ab6c42 100644
--- a/scripts/tint_overrides_with_defaults.gni
+++ b/scripts/tint_overrides_with_defaults.gni
@@ -42,7 +42,13 @@
}
tint_has_fuzzers = tint_has_build
-tint_has_protobuf = tint_standalone || build_with_chromium
+
+declare_args() {
+ # Is protobuf support present
+ if (!defined(tint_has_protobuf)) {
+ tint_has_protobuf = tint_standalone || build_with_chromium
+ }
+}
declare_args() {
# Path to tint checkout
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index d73a26c..a820043 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -41,7 +41,7 @@
endif()
endif()
-if (TARGET libprotobuf)
+if (DAWN_BUILD_PROTOBUF AND TARGET libprotobuf)
set(TINT_BUILD_IR_BINARY 1)
else()
set(TINT_BUILD_IR_BINARY 0)
@@ -672,16 +672,17 @@
################################################################################
# Generate protobuf sources
################################################################################
-foreach(PROTO_TARGET ${TINT_PROTO_TARGETS})
- generate_protos(
- TARGET ${PROTO_TARGET}
- IMPORT_DIRS "${TINT_ROOT_SOURCE_DIR}"
- PROTOC_OUT_DIR "${DAWN_BUILD_GEN_DIR}")
- target_include_directories(${PROTO_TARGET} PRIVATE "${DAWN_BUILD_GEN_DIR}/src/tint/")
- target_include_directories(${PROTO_TARGET} PUBLIC "${DAWN_BUILD_GEN_DIR}")
- target_link_libraries(${PROTO_TARGET} libprotobuf)
-endforeach()
-
+if (DAWN_BUILD_PROTOBUF)
+ foreach(PROTO_TARGET ${TINT_PROTO_TARGETS})
+ generate_protos(
+ TARGET ${PROTO_TARGET}
+ IMPORT_DIRS "${TINT_ROOT_SOURCE_DIR}"
+ PROTOC_OUT_DIR "${DAWN_BUILD_GEN_DIR}")
+ target_include_directories(${PROTO_TARGET} PRIVATE "${DAWN_BUILD_GEN_DIR}/src/tint/")
+ target_include_directories(${PROTO_TARGET} PUBLIC "${DAWN_BUILD_GEN_DIR}")
+ target_link_libraries(${PROTO_TARGET} libprotobuf)
+ endforeach()
+endif()
################################################################################
# tintd (VSCode WGSL language server)
diff --git a/src/tint/cmd/fuzz/ir/BUILD.cfg b/src/tint/cmd/fuzz/ir/BUILD.cfg
index 4184fdc..a5bef02 100644
--- a/src/tint/cmd/fuzz/ir/BUILD.cfg
+++ b/src/tint/cmd/fuzz/ir/BUILD.cfg
@@ -1,4 +1,7 @@
{
+ "proto": {
+ "Condition": "tint_build_ir_fuzzer"
+ },
"fuzz_cmd": {
"Condition": "tint_build_ir_fuzzer",
/* The Tint fuzzer executable for IR-input. */
diff --git a/src/tint/cmd/fuzz/ir/BUILD.cmake b/src/tint/cmd/fuzz/ir/BUILD.cmake
index edfb038..54630d1 100644
--- a/src/tint/cmd/fuzz/ir/BUILD.cmake
+++ b/src/tint/cmd/fuzz/ir/BUILD.cmake
@@ -34,14 +34,17 @@
# Do not modify this file directly
################################################################################
+if(TINT_BUILD_IR_FUZZER)
################################################################################
# Target: tint_cmd_fuzz_ir_proto
# Kind: proto
+# Condition: TINT_BUILD_IR_FUZZER
################################################################################
tint_add_target(tint_cmd_fuzz_ir_proto proto
cmd/fuzz/ir/fuzz.proto
)
+endif(TINT_BUILD_IR_FUZZER)
if(TINT_BUILD_IR_FUZZER)
################################################################################
# Target: tint_cmd_fuzz_ir_fuzz_cmd
@@ -55,7 +58,6 @@
tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd
tint_api_common
tint_cmd_fuzz_ir_fuzz
- tint_cmd_fuzz_ir_proto
tint_lang_core
tint_lang_core_constant
tint_lang_core_ir
@@ -105,6 +107,12 @@
)
endif(TINT_BUILD_IR_BINARY)
+if(TINT_BUILD_IR_FUZZER)
+ tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd
+ tint_cmd_fuzz_ir_proto
+ )
+endif(TINT_BUILD_IR_FUZZER)
+
if(TINT_BUILD_MSL_WRITER)
tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd
tint_lang_msl_writer_fuzz
diff --git a/src/tint/cmd/fuzz/ir/BUILD.gn b/src/tint/cmd/fuzz/ir/BUILD.gn
index 0077298..a147227 100644
--- a/src/tint/cmd/fuzz/ir/BUILD.gn
+++ b/src/tint/cmd/fuzz/ir/BUILD.gn
@@ -37,10 +37,11 @@
import("../../../../../scripts/tint_overrides_with_defaults.gni")
import("${tint_src_dir}/tint.gni")
-
-tint_proto_library("proto") {
- sources = [ "fuzz.proto" ]
- deps = []
+if (tint_build_ir_fuzzer) {
+ tint_proto_library("proto") {
+ sources = [ "fuzz.proto" ]
+ deps = []
+ }
}
tint_fuzz_source_set("fuzz") {
@@ -93,7 +94,6 @@
"${tint_lpm_dir}:libprotobuf-mutator",
"${tint_src_dir}/api/common",
"${tint_src_dir}/cmd/fuzz/ir:fuzz",
- "${tint_src_dir}/cmd/fuzz/ir:proto",
"${tint_src_dir}/lang/core",
"${tint_src_dir}/lang/core/constant",
"${tint_src_dir}/lang/core/ir",
@@ -135,6 +135,10 @@
]
}
+ if (tint_build_ir_fuzzer) {
+ deps += [ "${tint_src_dir}/cmd/fuzz/ir:proto" ]
+ }
+
if (tint_build_msl_writer) {
deps += [ "${tint_src_dir}/lang/msl/writer:fuzz" ]
}
diff --git a/src/tint/cmd/fuzz/ir/fuzz.cc b/src/tint/cmd/fuzz/ir/fuzz.cc
index 1942729..d74467c 100644
--- a/src/tint/cmd/fuzz/ir/fuzz.cc
+++ b/src/tint/cmd/fuzz/ir/fuzz.cc
@@ -65,7 +65,7 @@
std::cerr << err.Error() << "\n";
__builtin_trap();
}
-#endif
+#endif // TINT_BUILD_IR_BINARY
void Register(const IRFuzzer& fuzzer) {
#if TINT_BUILD_WGSL_READER
@@ -93,9 +93,12 @@
});
#endif
+#if TINT_BUILD_IR_BINARY
Fuzzers().Push(fuzzer);
+#endif // TINT_BUILD_IR_BINARY
}
+#if TINT_BUILD_IR_BINARY
void Run(const std::function<tint::core::ir::Module()>& acquire_module,
const Options& options,
Slice<const std::byte> data) {
@@ -144,5 +147,6 @@
}
}
}
+#endif // TINT_BUILD_IR_BINARY
} // namespace tint::fuzz::ir
diff --git a/src/tint/cmd/fuzz/ir/fuzz.h b/src/tint/cmd/fuzz/ir/fuzz.h
index cd391df..209f41e 100644
--- a/src/tint/cmd/fuzz/ir/fuzz.h
+++ b/src/tint/cmd/fuzz/ir/fuzz.h
@@ -94,6 +94,7 @@
/// @param fuzzer the fuzzer
void Register([[maybe_unused]] const IRFuzzer& fuzzer);
+#if TINT_BUILD_IR_BINARY
/// Runs all the registered IR fuzzers with the supplied IR module
/// @param acquire_module a function to obtain an IR module
/// @param options the options for running the fuzzers
@@ -101,6 +102,7 @@
void Run(const std::function<tint::core::ir::Module()>& acquire_module,
const Options& options,
Slice<const std::byte> data);
+#endif // TINT_BUILD_IR_BINARY
/// TINT_IR_MODULE_FUZZER registers the fuzzer function.
#define TINT_IR_MODULE_FUZZER(FUNCTION) \
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index d60758d..b9d97a5 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -63,9 +63,6 @@
if(${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER})
set(SPIRV_SKIP_TESTS ON CACHE BOOL "Controls whether SPIR-V tests are run" FORCE)
set(SPIRV_WERROR OFF CACHE BOOL OFF FORCE)
- if (${TINT_BUILD_SPIRV_TOOLS_FUZZER})
- set(SPIRV_BUILD_FUZZER ON CACHE BOOL "Controls whether spirv-fuzz is built" FORCE)
- endif()
endif()
message(STATUS "Dawn: using SPIRV-Tools at ${DAWN_SPIRV_TOOLS_DIR}")
@@ -103,7 +100,7 @@
add_subdirectory(${DAWN_ABSEIL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/abseil")
endif()
-if (NOT TARGET libprotobuf-mutator)
+if (DAWN_BUILD_PROTOBUF AND NOT TARGET libprotobuf-mutator)
message(STATUS "Dawn: using LPM at ${DAWN_LPM_DIR}")
include("libprotobuf-mutator/BUILD.cmake")
endif()