dawn-cmake/src/BUILD.gn

710 lines
20 KiB
Plaintext

# Copyright 2021 The Tint Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build_overrides/build.gni")
import("../tint_overrides_with_defaults.gni")
###############################################################################
# Common - Configs, etc. shared across targets
###############################################################################
config("tint_common_config") {
include_dirs = [
"${target_gen_dir}",
"${tint_root_dir}/",
"${tint_spirv_headers_dir}/include",
"${tint_spirv_tools_dir}/",
"${tint_spirv_tools_dir}/include",
]
}
config("tint_public_config") {
defines = []
if (tint_build_spv_reader) {
defines += [ "TINT_BUILD_SPV_READER=1" ]
} else {
defines += [ "TINT_BUILD_SPV_READER=0" ]
}
if (tint_build_spv_writer) {
defines += [ "TINT_BUILD_SPV_WRITER=1" ]
} else {
defines += [ "TINT_BUILD_SPV_WRITER=0" ]
}
if (tint_build_wgsl_reader) {
defines += [ "TINT_BUILD_WGSL_READER=1" ]
} else {
defines += [ "TINT_BUILD_WGSL_READER=0" ]
}
if (tint_build_wgsl_writer) {
defines += [ "TINT_BUILD_WGSL_WRITER=1" ]
} else {
defines += [ "TINT_BUILD_WGSL_WRITER=0" ]
}
if (tint_build_msl_writer) {
defines += [ "TINT_BUILD_MSL_WRITER=1" ]
} else {
defines += [ "TINT_BUILD_MSL_WRITER=0" ]
}
if (tint_build_hlsl_writer) {
defines += [ "TINT_BUILD_HLSL_WRITER=1" ]
} else {
defines += [ "TINT_BUILD_HLSL_WRITER=0" ]
}
include_dirs = [
"${tint_root_dir}/",
"${tint_root_dir}/include/",
"${tint_spirv_headers_dir}/include",
]
}
config("tint_config") {
include_dirs = []
if (tint_build_spv_reader || tint_build_spv_writer) {
include_dirs += [ "${tint_spirv_tools_dir}/include/" ]
}
}
###############################################################################
# Generated - Generated source files
###############################################################################
# These are copies of rules from SPIRV-Tools with the names tweaked to be Tint
# specific. They are needed here because referencing generated files in sibling
# packages is difficult/impossible in Chromium. Parts of Tint's SPIRV handling
# code depend on internal parts of SPIRV-Tools. This causes issues because when
# Tint references the internal headers, since it causes a dependency on these
# generated files, but they are not visible in the context building Tint. Thus
# Tint generates its own copy of the generated files. Since they come from the
# same source of truth, they should not vary.
template("tint_core_tables") {
assert(defined(invoker.version), "Need version in $target_name generation.")
action("tint_core_tables_" + target_name) {
script = "${tint_spirv_tools_dir}/utils/generate_grammar_tables.py"
version = invoker.version
core_json_file = "${tint_spirv_headers_dir}/include/spirv/$version/spirv.core.grammar.json"
core_insts_file = "${target_gen_dir}/core.insts-$version.inc"
operand_kinds_file = "${target_gen_dir}/operand.kinds-$version.inc"
debuginfo_insts_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.debuginfo.grammar.json"
cldebuginfo100_insts_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"
sources = [
cldebuginfo100_insts_file,
core_json_file,
debuginfo_insts_file,
]
outputs = [
core_insts_file,
operand_kinds_file,
]
args = [
"--spirv-core-grammar",
rebase_path(core_json_file, root_build_dir),
"--core-insts-output",
rebase_path(core_insts_file, root_build_dir),
"--extinst-debuginfo-grammar",
rebase_path(debuginfo_insts_file, root_build_dir),
"--extinst-cldebuginfo100-grammar",
rebase_path(cldebuginfo100_insts_file, root_build_dir),
"--operand-kinds-output",
rebase_path(operand_kinds_file, root_build_dir),
]
}
}
template("tint_core_enums") {
assert(defined(invoker.version), "Need version in $target_name generation.")
action("tint_core_enums_" + target_name) {
script = "${tint_spirv_tools_dir}/utils/generate_grammar_tables.py"
version = invoker.version
core_json_file = "${tint_spirv_headers_dir}/include/spirv/$version/spirv.core.grammar.json"
debuginfo_insts_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.debuginfo.grammar.json"
cldebuginfo100_insts_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"
extension_enum_file = "${target_gen_dir}/extension_enum.inc"
extension_map_file = "${target_gen_dir}/enum_string_mapping.inc"
args = [
"--spirv-core-grammar",
rebase_path(core_json_file, root_build_dir),
"--extinst-debuginfo-grammar",
rebase_path(debuginfo_insts_file, root_build_dir),
"--extinst-cldebuginfo100-grammar",
rebase_path(cldebuginfo100_insts_file, root_build_dir),
"--extension-enum-output",
rebase_path(extension_enum_file, root_build_dir),
"--enum-string-mapping-output",
rebase_path(extension_map_file, root_build_dir),
]
inputs = [
core_json_file,
debuginfo_insts_file,
cldebuginfo100_insts_file,
]
outputs = [
extension_enum_file,
extension_map_file,
]
}
}
template("tint_language_header") {
assert(defined(invoker.name), "Need name in $target_name generation.")
action("tint_language_header_" + target_name) {
script = "${tint_spirv_tools_dir}/utils/generate_language_headers.py"
name = invoker.name
extinst_output_path = "${target_gen_dir}/${name}.h"
args = [
"--extinst-grammar",
rebase_path(invoker.grammar_file, root_build_dir),
"--extinst-output-path",
rebase_path(extinst_output_path, root_build_dir),
]
inputs = [ invoker.grammar_file ]
outputs = [ "${extinst_output_path}" ]
}
}
tint_core_tables("unified1") {
version = "unified1"
}
tint_core_enums("unified1") {
version = "unified1"
}
tint_language_header("debuginfo") {
name = "DebugInfo"
grammar_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.debuginfo.grammar.json"
}
tint_language_header("cldebuginfo100") {
name = "OpenCLDebugInfo100"
grammar_file = "${tint_spirv_headers_dir}/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"
}
###############################################################################
# Library - Tint core and optional modules of libtint
###############################################################################
# libtint source sets are divided into a non-optional core in :libtint_core_src
# and optional :libtint_*_src subsets, because ninja does not like having
# multiple source files with the same name, like function.cc, in the same
# source set
# target.
#
# Targets that want to use tint as a library should depend on ":libtint" and
# use the build flags to control what is included, instead of trying to specify
# the subsets that they want.
template("libtint_source_set") {
source_set(target_name) {
forward_variables_from(invoker, "*", [ "configs" ])
if (!defined(invoker.deps)) {
deps = []
}
deps += [
":tint_core_enums_unified1",
":tint_core_tables_unified1",
":tint_language_header_cldebuginfo100",
":tint_language_header_debuginfo",
"${tint_spirv_headers_dir}:spv_headers",
"${tint_spirv_tools_dir}:spvtools_headers",
]
if (defined(invoker.configs)) {
configs += invoker.configs
}
configs += [ ":tint_common_config" ]
if (build_with_chromium) {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
if (!defined(invoker.public_configs)) {
public_configs = []
}
public_configs += [ ":tint_public_config" ]
}
}
libtint_source_set("libtint_core_all_src") {
sources = [
"ast/access_control.cc",
"ast/access_control.h",
"ast/access_decoration.cc",
"ast/access_decoration.h",
"ast/alias.cc",
"ast/alias.h",
"ast/array.cc",
"ast/array.h",
"ast/array_accessor_expression.cc",
"ast/array_accessor_expression.h",
"ast/assignment_statement.cc",
"ast/assignment_statement.h",
"ast/ast_type.cc", # TODO(bclayton) - rename to type.cc
"ast/binary_expression.cc",
"ast/binary_expression.h",
"ast/binding_decoration.cc",
"ast/binding_decoration.h",
"ast/bitcast_expression.cc",
"ast/bitcast_expression.h",
"ast/block_statement.cc",
"ast/block_statement.h",
"ast/bool.cc",
"ast/bool.h",
"ast/bool_literal.cc",
"ast/bool_literal.h",
"ast/break_statement.cc",
"ast/break_statement.h",
"ast/builtin.cc",
"ast/builtin.h",
"ast/builtin_decoration.cc",
"ast/builtin_decoration.h",
"ast/call_expression.cc",
"ast/call_expression.h",
"ast/call_statement.cc",
"ast/call_statement.h",
"ast/case_statement.cc",
"ast/case_statement.h",
"ast/constant_id_decoration.cc",
"ast/constant_id_decoration.h",
"ast/constructor_expression.cc",
"ast/constructor_expression.h",
"ast/continue_statement.cc",
"ast/continue_statement.h",
"ast/decoration.cc",
"ast/decoration.h",
"ast/depth_texture.cc",
"ast/depth_texture.h",
"ast/discard_statement.cc",
"ast/discard_statement.h",
"ast/else_statement.cc",
"ast/else_statement.h",
"ast/expression.cc",
"ast/expression.h",
"ast/f32.cc",
"ast/f32.h",
"ast/fallthrough_statement.cc",
"ast/fallthrough_statement.h",
"ast/float_literal.cc",
"ast/float_literal.h",
"ast/function.cc",
"ast/function.h",
"ast/group_decoration.cc",
"ast/group_decoration.h",
"ast/i32.cc",
"ast/i32.h",
"ast/identifier_expression.cc",
"ast/identifier_expression.h",
"ast/if_statement.cc",
"ast/if_statement.h",
"ast/int_literal.cc",
"ast/int_literal.h",
"ast/internal_decoration.cc",
"ast/internal_decoration.h",
"ast/literal.cc",
"ast/literal.h",
"ast/location_decoration.cc",
"ast/location_decoration.h",
"ast/loop_statement.cc",
"ast/loop_statement.h",
"ast/matrix.cc",
"ast/matrix.h",
"ast/member_accessor_expression.cc",
"ast/member_accessor_expression.h",
"ast/module.cc",
"ast/module.h",
"ast/multisampled_texture.cc",
"ast/multisampled_texture.h",
"ast/node.cc",
"ast/node.h",
"ast/pipeline_stage.cc",
"ast/pipeline_stage.h",
"ast/pointer.cc",
"ast/pointer.h",
"ast/return_statement.cc",
"ast/return_statement.h",
"ast/sampled_texture.cc",
"ast/sampled_texture.h",
"ast/sampler.cc",
"ast/sampler.h",
"ast/scalar_constructor_expression.cc",
"ast/scalar_constructor_expression.h",
"ast/sint_literal.cc",
"ast/sint_literal.h",
"ast/stage_decoration.cc",
"ast/stage_decoration.h",
"ast/statement.cc",
"ast/statement.h",
"ast/storage_class.cc",
"ast/storage_class.h",
"ast/storage_texture.cc",
"ast/storage_texture.h",
"ast/stride_decoration.cc",
"ast/stride_decoration.h",
"ast/struct.cc",
"ast/struct.h",
"ast/struct_block_decoration.cc",
"ast/struct_block_decoration.h",
"ast/struct_member.cc",
"ast/struct_member.h",
"ast/struct_member_align_decoration.cc",
"ast/struct_member_align_decoration.h",
"ast/struct_member_offset_decoration.cc",
"ast/struct_member_offset_decoration.h",
"ast/struct_member_size_decoration.cc",
"ast/struct_member_size_decoration.h",
"ast/switch_statement.cc",
"ast/switch_statement.h",
"ast/texture.cc",
"ast/texture.h",
"ast/type.h",
"ast/type_constructor_expression.cc",
"ast/type_constructor_expression.h",
"ast/u32.cc",
"ast/u32.h",
"ast/uint_literal.cc",
"ast/uint_literal.h",
"ast/unary_op.cc",
"ast/unary_op.h",
"ast/unary_op_expression.cc",
"ast/unary_op_expression.h",
"ast/variable.cc",
"ast/variable.h",
"ast/variable_decl_statement.cc",
"ast/variable_decl_statement.h",
"ast/vector.cc",
"ast/vector.h",
"ast/void.cc",
"ast/void.h",
"ast/workgroup_decoration.cc",
"ast/workgroup_decoration.h",
"block_allocator.h",
"castable.cc",
"castable.h",
"clone_context.cc",
"clone_context.h",
"debug.cc",
"debug.h",
"demangler.cc",
"demangler.h",
"diagnostic/diagnostic.cc",
"diagnostic/diagnostic.h",
"diagnostic/formatter.cc",
"diagnostic/formatter.h",
"diagnostic/printer.cc",
"diagnostic/printer.h",
"inspector/entry_point.cc",
"inspector/entry_point.h",
"inspector/inspector.cc",
"inspector/inspector.h",
"inspector/scalar.cc",
"inspector/scalar.h",
"intrinsic_table.cc",
"intrinsic_table.h",
"program.cc",
"program.h",
"program_builder.cc",
"program_builder.h",
"program_id.cc",
"program_id.h",
"reader/reader.cc",
"reader/reader.h",
"resolver/resolver.cc",
"resolver/resolver.h",
"scope_stack.h",
"sem/access_control_type.cc",
"sem/access_control_type.h",
"sem/alias_type.cc",
"sem/alias_type.h",
"sem/array.h",
"sem/array_type.cc",
"sem/array_type.h",
"sem/bool_type.cc",
"sem/bool_type.h",
"sem/call.h",
"sem/call_target.h",
"sem/depth_texture_type.cc",
"sem/depth_texture_type.h",
"sem/expression.h",
"sem/external_texture_type.cc",
"sem/external_texture_type.h",
"sem/f32_type.cc",
"sem/f32_type.h",
"sem/i32_type.cc",
"sem/i32_type.h",
"sem/info.h",
"sem/intrinsic.h",
"sem/matrix_type.cc",
"sem/matrix_type.h",
"sem/multisampled_texture_type.cc",
"sem/multisampled_texture_type.h",
"sem/node.h",
"sem/pointer_type.cc",
"sem/pointer_type.h",
"sem/sampled_texture_type.cc",
"sem/sampled_texture_type.h",
"sem/sampler_type.cc",
"sem/sampler_type.h",
"sem/storage_texture_type.cc",
"sem/storage_texture_type.h",
"sem/struct_type.cc",
"sem/struct_type.h",
"sem/texture_type.cc",
"sem/texture_type.h",
"sem/type.cc",
"sem/type.h",
"sem/type_manager.cc",
"sem/type_manager.h",
"sem/type_mappings.h",
"sem/u32_type.cc",
"sem/u32_type.h",
"sem/vector_type.cc",
"sem/vector_type.h",
"sem/void_type.cc",
"sem/void_type.h",
"source.cc",
"source.h",
"symbol.cc",
"symbol.h",
"symbol_table.cc",
"symbol_table.h",
"traits.h",
"typepair.h",
"transform/binding_point.h",
"transform/binding_remapper.cc",
"transform/binding_remapper.h",
"transform/bound_array_accessors.cc",
"transform/bound_array_accessors.h",
"transform/calculate_array_length.cc",
"transform/calculate_array_length.h",
"transform/canonicalize_entry_point_io.cc",
"transform/canonicalize_entry_point_io.h",
"transform/decompose_storage_access.cc",
"transform/decompose_storage_access.h",
"transform/emit_vertex_point_size.cc",
"transform/emit_vertex_point_size.h",
"transform/first_index_offset.cc",
"transform/first_index_offset.h",
"transform/manager.cc",
"transform/manager.h",
"transform/renamer.cc",
"transform/renamer.h",
"transform/transform.cc",
"transform/transform.h",
"transform/vertex_pulling.cc",
"transform/vertex_pulling.h",
"utils/get_or_create.h",
"utils/hash.h",
"utils/math.h",
"utils/unique_vector.h",
"writer/append_vector.cc",
"writer/append_vector.h",
"writer/float_to_string.cc",
"writer/float_to_string.h",
"writer/text.cc",
"writer/text.h",
"writer/text_generator.cc",
"writer/text_generator.h",
"writer/writer.cc",
"writer/writer.h",
]
if (is_linux) {
sources += [ "diagnostic/printer_linux.cc" ]
} else if (is_win) {
sources += [ "diagnostic/printer_windows.cc" ]
} else {
sources += [ "diagnostic/printer_other.cc" ]
}
}
libtint_source_set("libtint_sem_src") {
sources = [
"sem/array.cc",
"sem/call.cc",
"sem/call_target.cc",
"sem/expression.cc",
"sem/function.cc",
"sem/info.cc",
"sem/intrinsic.cc",
"sem/member_accessor_expression.cc",
"sem/node.cc",
"sem/statement.cc",
"sem/struct.cc",
"sem/variable.cc",
]
public_deps = [ ":libtint_core_all_src" ]
}
libtint_source_set("libtint_core_src") {
public_deps = [
":libtint_core_all_src",
":libtint_sem_src",
]
}
libtint_source_set("libtint_spv_reader_src") {
sources = [
"reader/spirv/construct.cc",
"reader/spirv/construct.h",
"reader/spirv/entry_point_info.h",
"reader/spirv/enum_converter.cc",
"reader/spirv/enum_converter.h",
"reader/spirv/fail_stream.h",
"reader/spirv/function.cc",
"reader/spirv/function.h",
"reader/spirv/namer.cc",
"reader/spirv/namer.h",
"reader/spirv/parser.cc",
"reader/spirv/parser.h",
"reader/spirv/parser_impl.cc",
"reader/spirv/parser_impl.h",
"reader/spirv/usage.cc",
"reader/spirv/usage.h",
]
public_deps = [
":libtint_core_src",
"${tint_spirv_tools_dir}/:spvtools_opt",
]
}
libtint_source_set("libtint_spv_writer_src") {
sources = [
"transform/spirv.cc",
"transform/spirv.h",
"writer/spirv/binary_writer.cc",
"writer/spirv/binary_writer.h",
"writer/spirv/builder.cc",
"writer/spirv/builder.h",
"writer/spirv/function.cc",
"writer/spirv/function.h",
"writer/spirv/generator.cc",
"writer/spirv/generator.h",
"writer/spirv/instruction.cc",
"writer/spirv/instruction.h",
"writer/spirv/operand.cc",
"writer/spirv/operand.h",
"writer/spirv/scalar_constant.h",
]
public_deps = [ ":libtint_core_src" ]
}
libtint_source_set("libtint_wgsl_reader_src") {
sources = [
"reader/wgsl/lexer.cc",
"reader/wgsl/lexer.h",
"reader/wgsl/parser.cc",
"reader/wgsl/parser.h",
"reader/wgsl/parser_impl.cc",
"reader/wgsl/parser_impl.h",
"reader/wgsl/parser_impl_detail.h",
"reader/wgsl/token.cc",
"reader/wgsl/token.h",
]
public_deps = [ ":libtint_core_src" ]
}
libtint_source_set("libtint_wgsl_writer_src") {
sources = [
"writer/wgsl/generator.cc",
"writer/wgsl/generator.h",
"writer/wgsl/generator_impl.cc",
"writer/wgsl/generator_impl.h",
]
public_deps = [ ":libtint_core_src" ]
}
libtint_source_set("libtint_msl_writer_src") {
sources = [
"transform/msl.cc",
"transform/msl.h",
"writer/msl/generator.cc",
"writer/msl/generator.h",
"writer/msl/generator_impl.cc",
"writer/msl/generator_impl.h",
]
public_deps = [ ":libtint_core_src" ]
}
libtint_source_set("libtint_hlsl_writer_src") {
sources = [
"transform/hlsl.cc",
"transform/hlsl.h",
"writer/hlsl/generator.cc",
"writer/hlsl/generator.h",
"writer/hlsl/generator_impl.cc",
"writer/hlsl/generator_impl.h",
]
public_deps = [ ":libtint_core_src" ]
}
source_set("libtint") {
public_deps = [ ":libtint_core_src" ]
if (tint_build_spv_reader) {
public_deps += [ ":libtint_spv_reader_src" ]
}
if (tint_build_spv_writer) {
public_deps += [ ":libtint_spv_writer_src" ]
}
if (tint_build_wgsl_reader) {
public_deps += [ ":libtint_wgsl_reader_src" ]
}
if (tint_build_wgsl_writer) {
public_deps += [ ":libtint_wgsl_writer_src" ]
}
if (tint_build_msl_writer) {
public_deps += [ ":libtint_msl_writer_src" ]
}
if (tint_build_hlsl_writer) {
public_deps += [ ":libtint_hlsl_writer_src" ]
}
configs += [ ":tint_common_config" ]
public_configs = [ ":tint_public_config" ]
if (build_with_chromium) {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}