diff --git a/BUILD.gn b/BUILD.gn index 6a774ba4ae9..7dab9c962ee 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -30,6 +30,7 @@ group("all") { if (dawn_standalone) { deps += [ "src/dawn/samples", + "src/tint/cmd/remote_compile", "src/tint/cmd/tint", ] } diff --git a/CMakeLists.txt b/CMakeLists.txt index fb7f0b1049d..449f1aebfb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,7 +180,6 @@ option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF) option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF) option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON) option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF) -option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF) set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.") @@ -323,7 +322,6 @@ message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}") message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}") message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") -message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}") message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}") @@ -571,6 +569,3 @@ if (DAWN_EMIT_COVERAGE) VERBATIM) endif() -if (TINT_BUILD_REMOTE_COMPILE) - add_subdirectory(tools/src/cmd/remote-compile) -endif() diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index b97374d3836..ea62726c1ed 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -199,6 +199,10 @@ group("abseil") { } } +source_set("winsock") { + libs = [ "ws2_32.lib" ] +} + ############################################################################### # Aliases. ############################################################################### diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 1720eadd49e..ef4ce00ce72 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -448,6 +448,8 @@ function(tint_target_add_external_dependencies UNSUFFIXED_TARGET KIND) target_link_libraries(${TARGET} PRIVATE glslang-default-resource-limits ) + elseif(${DEPENDENCY} STREQUAL "winsock") + target_link_libraries(${TARGET} PRIVATE ws2_32) else() message(FATAL_ERROR "unhandled external dependency ${DEPENDENCY}") endif() @@ -492,6 +494,9 @@ endfunction() ################################################################################ include("BUILD.cmake") +find_package(Threads REQUIRED) +target_link_libraries(tint_cmd_remote_compile_cmd PRIVATE Threads::Threads) + # If we're building on mac / ios and we have CoreGraphics, then we can use the # metal API to validate our shaders. This is roughly 4x faster than invoking # the metal shader compiler executable. @@ -500,6 +505,7 @@ if(APPLE AND TINT_BUILD_MSL_WRITER) if(LIB_CORE_GRAPHICS) target_sources("tint_lang_msl_validate" PRIVATE "lang/msl/validate/msl_metal.mm") + target_compile_definitions("tint_cmd_remote_compile_cmd" PRIVATE "-DTINT_ENABLE_MSL_VALIDATION_USING_METAL_API=1") target_compile_definitions("tint_lang_msl_validate" PUBLIC "-DTINT_ENABLE_MSL_VALIDATION_USING_METAL_API=1") target_compile_options("tint_lang_msl_validate" PRIVATE "-fmodules" "-fcxx-modules") target_link_options("tint_lang_msl_validate" PUBLIC "-framework" "CoreGraphics") diff --git a/src/tint/cmd/BUILD.cmake b/src/tint/cmd/BUILD.cmake index f5473191ee9..cbad9b942fa 100644 --- a/src/tint/cmd/BUILD.cmake +++ b/src/tint/cmd/BUILD.cmake @@ -24,5 +24,6 @@ include(cmd/bench/BUILD.cmake) include(cmd/common/BUILD.cmake) include(cmd/info/BUILD.cmake) include(cmd/loopy/BUILD.cmake) +include(cmd/remote_compile/BUILD.cmake) include(cmd/test/BUILD.cmake) include(cmd/tint/BUILD.cmake) diff --git a/src/tint/cmd/remote_compile/BUILD.cfg b/src/tint/cmd/remote_compile/BUILD.cfg new file mode 100644 index 00000000000..046b778616a --- /dev/null +++ b/src/tint/cmd/remote_compile/BUILD.cfg @@ -0,0 +1,3 @@ +{ + "cmd": { "OutputName": "tint_remote_compile" } +} diff --git a/src/tint/cmd/remote_compile/BUILD.cmake b/src/tint/cmd/remote_compile/BUILD.cmake new file mode 100644 index 00000000000..a92b5bd19df --- /dev/null +++ b/src/tint/cmd/remote_compile/BUILD.cmake @@ -0,0 +1,45 @@ +# 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. + +################################################################################ +# File generated by tools/src/cmd/gen +# using the template: +# tools/src/cmd/gen/build/BUILD.cmake.tmpl +# +# Do not modify this file directly +################################################################################ + +################################################################################ +# Target: tint_cmd_remote_compile_cmd +# Kind: cmd +################################################################################ +tint_add_target(tint_cmd_remote_compile_cmd cmd + cmd/remote_compile/main.cc +) + +tint_target_add_dependencies(tint_cmd_remote_compile_cmd cmd + tint_lang_wgsl_ast + tint_utils_macros + tint_utils_socket + tint_utils_text + tint_utils_traits +) + +if(TINT_BUILD_MSL_WRITER) + tint_target_add_dependencies(tint_cmd_remote_compile_cmd cmd + tint_lang_msl_validate + ) +endif(TINT_BUILD_MSL_WRITER) + +tint_target_set_output_name(tint_cmd_remote_compile_cmd cmd "tint_remote_compile") diff --git a/src/tint/cmd/remote_compile/BUILD.gn b/src/tint/cmd/remote_compile/BUILD.gn new file mode 100644 index 00000000000..033196a651f --- /dev/null +++ b/src/tint/cmd/remote_compile/BUILD.gn @@ -0,0 +1,41 @@ +# 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. + +################################################################################ +# File generated by tools/src/cmd/gen +# using the template: +# tools/src/cmd/gen/build/BUILD.gn.tmpl +# +# Do not modify this file directly +################################################################################ + +import("../../../../scripts/tint_overrides_with_defaults.gni") + +import("${tint_src_dir}/tint.gni") + +executable("remote_compile") { + output_name = "tint_remote_compile" + sources = [ "main.cc" ] + deps = [ + "${tint_src_dir}/lang/wgsl/ast", + "${tint_src_dir}/utils/macros", + "${tint_src_dir}/utils/socket", + "${tint_src_dir}/utils/text", + "${tint_src_dir}/utils/traits", + ] + + if (tint_build_msl_writer) { + deps += [ "${tint_src_dir}/lang/msl/validate" ] + } +} diff --git a/tools/src/cmd/remote-compile/main.cc b/src/tint/cmd/remote_compile/main.cc similarity index 90% rename from tools/src/cmd/remote-compile/main.cc rename to src/tint/cmd/remote_compile/main.cc index 14ef44db0c2..a13870ecdac 100644 --- a/tools/src/cmd/remote-compile/main.cc +++ b/src/tint/cmd/remote_compile/main.cc @@ -23,8 +23,9 @@ #include #include -#include "tools/src/cmd/remote-compile/compile.h" -#include "tools/src/cmd/remote-compile/socket.h" +#include "src/tint/lang/msl/validate/val.h" +#include "src/tint/utils/macros/compiler.h" +#include "src/tint/utils/socket/socket.h" namespace { @@ -34,6 +35,14 @@ namespace { #define DEBUG(...) #endif +/// The return structure of a compile function +struct CompileResult { + /// True if shader compiled + bool success = false; + /// Output of the compiler + std::string output; +}; + /// Print the tool usage, and exit with 1. [[noreturn]] void ShowUsage() { const char* name = "tint-remote-compile"; @@ -214,11 +223,11 @@ struct CompileRequest : Message { // Client -> Server using Response = CompileResponse; CompileRequest() : Message(Type::CompileRequest) {} - CompileRequest(SourceLanguage lang, uint32_t ver_major, uint32_t ver_minor, std::string src) + CompileRequest(SourceLanguage lang, int ver_major, int ver_minor, std::string src) : Message(Type::CompileRequest), language(lang), - version_major(ver_major), - version_minor(ver_minor), + version_major(uint32_t(ver_major)), + version_minor(uint32_t(ver_minor)), source(src) {} template @@ -284,13 +293,13 @@ bool RunServer(std::string port); bool RunClient(std::string address, std::string port, std::string file, - uint32_t version_major, - uint32_t version_minor); + int version_major, + int version_minor); int main(int argc, char* argv[]) { bool run_server = false; - uint32_t version_major = 0; - uint32_t version_minor = 0; + int version_major = 0; + int version_minor = 0; std::string port = "19000"; std::regex metal_version_re{"^-?-std=macos-metal([0-9]+)\\.([0-9]+)"}; @@ -347,9 +356,11 @@ int main(int argc, char* argv[]) { std::string file; switch (args.size()) { case 1: + TINT_BEGIN_DISABLE_WARNING(DEPRECATED); if (auto* addr = getenv("TINT_REMOTE_COMPILE_ADDRESS")) { address = addr; } + TINT_END_DISABLE_WARNING(DEPRECATED); file = args[0]; break; case 2: @@ -360,7 +371,6 @@ int main(int argc, char* argv[]) { std::cerr << "expected 1 or 2 arguments, got " << args.size() << std::endl << std::endl; ShowUsage(); - break; } if (address.empty() || file.empty()) { ShowUsage(); @@ -385,7 +395,7 @@ bool RunServer(std::string port) { while (auto conn = server_socket->Accept()) { std::thread([=] { DEBUG("Client connected..."); - Stream stream{conn.get()}; + Stream stream{conn.get(), ""}; { ConnectionRequest req; @@ -411,12 +421,15 @@ bool RunServer(std::string port) { DEBUG("%s\n", stream.error.c_str()); return; } -#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API +#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API if (req.language == SourceLanguage::MSL) { - auto result = - CompileMslUsingMetalAPI(req.source, req.version_major, req.version_minor); + auto version = tint::msl::validate::MslVersion::kMsl_1_2; + if (req.version_major == 2 && req.version_minor == 1) { + version = tint::msl::validate::MslVersion::kMsl_2_1; + } + auto result = tint::msl::validate::UsingMetalAPI(req.source, version); CompileResponse resp; - if (!result.success) { + if (result.failed) { resp.error = result.output; } stream << resp; @@ -435,8 +448,8 @@ bool RunServer(std::string port) { bool RunClient(std::string address, std::string port, std::string file, - uint32_t version_major, - uint32_t version_minor) { + int version_major, + int version_minor) { // Read the file std::ifstream input(file, std::ios::binary); if (!input) { @@ -453,7 +466,7 @@ bool RunClient(std::string address, return false; } - Stream stream{conn.get()}; + Stream stream{conn.get(), ""}; DEBUG("Sending connection request..."); auto conn_resp = Send(stream, ConnectionRequest{kProtocolVersion}); diff --git a/src/tint/lang/msl/validate/val.h b/src/tint/lang/msl/validate/val.h index 498516b37a9..78096dcc574 100644 --- a/src/tint/lang/msl/validate/val.h +++ b/src/tint/lang/msl/validate/val.h @@ -40,7 +40,7 @@ enum class MslVersion { struct Result { /// True if validation passed bool failed = false; - /// Output of DXC. + /// Output of Metal compiler. std::string output; }; diff --git a/src/tint/utils/BUILD.cmake b/src/tint/utils/BUILD.cmake index b4c50f55dd1..0f7a6a9ca5a 100644 --- a/src/tint/utils/BUILD.cmake +++ b/src/tint/utils/BUILD.cmake @@ -35,6 +35,7 @@ include(utils/memory/BUILD.cmake) include(utils/reflection/BUILD.cmake) include(utils/result/BUILD.cmake) include(utils/rtti/BUILD.cmake) +include(utils/socket/BUILD.cmake) include(utils/strconv/BUILD.cmake) include(utils/symbol/BUILD.cmake) include(utils/text/BUILD.cmake) diff --git a/src/tint/utils/macros/compiler.h b/src/tint/utils/macros/compiler.h index f0af760d23a..6d31ca86f53 100644 --- a/src/tint/utils/macros/compiler.h +++ b/src/tint/utils/macros/compiler.h @@ -31,6 +31,7 @@ #define TINT_DISABLE_WARNING_UNREACHABLE_CODE __pragma(warning(disable : 4702)) #define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */ #define TINT_DISABLE_WARNING_FLOAT_EQUAL /* currently no-op */ +#define TINT_DISABLE_WARNING_DEPRECATED __pragma(warning(disable : 4996)) // clang-format off #define TINT_BEGIN_DISABLE_WARNING(name) \ @@ -57,6 +58,7 @@ #define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */ #define TINT_DISABLE_WARNING_WEAK_VTABLES _Pragma("clang diagnostic ignored \"-Wweak-vtables\"") #define TINT_DISABLE_WARNING_FLOAT_EQUAL _Pragma("clang diagnostic ignored \"-Wfloat-equal\"") +#define TINT_DISABLE_WARNING_DEPRECATED /* currently no-op */ // clang-format off #define TINT_BEGIN_DISABLE_WARNING(name) \ @@ -83,6 +85,7 @@ #define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */ #define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */ #define TINT_DISABLE_WARNING_FLOAT_EQUAL /* currently no-op */ +#define TINT_DISABLE_WARNING_DEPRECATED /* currently no-op */ // clang-format off #define TINT_BEGIN_DISABLE_WARNING(name) \ diff --git a/src/tint/utils/socket/BUILD.cmake b/src/tint/utils/socket/BUILD.cmake new file mode 100644 index 00000000000..84577fa0f11 --- /dev/null +++ b/src/tint/utils/socket/BUILD.cmake @@ -0,0 +1,37 @@ +# 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. + +################################################################################ +# File generated by tools/src/cmd/gen +# using the template: +# tools/src/cmd/gen/build/BUILD.cmake.tmpl +# +# Do not modify this file directly +################################################################################ + +################################################################################ +# Target: tint_utils_socket +# Kind: lib +################################################################################ +tint_add_target(tint_utils_socket lib + utils/socket/rwmutex.h + utils/socket/socket.cc + utils/socket/socket.h +) + +if(IS_WIN) + tint_target_add_external_dependencies(tint_utils_socket lib + "winsock" + ) +endif(IS_WIN) diff --git a/src/tint/utils/socket/BUILD.gn b/src/tint/utils/socket/BUILD.gn new file mode 100644 index 00000000000..7f0bba4a68b --- /dev/null +++ b/src/tint/utils/socket/BUILD.gn @@ -0,0 +1,38 @@ +# 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. + +################################################################################ +# File generated by tools/src/cmd/gen +# using the template: +# tools/src/cmd/gen/build/BUILD.gn.tmpl +# +# Do not modify this file directly +################################################################################ + +import("../../../../scripts/tint_overrides_with_defaults.gni") + +import("${tint_src_dir}/tint.gni") + +libtint_source_set("socket") { + sources = [ + "rwmutex.h", + "socket.cc", + "socket.h", + ] + deps = [] + + if (is_win) { + deps += [ "${tint_src_dir}:winsock" ] + } +} diff --git a/tools/src/cmd/remote-compile/rwmutex.h b/src/tint/utils/socket/rwmutex.h similarity index 97% rename from tools/src/cmd/remote-compile/rwmutex.h rename to src/tint/utils/socket/rwmutex.h index 0a6381dbbbe..9b010ed977d 100644 --- a/tools/src/cmd/remote-compile/rwmutex.h +++ b/src/tint/utils/socket/rwmutex.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef TOOLS_SRC_CMD_REMOTE_COMPILE_RWMUTEX_H_ -#define TOOLS_SRC_CMD_REMOTE_COMPILE_RWMUTEX_H_ +#ifndef SRC_TINT_UTILS_SOCKET_RWMUTEX_H_ +#define SRC_TINT_UTILS_SOCKET_RWMUTEX_H_ #include #include @@ -187,4 +187,4 @@ WLock& WLock::operator=(WLock&& other) { return *this; } -#endif // TOOLS_SRC_CMD_REMOTE_COMPILE_RWMUTEX_H_ +#endif // SRC_TINT_UTILS_SOCKET_RWMUTEX_H_ diff --git a/tools/src/cmd/remote-compile/socket.cc b/src/tint/utils/socket/socket.cc similarity index 89% rename from tools/src/cmd/remote-compile/socket.cc rename to src/tint/utils/socket/socket.cc index 91e87a0a7f9..54cb462c501 100644 --- a/tools/src/cmd/remote-compile/socket.cc +++ b/src/tint/utils/socket/socket.cc @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "tools/src/cmd/remote-compile/socket.h" +#include "src/tint/utils/socket/socket.h" -#include "tools/src/cmd/remote-compile/rwmutex.h" +#include "src/tint/utils/socket/rwmutex.h" #if defined(_WIN32) #include @@ -101,6 +101,8 @@ class Impl : public Socket { if (err) { printf("getaddrinfo(%s, %s) error: %s\n", address, port, gai_strerror(err)); } +#else + (void)err; #endif if (info) { @@ -110,16 +112,18 @@ class Impl : public Socket { return out; } - freeaddrinfo(info); Term(); return nullptr; } explicit Impl(SOCKET socket) : info(nullptr), s(socket) {} - Impl(addrinfo* info, SOCKET socket) : info(info), s(socket) {} - ~Impl() { - freeaddrinfo(info); + Impl(addrinfo* i, SOCKET socket) : info(i), s(socket) {} + + ~Impl() override { + if (info) { + freeaddrinfo(info); + } Close(); Term(); } @@ -193,9 +197,9 @@ class Impl : public Socket { if (s == InvalidSocket) { return 0; } - size_t len = recv(s, reinterpret_cast(buffer), static_cast(bytes), 0); + auto len = recv(s, reinterpret_cast(buffer), bytes, 0); if (len > 0) { - return len; + return static_cast(len); } } // Socket closed or errored @@ -212,7 +216,7 @@ class Impl : public Socket { if (bytes == 0) { return true; } - return ::send(s, reinterpret_cast(buffer), static_cast(bytes), 0) > 0; + return ::send(s, reinterpret_cast(buffer), bytes, 0) > 0; } std::shared_ptr Accept() override { @@ -220,8 +224,8 @@ class Impl : public Socket { Lock([&](SOCKET socket, const addrinfo*) { if (socket != InvalidSocket) { Init(); - if (auto s = ::accept(socket, 0, 0); s >= 0) { - out = std::make_shared(s); + if (auto sock = ::accept(socket, nullptr, nullptr); s >= 0) { + out = std::make_shared(sock); out->SetOptions(); } } @@ -237,13 +241,15 @@ class Impl : public Socket { } // anonymous namespace +Socket::~Socket() = default; + std::shared_ptr Socket::Listen(const char* address, const char* port) { auto impl = Impl::create(address, port); if (!impl) { return nullptr; } impl->Lock([&](SOCKET socket, const addrinfo* info) { - if (bind(socket, info->ai_addr, static_cast(info->ai_addrlen)) != 0) { + if (bind(socket, info->ai_addr, info->ai_addrlen) != 0) { impl.reset(); return; } @@ -271,7 +277,7 @@ std::shared_ptr Socket::Connect(const char* address, } if (timeout_ms == 0) { - if (::connect(socket, info->ai_addr, static_cast(info->ai_addrlen)) == 0) { + if (::connect(socket, info->ai_addr, info->ai_addrlen) == 0) { out = impl; } return; @@ -281,7 +287,7 @@ std::shared_ptr Socket::Connect(const char* address, return; } - auto res = ::connect(socket, info->ai_addr, static_cast(info->ai_addrlen)); + auto res = ::connect(socket, info->ai_addr, info->ai_addrlen); if (res == 0) { if (SetBlocking(socket, true)) { out = impl; @@ -295,7 +301,7 @@ std::shared_ptr Socket::Connect(const char* address, timeval tv; tv.tv_sec = timeout_us / 1000000; - tv.tv_usec = timeout_us - static_cast(tv.tv_sec * 1000000); + tv.tv_usec = static_cast(timeout_us - (tv.tv_sec * 1000000)); res = select(static_cast(socket + 1), nullptr, &fdset, nullptr, &tv); if (res > 0 && !Errored(socket) && SetBlocking(socket, true)) { out = impl; diff --git a/tools/src/cmd/remote-compile/socket.h b/src/tint/utils/socket/socket.h similarity index 94% rename from tools/src/cmd/remote-compile/socket.h rename to src/tint/utils/socket/socket.h index 59115ea19df..5ca37cc2967 100644 --- a/tools/src/cmd/remote-compile/socket.h +++ b/src/tint/utils/socket/socket.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef TOOLS_SRC_CMD_REMOTE_COMPILE_SOCKET_H_ -#define TOOLS_SRC_CMD_REMOTE_COMPILE_SOCKET_H_ +#ifndef SRC_TINT_UTILS_SOCKET_SOCKET_H_ +#define SRC_TINT_UTILS_SOCKET_SOCKET_H_ #include #include @@ -40,6 +40,9 @@ class Socket { /// @returns the Socket that listens for connections static std::shared_ptr Listen(const char* address, const char* port); + /// Destructor + virtual ~Socket(); + /// Attempts to read at most `n` bytes into buffer, returning the actual number of bytes read. /// read() will block until the socket is closed or at least one byte is read. /// @param buffer the output buffer. Must be at least `n` bytes in size. @@ -65,4 +68,4 @@ class Socket { virtual std::shared_ptr Accept() = 0; }; -#endif // TOOLS_SRC_CMD_REMOTE_COMPILE_SOCKET_H_ +#endif // SRC_TINT_UTILS_SOCKET_SOCKET_H_ diff --git a/tools/src/cmd/gen/build/BUILD.gn.tmpl b/tools/src/cmd/gen/build/BUILD.gn.tmpl index 4d325de1ad0..89ba09fbace 100644 --- a/tools/src/cmd/gen/build/BUILD.gn.tmpl +++ b/tools/src/cmd/gen/build/BUILD.gn.tmpl @@ -150,6 +150,7 @@ test("{{$.Directory.Name}}") { {{- else if eq $.Name "spirv-headers" -}}"${tint_spirv_headers_dir}:spv_headers", {{- else if eq $.Name "glslang" -}}"${tint_glslang_dir}:glslang_lib_sources", {{- else if eq $.Name "glslang-res-limits" -}}"${tint_glslang_dir}:glslang_default_resource_limits_sources", +{{- else if eq $.Name "winsock" -}}"${tint_src_dir}:winsock", {{- else -}}{{Error (printf "unhandled external dependency '%v'" $.Name)}} {{- end}} {{- end}} diff --git a/tools/src/cmd/gen/build/build.go b/tools/src/cmd/gen/build/build.go index 1678bd3b001..a185c3ce767 100644 --- a/tools/src/cmd/gen/build/build.go +++ b/tools/src/cmd/gen/build/build.go @@ -641,7 +641,7 @@ func emitDotFile(p *Project, kind TargetKind) error { var ( // Regular expressions used by this file - reInclude = regexp.MustCompile(`\s*#\s*include\s*\"([^"]+)\"`) + reInclude = regexp.MustCompile(`\s*#\s*include\s*(?:\"|<)([^(\"|>)]+)(?:\"|>)`) reIgnoreFile = regexp.MustCompile(`//\s*GEN_BUILD:IGNORE_FILE`) reIgnoreInclude = regexp.MustCompile(`//\s*GEN_BUILD:IGNORE_INCLUDE`) reCondition = regexp.MustCompile(`//\s*GEN_BUILD:CONDITION\((.*)\)\s*$`) diff --git a/tools/src/cmd/gen/build/externals.json b/tools/src/cmd/gen/build/externals.json index 54816e87450..55d2ae6434b 100644 --- a/tools/src/cmd/gen/build/externals.json +++ b/tools/src/cmd/gen/build/externals.json @@ -31,4 +31,8 @@ "gmock/**", ], }, + "winsock": { + "IncludePatterns": ["winsock2.h"], + "Condition": "is_win", + }, } diff --git a/tools/src/cmd/remote-compile/CMakeLists.txt b/tools/src/cmd/remote-compile/CMakeLists.txt deleted file mode 100644 index 8748ff13acb..00000000000 --- a/tools/src/cmd/remote-compile/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# 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. - -set(SRC - main.cc - rwmutex.h - socket.cc - socket.h -) - -find_package (Threads REQUIRED) - -add_executable(tint-remote-compile ${SRC}) - -target_link_libraries (tint-remote-compile Threads::Threads) -target_include_directories(tint-remote-compile PRIVATE "${TINT_ROOT_SOURCE_DIR}") - -# If we're building on mac / ios and we have CoreGraphics, then we can use the -# metal API to validate our shaders. This is roughly 4x faster than invoking -# the metal shader compiler executable. -if(APPLE) - find_library(LIB_CORE_GRAPHICS CoreGraphics) - if(LIB_CORE_GRAPHICS) - target_sources(tint-remote-compile PRIVATE "msl_metal.mm") - target_compile_definitions(tint-remote-compile PRIVATE "-DTINT_ENABLE_MSL_COMPILATION_USING_METAL_API=1") - target_compile_options(tint-remote-compile PRIVATE "-fmodules" "-fcxx-modules") - target_link_options(tint-remote-compile PRIVATE "-framework" "CoreGraphics") - endif() -endif() diff --git a/tools/src/cmd/remote-compile/compile.h b/tools/src/cmd/remote-compile/compile.h deleted file mode 100644 index bdff29a1d8d..00000000000 --- a/tools/src/cmd/remote-compile/compile.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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 -// -// https://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 TOOLS_SRC_CMD_REMOTE_COMPILE_COMPILE_H_ -#define TOOLS_SRC_CMD_REMOTE_COMPILE_COMPILE_H_ - -#include - -/// The return structure of a compile function -struct CompileResult { - /// True if shader compiled - bool success = false; - /// Output of the compiler - std::string output; -}; - -CompileResult CompileMslUsingMetalAPI(const std::string& src, - uint32_t version_major, - uint32_t version_minor); - -#endif // TOOLS_SRC_CMD_REMOTE_COMPILE_COMPILE_H_ diff --git a/tools/src/cmd/remote-compile/msl_metal.mm b/tools/src/cmd/remote-compile/msl_metal.mm deleted file mode 100644 index 1b13a44fef2..00000000000 --- a/tools/src/cmd/remote-compile/msl_metal.mm +++ /dev/null @@ -1,69 +0,0 @@ -// 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. - -#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API - -@import Metal; - -// Disable: error: treating #include as an import of module 'std.string' -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wauto-import" -#include "compile.h" -#pragma clang diagnostic pop - -CompileResult CompileMslUsingMetalAPI(const std::string& src, - uint32_t version_major, - uint32_t version_minor) { - CompileResult result; - result.success = false; - - NSError* error = nil; - - id device = MTLCreateSystemDefaultDevice(); - if (!device) { - result.output = "MTLCreateSystemDefaultDevice returned null"; - result.success = false; - return result; - } - - NSString* source = [NSString stringWithCString:src.c_str() encoding:NSUTF8StringEncoding]; - - MTLCompileOptions* compileOptions = [MTLCompileOptions new]; - compileOptions.fastMathEnabled = true; - compileOptions.languageVersion = MTLLanguageVersion1_2; - - if ((version_major == 0 && version_minor == 0) || (version_major == 1 && version_minor == 2)) { - compileOptions.languageVersion = MTLLanguageVersion1_2; - } else if (version_major == 2 && version_minor == 1) { - compileOptions.languageVersion = MTLLanguageVersion2_1; - } else { - result.output = "unsupported version " + std::to_string(version_major) + "." + - std::to_string(version_minor); - result.success = false; - return result; - } - - id library = [device newLibraryWithSource:source - options:compileOptions - error:&error]; - if (!library) { - NSString* output = [error localizedDescription]; - result.output = [output UTF8String]; - result.success = false; - } - - return result; -} - -#endif