diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a4551db..250bde3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -11,9 +11,11 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ ca-certificates \ curl \ gnupg2 \ + libssl-dev \ vim \ software-properties-common \ graphviz xdot \ + ninja-build \ && add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ @@ -33,6 +35,15 @@ RUN curl -L -O https://github.com/bazelbuild/buildtools/releases/download/3.5.0/ && chmod +x buildifier \ && mv buildifier /usr/local/bin +RUN curl -L -O https://github.com/actor-framework/actor-framework/archive/c2be26e7f9e3e84ef14730590fc4e7b25fb9d29a.zip \ + && unzip -d caf c2be26e7f9e3e84ef14730590fc4e7b25fb9d29a.zip \ + && cd caf/actor-framework-c2be26e7f9e3e84ef14730590fc4e7b25fb9d29a/ \ + && ./configure --generator=Ninja \ + && cd build \ + && cmake -G "Ninja" .. \ + && ninja install \ + && cd ../../.. \ + && rm -rf caf RUN locale-gen en_US.UTF-8 ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b92ed3..eb040bc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -38,5 +38,6 @@ // "postCreateCommand": "gcc -v", // Comment out this line to run as root instead. - "remoteUser": "vscode" + "remoteUser": "vscode", + } diff --git a/WORKSPACE b/WORKSPACE index 35b8c62..00c8ed3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,4 +1,5 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") git_repository( name = "googletest", @@ -15,6 +16,14 @@ new_local_repository( new_git_repository( name = "fmt", remote = "https://github.com/fmtlib/fmt", - branch = "master", + commit = "6884aab49b1b7fc6dcba1e27999f1aced0b888be", + shallow_since = "1641501513 -0800", build_file = "//:fmt.BUILD", +) + +new_local_repository( + name = "caf", + path = "/usr/local", + build_file = "caf.BUILD", + ) \ No newline at end of file diff --git a/actor/BUILD b/actor/BUILD new file mode 100644 index 0000000..d1f97aa --- /dev/null +++ b/actor/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@//:global_copts.bzl", "global_copts") + +package(features = ["-default_compile_flags"]) + +cc_binary( + name = "actor", + srcs = ["actor.cpp"], + copts = global_copts(), + deps = [ + "@caf//:main", + "@fmt//:main", + "@ncurses//:main", + ], +) diff --git a/actor/actor.cpp b/actor/actor.cpp new file mode 100644 index 0000000..89260e2 --- /dev/null +++ b/actor/actor.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include "caf/actor_ostream.hpp" +#include "caf/actor_system.hpp" +#include "caf/caf_main.hpp" +#include "caf/event_based_actor.hpp" + +using namespace caf; + +behavior mirror(event_based_actor* self) { + // return the (initial) actor behavior + return { + // a handler for messages containing a single string + // that replies with a string + [=](const std::string& what) -> std::string { + // prints "Hello World!" via aout (thread-safe cout wrapper) + aout(self) << what << std::endl; + // reply "!dlroW olleH" + return std::string{what.rbegin(), what.rend()}; + }, + }; +} + +void hello_world(event_based_actor* self, const actor& buddy) { + // send "Hello World!" to our buddy ... + self->request(buddy, std::chrono::seconds(10), "Hello World!") + .then( + // ... wait up to 10s for a response ... + [=](const std::string& what) { + // ... and print it + aout(self) << what << std::endl; + }); +} + +void caf_main(actor_system& sys) { + // create a new actor that calls 'mirror()' + auto mirror_actor = sys.spawn(mirror); + // create another actor that calls 'hello_world(mirror_actor)'; + sys.spawn(hello_world, mirror_actor); + // the system will wait until both actors are done before exiting the program +} + +// creates a main function for us that calls our caf_main +CAF_MAIN() \ No newline at end of file diff --git a/caf.BUILD b/caf.BUILD new file mode 100644 index 0000000..92b7305 --- /dev/null +++ b/caf.BUILD @@ -0,0 +1,14 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "main", + srcs = [ + "lib/libcaf_openssl.so.0.18.5", + "lib/libcaf_io.so", + "lib/libcaf_openssl.so", + "lib/libcaf_io.so.0.18.5", + "lib/libcaf_core.so.0.18.5", + "lib/libcaf_core.so", + ], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/util/BUILD b/util/BUILD index 82edb1e..9918682 100644 --- a/util/BUILD +++ b/util/BUILD @@ -12,3 +12,13 @@ cc_binary( "@ncurses//:main", ], ) + +cc_binary( + name = "scratch", + srcs = ["scratch.cpp"], + copts = global_copts(), + deps = [ + "@fmt//:main", + "@ncurses//:main", + ], +) diff --git a/util/scratch.cpp b/util/scratch.cpp new file mode 100644 index 0000000..e2f87e5 --- /dev/null +++ b/util/scratch.cpp @@ -0,0 +1,15 @@ +#include "include/fmt/format.h" +#include "include/fmt/printf.h" + +#include + +int main(int /*argc*/, char** /*argv*/) { + + std::unique_ptr pint = std::make_unique(); + std::shared_ptr spint = std::move(pint); + *spint = 10; + + fmt::printf("Value is %d\n", *spint); + + return 0; +} \ No newline at end of file