[tint] Move tint.cc to api/tint.cc
This new directory will hold the public tint API.
Remove all "tint/tint.h" includes from Tint code. Use the specific
includes required. Follows the principles of IWYU, and helps the new
build generator to properly track what's in use.
Change-Id: I2875c3c4684a41ec3d8de0e931ad93d05a5a7700
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/146383
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/include/tint/tint.h b/include/tint/tint.h
index d6e54e8..046a685 100644
--- a/include/tint/tint.h
+++ b/include/tint/tint.h
@@ -21,6 +21,7 @@
// TODO(tint:88): When implementing support for an install target, all of these
// headers will need to be moved to include/tint/.
+#include "src/tint/api/tint.h"
#include "src/tint/lang/core/type/manager.h"
#include "src/tint/lang/wgsl/ast/transform/first_index_offset.h"
#include "src/tint/lang/wgsl/ast/transform/manager.h"
@@ -65,16 +66,6 @@
#include "src/tint/lang/glsl/writer/writer.h"
#endif // TINT_BUILD_GLSL_WRITER
-namespace tint {
-
-/// Initialize initializes the Tint library. Call before using the Tint API.
-void Initialize();
-
-/// Shutdown uninitializes the Tint library. Call after using the Tint API.
-void Shutdown();
-
-} // namespace tint
-
#undef CURRENTLY_IN_TINT_PUBLIC_HEADER
#endif // INCLUDE_TINT_TINT_H_
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index 30e4ddb..7abe92e 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -332,10 +332,6 @@
]
}
-libtint_source_set("libtint_initializer_src") {
- sources = [ "tint.cc" ]
-}
-
libtint_source_set("libtint_inspector_src") {
sources = [
"lang/wgsl/inspector/entry_point.cc",
@@ -1377,13 +1373,17 @@
}
source_set("libtint") {
+ sources = [
+ "api/tint.cc",
+ "api/tint.h",
+ ]
+
public_deps = [
":libtint_ast_src",
":libtint_ast_transform_base_src",
":libtint_ast_transform_src",
":libtint_builtins_src",
":libtint_constant_src",
- ":libtint_initializer_src",
":libtint_inspector_src",
":libtint_program_src",
":libtint_sem_src",
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index b36d852..79c46ad 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -80,6 +80,8 @@
list(APPEND TINT_LIB_SRCS
../../include/tint/tint.h
+ api/tint.cc
+ api/tint.h
lang/wgsl/ast/clone_context.cc
lang/wgsl/ast/clone_context.h
lang/core/binary_op.cc
@@ -536,7 +538,6 @@
lang/wgsl/resolver/uniformity.h
lang/wgsl/resolver/validator.cc
lang/wgsl/resolver/validator.h
- tint.cc
utils/cli/cli.cc
utils/cli/cli.h
utils/containers/bitset.h
diff --git a/src/tint/api/tint.cc b/src/tint/api/tint.cc
new file mode 100644
index 0000000..21f90ac
--- /dev/null
+++ b/src/tint/api/tint.cc
@@ -0,0 +1,70 @@
+// Copyright 2023 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.
+
+#include "src/tint/api/tint.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// The following includes are used by './tools/run gen' to add an implicit
+// dependency from 'tint/api' to the libraries used to make up the Tint API.
+////////////////////////////////////////////////////////////////////////////////
+#if TINT_BUILD_GLSL_WRITER
+#include "src/tint/lang/glsl/writer/writer.h" // nogncheck
+#endif
+
+#if TINT_BUILD_HLSL_WRITER
+#include "src/tint/lang/hlsl/writer/writer.h" // nogncheck
+#endif
+
+#if TINT_BUILD_MSL_WRITER
+#include "src/tint/lang/msl/writer/writer.h" // nogncheck
+#endif
+
+#if TINT_BUILD_SPV_READER
+#include "src/tint/lang/spirv/reader/reader.h" // nogncheck
+#endif
+
+#if TINT_BUILD_SPV_WRITER
+#include "src/tint/lang/spirv/writer/writer.h" // nogncheck
+#endif
+
+#if TINT_BUILD_WGSL_READER
+#include "src/tint/lang/wgsl/reader/reader.h" // nogncheck
+#endif
+
+#if TINT_BUILD_WGSL_WRITER
+#include "src/tint/lang/wgsl/writer/writer.h" // nogncheck
+#endif
+
+namespace tint {
+
+/// Initialize initializes the Tint library. Call before using the Tint API.
+void Initialize() {
+#if TINT_BUILD_WGSL_WRITER
+ // Register the Program printer. This is used for debugging purposes.
+ tint::Program::printer = [](const tint::Program* program) {
+ auto result = wgsl::writer::Generate(program, {});
+ if (!result) {
+ return "error: " + result.Failure();
+ }
+ return result->wgsl;
+ };
+#endif
+}
+
+/// Shutdown uninitializes the Tint library. Call after using the Tint API.
+void Shutdown() {
+ // Currently no-op, but may release tint resources in the future.
+}
+
+} // namespace tint
diff --git a/src/tint/api/tint.h b/src/tint/api/tint.h
new file mode 100644
index 0000000..e7e600e
--- /dev/null
+++ b/src/tint/api/tint.h
@@ -0,0 +1,28 @@
+// Copyright 2023 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.
+
+#ifndef SRC_TINT_API_TINT_H_
+#define SRC_TINT_API_TINT_H_
+
+namespace tint {
+
+/// Initialize initializes the Tint library. Call before using the Tint API.
+void Initialize();
+
+/// Shutdown uninitializes the Tint library. Call after using the Tint API.
+void Shutdown();
+
+} // namespace tint
+
+#endif // SRC_TINT_API_TINT_H_
diff --git a/src/tint/cmd/common/generate_external_texture_bindings.h b/src/tint/cmd/common/generate_external_texture_bindings.h
index 6a355f2..eee5ae9 100644
--- a/src/tint/cmd/common/generate_external_texture_bindings.h
+++ b/src/tint/cmd/common/generate_external_texture_bindings.h
@@ -16,7 +16,11 @@
#define SRC_TINT_CMD_COMMON_GENERATE_EXTERNAL_TEXTURE_BINDINGS_H_
#include "tint/external_texture_options.h"
-#include "tint/tint.h"
+
+// Forward declarations
+namespace tint {
+class Program;
+}
namespace tint::cmd {
diff --git a/src/tint/cmd/common/helper.cc b/src/tint/cmd/common/helper.cc
index aac52b5..564246f 100644
--- a/src/tint/cmd/common/helper.cc
+++ b/src/tint/cmd/common/helper.cc
@@ -20,6 +20,15 @@
#if TINT_BUILD_SPV_READER
#include "spirv-tools/libspirv.hpp"
+#include "src/tint/lang/spirv/reader/reader.h"
+#endif
+
+#if TINT_BUILD_WGSL_WRITER
+#include "src/tint/lang/wgsl/writer/writer.h"
+#endif
+
+#if TINT_BUILD_WGSL_READER
+#include "src/tint/lang/wgsl/reader/reader.h"
#endif
#include "src/tint/utils/diagnostic/formatter.h"
diff --git a/src/tint/cmd/common/helper.h b/src/tint/cmd/common/helper.h
index 931d13a..9b0ed81 100644
--- a/src/tint/cmd/common/helper.h
+++ b/src/tint/cmd/common/helper.h
@@ -20,7 +20,18 @@
#include <string>
#include <vector>
-#include "tint/tint.h"
+#include "src/tint/lang/wgsl/inspector/inspector.h"
+#include "src/tint/utils/diagnostic/source.h"
+
+#if TINT_BUILD_SPV_READER
+#include "src/tint/lang/spirv/reader/common/options.h"
+#endif
+
+// Forward declarations
+namespace tint {
+class Program;
+class InternalCompilerError;
+} // namespace tint
namespace tint::cmd {
diff --git a/src/tint/cmd/loopy/main.cc b/src/tint/cmd/loopy/main.cc
index 0dd9eeb..b6b5eca 100644
--- a/src/tint/cmd/loopy/main.cc
+++ b/src/tint/cmd/loopy/main.cc
@@ -14,15 +14,44 @@
#include <iostream>
+#include "src/tint/api/tint.h"
#include "src/tint/cmd/common/generate_external_texture_bindings.h"
#include "src/tint/cmd/common/helper.h"
-#include "tint/tint.h"
#if TINT_BUILD_IR
#include "src/tint/lang/core/ir/module.h"
#include "src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.h"
#endif // TINT_BUILD_IR
+#if TINT_BUILD_GLSL_WRITER
+#include "src/tint/lang/glsl/writer/writer.h"
+#endif // TINT_BUILD_GLSL_WRITER
+
+#if TINT_BUILD_HLSL_WRITER
+#include "src/tint/lang/hlsl/writer/writer.h"
+#endif // TINT_BUILD_HLSL_WRITER
+
+#if TINT_BUILD_MSL_WRITER
+#include "src/tint/lang/msl/writer/writer.h"
+#endif // TINT_BUILD_MSL_WRITER
+
+#if TINT_BUILD_SPV_READER
+#include "src/tint/lang/spirv/reader/reader.h"
+#endif // TINT_BUILD_SPV_READER
+
+#if TINT_BUILD_SPV_WRITER
+#include "src/tint/lang/spirv/writer/writer.h"
+#endif // TINT_BUILD_SPV_WRITER
+
+#if TINT_BUILD_WGSL_READER
+#include "src/tint/lang/wgsl/reader/reader.h"
+#endif // TINT_BUILD_WGSL_READER
+
+#if TINT_BUILD_WGSL_WRITER
+#include "src/tint/lang/wgsl/helpers/flatten_bindings.h"
+#include "src/tint/lang/wgsl/writer/writer.h"
+#endif // TINT_BUILD_WGSL_WRITER
+
namespace {
enum class Format {
diff --git a/src/tint/cmd/test/main_test.cc b/src/tint/cmd/test/main_test.cc
index 4f7ae8d..d00379d 100644
--- a/src/tint/cmd/test/main_test.cc
+++ b/src/tint/cmd/test/main_test.cc
@@ -13,7 +13,9 @@
// limitations under the License.
#include "gmock/gmock.h"
-#include "tint/tint.h"
+
+#include "src/tint/api/tint.h"
+#include "src/tint/utils/ice/ice.h"
namespace {
diff --git a/src/tint/cmd/tint/main.cc b/src/tint/cmd/tint/main.cc
index 23a7e3f..870b885 100644
--- a/src/tint/cmd/tint/main.cc
+++ b/src/tint/cmd/tint/main.cc
@@ -33,11 +33,18 @@
#include "spirv-tools/libspirv.hpp"
#endif // TINT_BUILD_SPV_READER || TINT_BUILD_SPV_WRITER
+#include "src/tint/api/tint.h"
#include "src/tint/cmd/common/generate_external_texture_bindings.h"
#include "src/tint/cmd/common/helper.h"
#include "src/tint/lang/hlsl/validate/val.h"
#include "src/tint/lang/msl/validate/val.h"
#include "src/tint/lang/wgsl/ast/module.h"
+#include "src/tint/lang/wgsl/ast/transform/first_index_offset.h"
+#include "src/tint/lang/wgsl/ast/transform/manager.h"
+#include "src/tint/lang/wgsl/ast/transform/renamer.h"
+#include "src/tint/lang/wgsl/ast/transform/single_entry_point.h"
+#include "src/tint/lang/wgsl/ast/transform/substitute_override.h"
+#include "src/tint/lang/wgsl/helpers/flatten_bindings.h"
#include "src/tint/utils/cli/cli.h"
#include "src/tint/utils/command/command.h"
#include "src/tint/utils/containers/transform.h"
diff --git a/src/tint/fuzzers/apply_substitute_overrides.cc b/src/tint/fuzzers/apply_substitute_overrides.cc
index 64f630d..16ea79c 100644
--- a/src/tint/fuzzers/apply_substitute_overrides.cc
+++ b/src/tint/fuzzers/apply_substitute_overrides.cc
@@ -17,6 +17,11 @@
#include <memory>
#include <utility>
+#include "src/tint/lang/wgsl/ast/transform/manager.h"
+#include "src/tint/lang/wgsl/ast/transform/substitute_override.h"
+#include "src/tint/lang/wgsl/inspector/inspector.h"
+#include "src/tint/lang/wgsl/program/program.h"
+
namespace tint::fuzzers {
Program ApplySubstituteOverrides(Program&& program) {
diff --git a/src/tint/fuzzers/apply_substitute_overrides.h b/src/tint/fuzzers/apply_substitute_overrides.h
index 76fb029..31f0263 100644
--- a/src/tint/fuzzers/apply_substitute_overrides.h
+++ b/src/tint/fuzzers/apply_substitute_overrides.h
@@ -15,7 +15,10 @@
#ifndef SRC_TINT_FUZZERS_APPLY_SUBSTITUTE_OVERRIDES_H_
#define SRC_TINT_FUZZERS_APPLY_SUBSTITUTE_OVERRIDES_H_
-#include "tint/tint.h"
+// Forward declarations
+namespace tint {
+class Program;
+}
namespace tint::fuzzers {
diff --git a/src/tint/lang/wgsl/inspector/inspector_builder_test.h b/src/tint/lang/wgsl/inspector/inspector_builder_test.h
index 84162b2..21a962b 100644
--- a/src/tint/lang/wgsl/inspector/inspector_builder_test.h
+++ b/src/tint/lang/wgsl/inspector/inspector_builder_test.h
@@ -30,9 +30,11 @@
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/stage_attribute.h"
#include "src/tint/lang/wgsl/ast/workgroup_attribute.h"
+#include "src/tint/lang/wgsl/inspector/entry_point.h"
+#include "src/tint/lang/wgsl/inspector/inspector.h"
+#include "src/tint/lang/wgsl/inspector/resource_binding.h"
#include "src/tint/lang/wgsl/program/program_builder.h"
#include "src/tint/lang/wgsl/sem/variable.h"
-#include "tint/tint.h"
namespace tint::inspector {
diff --git a/src/tint/lang/wgsl/inspector/inspector_runner_test.cc b/src/tint/lang/wgsl/inspector/inspector_runner_test.cc
index 84a41f3..8993320 100644
--- a/src/tint/lang/wgsl/inspector/inspector_runner_test.cc
+++ b/src/tint/lang/wgsl/inspector/inspector_runner_test.cc
@@ -13,6 +13,7 @@
// limitations under the License.
#include "src/tint/lang/wgsl/inspector/inspector_runner_test.h"
+#include "src/tint/lang/wgsl/reader/reader.h"
namespace tint::inspector {
diff --git a/src/tint/lang/wgsl/inspector/inspector_runner_test.h b/src/tint/lang/wgsl/inspector/inspector_runner_test.h
index cdcb4d6..8b01258 100644
--- a/src/tint/lang/wgsl/inspector/inspector_runner_test.h
+++ b/src/tint/lang/wgsl/inspector/inspector_runner_test.h
@@ -19,7 +19,10 @@
#include <string>
#include "gtest/gtest.h"
-#include "tint/tint.h"
+
+#include "src/tint/lang/wgsl/inspector/inspector.h"
+#include "src/tint/lang/wgsl/program/program.h"
+#include "src/tint/utils/diagnostic/source.h"
namespace tint::inspector {
diff --git a/src/tint/lang/wgsl/inspector/inspector_test.cc b/src/tint/lang/wgsl/inspector/inspector_test.cc
index 3bf9cd3..7a5832e 100644
--- a/src/tint/lang/wgsl/inspector/inspector_test.cc
+++ b/src/tint/lang/wgsl/inspector/inspector_test.cc
@@ -24,11 +24,12 @@
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/stage_attribute.h"
#include "src/tint/lang/wgsl/ast/workgroup_attribute.h"
+#include "src/tint/lang/wgsl/inspector/entry_point.h"
+#include "src/tint/lang/wgsl/inspector/inspector.h"
#include "src/tint/lang/wgsl/inspector/inspector_builder_test.h"
#include "src/tint/lang/wgsl/inspector/inspector_runner_test.h"
#include "src/tint/lang/wgsl/program/program_builder.h"
#include "src/tint/lang/wgsl/sem/variable.h"
-#include "tint/tint.h"
using namespace tint::number_suffixes; // NOLINT
diff --git a/src/tint/tint.cc b/src/tint/tint.cc
deleted file mode 100644
index 5e7aecc..0000000
--- a/src/tint/tint.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2022 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.
-
-#include "tint/tint.h"
-
-namespace tint {
-
-/// Initialize initializes the Tint library. Call before using the Tint API.
-void Initialize() {
-#if TINT_BUILD_WGSL_WRITER
- // Register the Program printer. This is used for debugging purposes.
- tint::Program::printer = [](const tint::Program* program) {
- auto result = wgsl::writer::Generate(program, {});
- if (!result) {
- return "error: " + result.Failure();
- }
- return result->wgsl;
- };
-#endif
-}
-
-/// Shutdown uninitializes the Tint library. Call after using the Tint API.
-void Shutdown() {
- // Currently no-op, but may release tint resources in the future.
-}
-
-} // namespace tint