Skip to content

Commit

Permalink
Create a shared utils folder.
Browse files Browse the repository at this point in the history
This CL creates a `src/utils` folder and adds a `compiler.h` header. A
define is pulled out of the Dawn common compilers file and the tint
macros compiler file and added to the header.

The define is the same, just for `TINT_` or `DAWN_`. It will be
collapsed to a single define in a future CL.

Change-Id: Idb420cee2803a23353d3fa8b893db35fd7069206
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203694
Commit-Queue: dan sinclair <[email protected]>
Reviewed-by: James Price <[email protected]>
Reviewed-by: Corentin Wallez <[email protected]>
  • Loading branch information
dj2 authored and Dawn LUCI CQ committed Aug 28, 2024
1 parent b7b0463 commit d90557b
Show file tree
Hide file tree
Showing 348 changed files with 1,288 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ target_include_directories(dawn_public_config INTERFACE
# The internal config contains additional path but includes the dawn_public_config include paths
add_library(dawn_internal_config INTERFACE)
target_include_directories(dawn_internal_config INTERFACE
"${PROJECT_SOURCE_DIR}"
"${DAWN_SRC_DIR}"
"${DAWN_BUILD_GEN_DIR}/src"
)
Expand Down Expand Up @@ -420,6 +421,9 @@ add_subdirectory(third_party)
# BUILD_SHARED_LIBS=1, so always build it as static for now.
set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS 0)

add_subdirectory(src/utils)

# Only build Tint when we are not building under Emscripten.
if (NOT ${DAWN_ENABLE_EMSCRIPTEN})
add_subdirectory(src/tint)
Expand Down
1 change: 1 addition & 0 deletions src/dawn/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ if (is_win || is_linux || is_chromeos || is_mac || is_fuchsia || is_android ||
":dawn_gpu_info_gen",
":dawn_version_gen",
"${dawn_root}/src/dawn/partition_alloc:raw_ptr",
"${dawn_root}/src/utils:utils",
]

if (is_apple) {
Expand Down
1 change: 1 addition & 0 deletions src/dawn/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@ dawn_add_library(
PRIVATE_DEPENDS
absl::inlined_vector
dawn::partition_alloc
dawn_shared_utils
${conditional_private_depends}
)
21 changes: 2 additions & 19 deletions src/dawn/common/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef SRC_DAWN_COMMON_COMPILER_H_
#define SRC_DAWN_COMMON_COMPILER_H_

#include "src/utils/compiler.h"

// Defines macros for compiler-specific functionality

// DAWN_COMPILER_IS(CLANG|GCC|MSVC): Compiler detection
Expand Down Expand Up @@ -55,25 +57,6 @@
// code block as usage of undefined macro "function" will be blocked by the compiler.
#define DAWN_COMPILER_IS(X) (1 == DAWN_COMPILER_IS_##X)

// DAWN_HAS_ATTRIBUTE
//
// A wrapper around `__has_attribute`. This test whether its operand is recognized by the compiler.
#if defined(__has_attribute)
#define DAWN_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
#define DAWN_HAS_ATTRIBUTE(x) 0
#endif

// DAWN_HAS_CPP_ATTRIBUTE
//
// A wrapper around `__has_cpp_attribute`. This test whether its operand is recognized by the
// compiler.
#if defined(__has_cpp_attribute)
#define DAWN_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else
#define DAWN_HAS_CPP_ATTRIBUTE(x) 0
#endif

// DAWN_BUILTIN_UNREACHABLE()
//
// Hints the compiler that a code path is unreachable.
Expand Down
1 change: 1 addition & 0 deletions src/dawn/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ group("tests") {
":dawn_perf_tests",
":dawn_unittests",
"${dawn_root}/src/dawn/tests/benchmarks:dawn_benchmarks",
"${dawn_root}/src/utils",
]
}

