[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-01-04 Thread Jan Svoboda via cfe-commits


@@ -0,0 +1,48 @@
+//===-- Utils.h 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Functions required by both the frontend and the module build daemon
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_MODULEBUILDDAEMON_UTILS_H
+#define LLVM_CLANG_TOOLING_MODULEBUILDDAEMON_UTILS_H
+
+#include "llvm/Support/Error.h"
+
+#include 
+
+#ifdef _WIN32
+#include 
+#else
+#include 
+#endif
+
+namespace clang::tooling::cc1modbuildd {
+
+constexpr const std::string_view SOCKET_FILE_NAME = "mbd.sock";
+constexpr const std::string_view STDOUT_FILE_NAME = "mbd.out";
+constexpr const std::string_view STDERR_FILE_NAME = "mbd.err";
+constexpr const std::string_view MODULE_BUILD_DAEMON_FLAG = "-cc1modbuildd";
+
+// A llvm::raw_socket_stream uses sockaddr_un
+constexpr const size_t SOCKET_ADDR_MAX_LENGTH = sizeof(sockaddr_un::sun_path);
+
+constexpr const size_t BASEPATH_MAX_LENGTH =
+SOCKET_ADDR_MAX_LENGTH - std::string_view(SOCKET_FILE_NAME).length();

jansvoboda11 wrote:

Is constructing new `std::string_view` from `SOCKET_FILE_NAME` necessary?

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-01-04 Thread Jan Svoboda via cfe-commits


@@ -383,6 +383,9 @@ class FrontendOptions {
   LLVM_PREFERRED_TYPE(bool)
   unsigned ModulesShareFileManager : 1;
 
+  /// Connect to module build daemon
+  unsigned ModuleBuildDaemon : 1;

jansvoboda11 wrote:

Mark this with `LLVM_PREFERRED_TYPE(bool)`, like the other bool-like bitfield 
in this class.

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-01-04 Thread Jan Svoboda via cfe-commits


@@ -0,0 +1,48 @@
+//===-- Utils.h 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Functions required by both the frontend and the module build daemon
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_MODULEBUILDDAEMON_UTILS_H
+#define LLVM_CLANG_TOOLING_MODULEBUILDDAEMON_UTILS_H
+
+#include "llvm/Support/Error.h"
+
+#include 
+
+#ifdef _WIN32
+#include 
+#else
+#include 
+#endif
+
+namespace clang::tooling::cc1modbuildd {
+
+constexpr const std::string_view SOCKET_FILE_NAME = "mbd.sock";

jansvoboda11 wrote:

You should be able to drop `const` here, since that's implied by `constexpr`.

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-01-04 Thread Jan Svoboda via cfe-commits


@@ -0,0 +1,60 @@
+//=== SocketMsgSupport.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_socket_stream.h"
+
+#include 
+#include 
+
+using namespace llvm;
+
+namespace clang::tooling::cc1modbuildd {
+
+Expected>
+connectToSocket(StringRef SocketPath) {
+
+  Expected> MaybeClient =
+  raw_socket_stream::createConnectedUnix(SocketPath);
+  if (!MaybeClient)
+return std::move(MaybeClient.takeError());
+
+  return std::move(*MaybeClient);
+}
+
+Expected readBufferFromSocket(raw_socket_stream &Socket) {
+
+  constexpr const unsigned short MAX_BUFFER = 4096;
+  char Buffer[MAX_BUFFER];
+  std::string ReturnBuffer;
+
+  ssize_t n = 0;
+  while ((n = Socket.read(Buffer, MAX_BUFFER)) > 0) {
+ReturnBuffer.append(Buffer, n);
+// Read until \n... encountered which is the last line of a YAML document
+if (ReturnBuffer.find("\n...") != std::string::npos)

jansvoboda11 wrote:

IIUC `"\n..."` is always going to be at the end of `ReturnBuffer`, right? Could 
we replace the call to `std::string::find()` with 
`StringRef(ReturnBuffer).ends_with("\n...")`? Considering `"\n..."` constant, I 
think this would reduce the complexity of the `while` loop from `O(n*n)` to 
`O(n)`.

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-12-14 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

> This seems like something that shouldn't be in the compiler binary itself. 
> There should be a separate binary for this type of thing.

Discussed here: 
https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-12-14 Thread Nico Weber via cfe-commits

nico wrote:

This seems like something that shouldn't be in the compiler binary itself. 
There should be a separate binary for this type of thing.

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits