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- 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 #include #include -#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 + +#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 +#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 #include #include -#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");