From 3dbff1f646ec75642d8efc4cc6ae827ff8452c30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8C=85=E4=BB=81=E4=B9=89?= <renyi.bao@yiducloud.cn>
Date: Thu, 11 Aug 2022 19:22:52 +0800
Subject: [PATCH] change source to mpct

---
 .gitignore                | 14 +++++++++++++-
 README.md                 | 25 ++++++++++++++++++++++++-
 WORKSPACE                 | 16 ++++++++++++++++
 bazel/repositories.bzl    |  2 +-
 {src => mpct}/BUILD.bazel |  0
 {src => mpct}/client.cpp  |  2 +-
 mpct/common/BUILD.bazel   | 14 ++++++++++++++
 mpct/common/executor.hpp  | 22 ++++++++++++++++++++++
 mpct/common/task.hpp      |  5 +++++
 {src => mpct}/echo.proto  |  0
 {src => mpct}/main.cc     |  0
 mpct/network/BUILD.bazel  | 10 ++++++++++
 mpct/network/party.cpp    |  8 ++++++++
 mpct/network/party.hpp    | 13 +++++++++++++
 {src => mpct}/server.cpp  |  2 +-
 15 files changed, 128 insertions(+), 5 deletions(-)
 rename {src => mpct}/BUILD.bazel (100%)
 rename {src => mpct}/client.cpp (99%)
 create mode 100644 mpct/common/BUILD.bazel
 create mode 100644 mpct/common/executor.hpp
 create mode 100644 mpct/common/task.hpp
 rename {src => mpct}/echo.proto (100%)
 rename {src => mpct}/main.cc (100%)
 create mode 100644 mpct/network/BUILD.bazel
 create mode 100644 mpct/network/party.cpp
 create mode 100644 mpct/network/party.hpp
 rename {src => mpct}/server.cpp (99%)

diff --git a/.gitignore b/.gitignore
index 4dc5ddd..512a00b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,17 @@
 /.vscode/
+
+# add symlinks
 bazel-bin
 bazel-mpc-toolkit
 bazel-out