Expand Down
2 changes: 2 additions & 0 deletions src/tint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ function(tint_target_add_external_dependencies TARGET KIND)
target_link_libraries(${TARGET} PRIVATE Threads::Threads)
elseif(${DEPENDENCY} STREQUAL "winsock")
target_link_libraries(${TARGET} PRIVATE ws2_32)
elseif(${DEPENDENCY} STREQUAL "src_utils")
target_link_libraries(${TARGET} PRIVATE dawn_shared_utils)
else()
message(FATAL_ERROR "unhandled external dependency ${DEPENDENCY}")
endif()
Expand Down
1 change: 1 addition & 0 deletions src/tint/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cc_library(
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"//src/utils",
] + select({
":tint_build_glsl_writer": [
"//src/tint/lang/glsl/writer",
Expand Down
4 changes: 4 additions & 0 deletions src/tint/api/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ tint_target_add_dependencies(tint_api lib
tint_utils_traits
)

tint_target_add_external_dependencies(tint_api lib
"src_utils"
)

if(TINT_BUILD_GLSL_WRITER)
tint_target_add_dependencies(tint_api lib
tint_lang_glsl_writer
Expand Down
2 changes: 2 additions & 0 deletions src/tint/api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -44,6 +45,7 @@ libtint_source_set("api") {
"tint.h",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}/api/common",
"${tint_src_dir}/lang/core",
"${tint_src_dir}/lang/core/constant",
Expand Down
2 changes: 2 additions & 0 deletions src/tint/api/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cc_library(
"//src/tint/utils/rtti",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"//src/utils",
],
copts = COPTS,
visibility = ["//visibility:public"],
Expand All @@ -82,6 +83,7 @@ cc_library(
"//src/tint/utils/text",
"//src/tint/utils/traits",
"@gtest",
"//src/utils",
],
copts = COPTS,
visibility = ["//visibility:public"],
Expand Down
5 changes: 5 additions & 0 deletions src/tint/api/common/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ tint_target_add_dependencies(tint_api_common lib
tint_utils_traits
)

tint_target_add_external_dependencies(tint_api_common lib
"src_utils"
)

################################################################################
# Target: tint_api_common_test
# Kind: test
Expand All @@ -84,4 +88,5 @@ tint_target_add_dependencies(tint_api_common_test test

tint_target_add_external_dependencies(tint_api_common_test test
"gtest"
"src_utils"
)
3 changes: 3 additions & 0 deletions src/tint/api/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -49,6 +50,7 @@ libtint_source_set("common") {
"override_id.h",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}/utils/containers",
"${tint_src_dir}/utils/diagnostic",
"${tint_src_dir}/utils/ice",
Expand All @@ -69,6 +71,7 @@ if (tint_build_unittests) {
"override_id_test.cc",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}:gmock_and_gtest",
"${tint_src_dir}/api/common",
"${tint_src_dir}/utils/containers",
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
2 changes: 2 additions & 0 deletions src/tint/cmd/bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ cc_library(
"//src/tint/utils/text",
"//src/tint/utils/traits",
"@benchmark",
"//src/utils",
] + select({
":tint_build_wgsl_reader": [
"//src/tint/lang/wgsl/reader",
Expand Down Expand Up @@ -108,6 +109,7 @@ cc_binary(
"//src/tint/utils/text",
"//src/tint/utils/traits",
"@benchmark",
"//src/utils",
] + select({
":tint_build_glsl_writer_and_tint_build_wgsl_reader": [
"//src/tint/lang/glsl/writer:bench",
Expand Down
2 changes: 2 additions & 0 deletions src/tint/cmd/bench/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd

tint_target_add_external_dependencies(tint_cmd_bench_bench_cmd bench_cmd
"google-benchmark"
"src_utils"
)

if(TINT_BUILD_GLSL_WRITER AND TINT_BUILD_WGSL_READER)
Expand Down Expand Up @@ -155,6 +156,7 @@ tint_target_add_dependencies(tint_cmd_bench_bench bench

tint_target_add_external_dependencies(tint_cmd_bench_bench bench
"google-benchmark"
"src_utils"
)

if(TINT_BUILD_WGSL_READER)
Expand Down
3 changes: 3 additions & 0 deletions src/tint/cmd/bench/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -49,6 +50,7 @@ if (tint_build_benchmarks) {
"bench.h",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}:google_benchmark",
"${tint_src_dir}/api/common",
"${tint_src_dir}/lang/core",
Expand Down Expand Up @@ -89,6 +91,7 @@ if (tint_build_benchmarks) {
output_name = "tint_benchmark"
sources = [ "main_bench.cc" ]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}:google_benchmark",
"${tint_src_dir}/lang/core",
"${tint_src_dir}/lang/core:bench",
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cc_library(
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"//src/utils",
] + select({
":tint_build_spv_reader": [
"//src/tint/lang/spirv/reader",
Expand Down
4 changes: 4 additions & 0 deletions src/tint/cmd/common/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ tint_target_add_dependencies(tint_cmd_common lib
tint_utils_traits
)

tint_target_add_external_dependencies(tint_cmd_common lib
"src_utils"
)

if(TINT_BUILD_SPV_READER)
tint_target_add_dependencies(tint_cmd_common lib
tint_lang_spirv_reader
Expand Down
2 changes: 2 additions & 0 deletions src/tint/cmd/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -44,6 +45,7 @@ libtint_source_set("common") {
"helper.h",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}/api/common",
"${tint_src_dir}/lang/core",
"${tint_src_dir}/lang/core/constant",
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/fuzz/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
2 changes: 2 additions & 0 deletions src/tint/cmd/fuzz/ir/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd

tint_target_add_external_dependencies(tint_cmd_fuzz_ir_fuzz_cmd fuzz_cmd
"libprotobuf-mutator"
"src_utils"
)

if(TINT_BUILD_GLSL_WRITER)
Expand Down Expand Up @@ -172,6 +173,7 @@ tint_target_add_dependencies(tint_cmd_fuzz_ir_fuzz fuzz
)

tint_target_add_external_dependencies(tint_cmd_fuzz_ir_fuzz fuzz
"src_utils"
"thread"
)

Expand Down
3 changes: 3 additions & 0 deletions src/tint/cmd/fuzz/ir/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -44,6 +45,7 @@ tint_fuzz_source_set("fuzz") {
"fuzz.h",
]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}:thread",
"${tint_src_dir}/api/common",
"${tint_src_dir}/lang/core",
Expand Down Expand Up @@ -86,6 +88,7 @@ if (tint_build_ir_binary && tint_build_ir_fuzzer &&
output_name = "tint_ir_fuzzer"
sources = [ "main_fuzz.cc" ]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_lpm_dir}:libprotobuf-mutator",
"${tint_src_dir}/api/common",
"${tint_src_dir}/cmd/fuzz/ir:fuzz",
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/fuzz/ir/as/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cc_binary(
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"//src/utils",
] + select({
":tint_build_ir_binary": [
"//src/tint/lang/core/ir/binary",
Expand Down
4 changes: 4 additions & 0 deletions src/tint/cmd/fuzz/ir/as/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ tint_target_add_dependencies(tint_cmd_fuzz_ir_as_cmd cmd
tint_utils_traits
)

tint_target_add_external_dependencies(tint_cmd_fuzz_ir_as_cmd cmd
"src_utils"
)

if(TINT_BUILD_IR_BINARY)
tint_target_add_dependencies(tint_cmd_fuzz_ir_as_cmd cmd
tint_lang_core_ir_binary
Expand Down
2 changes: 2 additions & 0 deletions src/tint/cmd/fuzz/ir/as/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -42,6 +43,7 @@ if (tint_build_ir_binary && tint_build_wgsl_reader && tint_build_ir_fuzzer) {
output_name = "ir_fuzz_as"
sources = [ "main.cc" ]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}/api",
"${tint_src_dir}/api/common",
"${tint_src_dir}/cmd/common",
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/fuzz/ir/dis/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cc_binary(
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"//src/utils",
] + select({
":tint_build_ir_binary": [
"//src/tint/lang/core/ir/binary",
Expand Down
4 changes: 4 additions & 0 deletions src/tint/cmd/fuzz/ir/dis/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ tint_target_add_dependencies(tint_cmd_fuzz_ir_dis_cmd cmd
tint_utils_traits
)

tint_target_add_external_dependencies(tint_cmd_fuzz_ir_dis_cmd cmd
"src_utils"
)

if(TINT_BUILD_IR_BINARY)
tint_target_add_dependencies(tint_cmd_fuzz_ir_dis_cmd cmd
tint_lang_core_ir_binary
Expand Down
2 changes: 2 additions & 0 deletions src/tint/cmd/fuzz/ir/dis/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Do not modify this file directly
################################################################################

import("../../../../../../scripts/dawn_overrides_with_defaults.gni")
import("../../../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")
Expand All @@ -43,6 +44,7 @@ if (tint_build_ir_binary && tint_build_ir_fuzzer && tint_build_wgsl_writer &&
output_name = "ir_fuzz_dis"
sources = [ "main.cc" ]
deps = [
"${dawn_root}/src/utils:utils",
"${tint_src_dir}/api",
"${tint_src_dir}/api/common",
"${tint_src_dir}/cmd/common",
Expand Down
Loading

0 comments on commit d90557b

Please sign in to comment.