-bazel-testlogs
\ No newline at end of file
+bazel-testlogs
+
+### Added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
+# The external link: Differs on Windows vs macOS/Linux, so we can't check it in. The pattern needs to not have a trailing / because it's a symlink on macOS/Linux.
+/external
+# Bazel output symlinks: Same reasoning as /external. You need the * because people can change the name of the directory your repository is cloned into, changing the bazel-<workspace_name> symlink.
+/bazel-*
+# Compiled output -> don't check in
+/compile_commands.json
+# Directory where clangd puts its indexing work
+/.cache/
diff --git a/README.md b/README.md
index 592f81e..c83a95f 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,24 @@
-# mpc-toolkit
\ No newline at end of file
+# mpc-toolkit
+
+## 环境初始化
+
+```bash
+$ git clone https://github.com/baobaoyeye/mpc-toolkit.git
+$ cd mpc-toolkit
+```
+
+bazel+clangd生成compile_commands.json 
+[compilation-database.html#bazel](https://sarcasm.github.io/notes/dev/compilation-database.html#bazel) 
+[bazel-compile-commands-extractor](https://github.com/hedronvision/bazel-compile-commands-extractor)
+
+```bash
+# 生成在根目录生成 compile_commands.json
+$ bazel run @hedron_compile_commands//:refresh_all
+```
+
+## 编译构建
+
+```bash
+# 全部编译
+$ bazel build //... -c dbg
+```
diff --git a/WORKSPACE b/WORKSPACE
index 84dabd3..055e8e6 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,6 +1,8 @@
 workspace(name = "mpc-toolkit")
 
 load("//bazel:repositories.bzl", "mpct_deps")
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
 
 mpct_deps()
 
@@ -14,3 +16,17 @@ rules_foreign_cc_dependencies(
     register_default_tools = False,
     register_preinstalled_tools = True,
 )
+
+# Hedron's Compile Commands Extractor for Bazel
+# https://github.com/hedronvision/bazel-compile-commands-extractor
+http_archive(
+    name = "hedron_compile_commands",
+
+    # Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
+    # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
+    url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/d1e95ec162e050b04d0a191826f9bc478de639f7.tar.gz",
+    strip_prefix = "bazel-compile-commands-extractor-d1e95ec162e050b04d0a191826f9bc478de639f7",
+    # When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
+)
+load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
+hedron_compile_commands_setup()
\ No newline at end of file
diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl
index 5d4a227..063bce6 100644
--- a/bazel/repositories.bzl
+++ b/bazel/repositories.bzl
@@ -151,7 +151,7 @@ def _com_github_gabime_spdlog():
         strip_prefix = "spdlog-1.9.2",
         type = "tar.gz",
         sha256 = "6fff9215f5cb81760be4cc16d033526d1080427d236e86d70bb02994f85e3d38",
-        build_file = "@mpct-toolkit//bazel:spdlog.BUILD",
+        build_file = "@mpc-toolkit//bazel:spdlog.BUILD",
         urls = [
             "https://github.com/gabime/spdlog/archive/refs/tags/v1.9.2.tar.gz",
         ],
diff --git a/src/BUILD.bazel b/mpct/BUILD.bazel
similarity index 100%
rename from src/BUILD.bazel
rename to mpct/BUILD.bazel
diff --git a/src/client.cpp b/mpct/client.cpp
similarity index 99%
rename from src/client.cpp
rename to mpct/client.cpp
index d4cafb6..2d5e6ed 100644
--- a/src/client.cpp
+++ b/mpct/client.cpp
@@ -2,7 +2,7 @@
 #include <butil/logging.h>
 #include <butil/time.h>
 #include <brpc/channel.h>
-#include "src/echo.pb.h"
+#include "mpct/echo.pb.h"
 
 DEFINE_string(attachment, "", "Carry this along with requests");
 DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options.proto");
diff --git a/mpct/common/BUILD.bazel b/mpct/common/BUILD.bazel
new file mode 100644
index 0000000..df035a2
--- /dev/null
+++ b/mpct/common/BUILD.bazel
@@ -0,0 +1,14 @@
+load("//bazel:mpct.bzl", "mpct_cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+mpct_cc_library(
+    name = "task",
+    hdrs = ["task.hpp"],
+)
+
+mpct_cc_library(
+    name = "executor",
+    hdrs = ["executor.hpp"],
+    deps = [":task"],
+)
diff --git a/mpct/common/executor.hpp b/mpct/common/executor.hpp
new file mode 100644
index 0000000..2a3a1b3
--- /dev/null
+++ b/mpct/common/executor.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <vector>
+
+#include "mpct/common/task.hpp"
+
+class Executor {
+ public:
+  virtual ~Executor() = default;
+  virtual void execute(const Task& task);
+  virtual void executeAll(const Task& task);
+};
+
+class PlainExecutor : public Executor {
+ public:
+  virtual ~PlainExecutor() = default;
+};
+
+class SecureExecutor : public Executor {
+ public:
+  virtual ~SecureExecutor() = default;
+};
\ No newline at end of file
diff --git a/mpct/common/task.hpp b/mpct/common/task.hpp
new file mode 100644
index 0000000..71eef86
--- /dev/null
+++ b/mpct/common/task.hpp
@@ -0,0 +1,5 @@
+#pragma once
+
+class Task {
+
+};
\ No newline at end of file
diff --git a/src/echo.proto b/mpct/echo.proto
similarity index 100%
rename from src/echo.proto
rename to mpct/echo.proto
diff --git a/src/main.cc b/mpct/main.cc
similarity index 100%
rename from src/main.cc
rename to mpct/main.cc
diff --git a/mpct/network/BUILD.bazel b/mpct/network/BUILD.bazel
new file mode 100644
index 0000000..c67eaa6
--- /dev/null
+++ b/mpct/network/BUILD.bazel
@@ -0,0 +1,10 @@
+load("//bazel:mpct.bzl", "mpct_cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+mpct_cc_library(
+    name = "party",
+    srcs = ["party.cpp"],
+    hdrs = ["party.hpp"],
+    deps = ["//mpct/common:executor"],
+)
\ No newline at end of file
diff --git a/mpct/network/party.cpp b/mpct/network/party.cpp
new file mode 100644
index 0000000..9ebcbd7
--- /dev/null
+++ b/mpct/network/party.cpp
@@ -0,0 +1,8 @@
+
+#include "mpct/network/party.hpp"
+#include "spdlog/spdlog.h"
+
+
+Party::Party() {
+    SPDLOG_INFO("create party");
+}
\ No newline at end of file
diff --git a/mpct/network/party.hpp b/mpct/network/party.hpp
new file mode 100644
index 0000000..298052a
--- /dev/null
+++ b/mpct/network/party.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <stdint.h>
+#include "mpct/common/executor.hpp"
+
+class Party {
+ public:
+  Party();
+  ~Party();
+ private:
+  uint32_t party_id;
+  Executor* executor;
+};
\ No newline at end of file
diff --git a/src/server.cpp b/mpct/server.cpp
similarity index 99%
rename from src/server.cpp
rename to mpct/server.cpp
index 667af65..097e5e6 100644
--- a/src/server.cpp
+++ b/mpct/server.cpp
@@ -1,7 +1,7 @@
 #include <gflags/gflags.h>
 #include <butil/logging.h>
 #include <brpc/server.h>
-#include "src/echo.pb.h"
+#include "mpct/echo.pb.h"
 
 DEFINE_bool(echo_attachment, true, "Echo attachment as well");
 DEFINE_int32(port, 8000, "TCP Port of this server");