Skip to content

Commit 7f678f6

Browse files
authored
Merge pull request #8 from StarryInternet/feature/macOS
Building on macOS
2 parents ca82037 + 745b809 commit 7f678f6

13 files changed

+126
-59
lines changed

README.md

+48-36
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,6 @@ sysadmin
33

44
Like system administrators in big companies, `sysadmin` configures things
55

6-
Development
7-
===========
8-
9-
Generally speaking, build as follows:
10-
11-
```
12-
mkdir build
13-
cd build
14-
cmake ..
15-
make check
16-
make
17-
```
18-
19-
`make check` runs only sysadmin's tests. If you wish to run the decibel-cpp tests, run
20-
`make decibel-check`.
21-
22-
If this is your first time, you might have some dependencies which need to be installed
23-
first. The included `third-party-build.sh` will download, build, then install those
24-
dependencies. You will definitely need gcc, g++, and make at the very least in order
25-
to build those dependencies.
26-
27-
Dependencies
28-
============
29-
30-
sysadmin's dependencies are codified in its CMakeLists.txt files, but the key ones are
31-
as follows:
32-
- decibel-cpp, which is included with sysadmin and built when sysadmin is built. It
33-
is a C++ wrapper around libuv, and additional abstractions built with folly
34-
- [libuv](https://github.com/libuv/libuv) is a C event loop library
35-
- [boost](http://www.boost.org/) is boost
36-
- [folly](https://github.com/facebook/folly) is a C++ library, primarily used for
37-
its excellent futures code
38-
- [protobufs](https://developers.google.com/protocol-buffers/), specifically proto 2,
39-
provides the API to sysadmin
40-
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) provides YAML config file support
41-
426
About
437
=====
448

@@ -70,3 +34,51 @@ sysadmin allows you to change the value of one or more of these keys, then `comm
7034
all at once, at which point the 2 hooks above are run. From a user's perspective, they need
7135
only know what values they want, and sysadmin takes care of the messy, system level details
7236
via its hooks.
37+
38+
Dependencies
39+
============
40+
41+
sysadmin's dependencies are codified in its CMakeLists.txt files, but the key ones are
42+
as follows:
43+
- decibel-cpp, which is included with sysadmin and built when sysadmin is built. It
44+
is a C++ wrapper around libuv, and additional abstractions built with folly
45+
- [libuv](https://github.com/libuv/libuv) is a C event loop library
46+
- [boost](http://www.boost.org/) is boost
47+
- [folly](https://github.com/facebook/folly) is a C++ library, primarily used for
48+
its excellent futures code
49+
- [protobufs](https://developers.google.com/protocol-buffers/), specifically proto 2,
50+
provides the API to sysadmin
51+
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) provides YAML config file support
52+
53+
Development
54+
===========
55+
56+
Generally speaking, build as follows:
57+
58+
```
59+
mkdir build
60+
cd build
61+
cmake ..
62+
make check
63+
make
64+
```
65+
66+
`make check` runs only sysadmin's tests. If you wish to run the decibel-cpp tests, run
67+
`make decibel-check`.
68+
69+
If this is your first time, you might have some dependencies which need to be installed
70+
first.
71+
72+
If you're on linux, the included `third-party-build.sh` will pull and install all
73+
the necessary dependencies.
74+
75+
On macOS, `brew` is generally able to install all the necessary
76+
libraries, at least at the time of writing this. You'll at least need to do the following
77+
the first time:
78+
```bash
79+
brew install folly # Folly is the key dependency, and brings boost with it
80+
brew install amqp-cpp
81+
brew install libuv
82+
brew install yaml-cpp
83+
brew install protobuf
84+
```

decibel-cpp/include/decibel/Protobuf.h

+2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct ProtobufSetter
100100

101101
DEFINE_PROTOBUF_FIELD_MAPPING(int32_t, Int32);
102102
DEFINE_PROTOBUF_FIELD_MAPPING(int64_t, Int64);
103+
DEFINE_PROTOBUF_FIELD_MAPPING(long, Int64);
103104
DEFINE_PROTOBUF_FIELD_MAPPING(uint32_t, UInt32);
104105
DEFINE_PROTOBUF_FIELD_MAPPING(uint64_t, UInt64);
106+
DEFINE_PROTOBUF_FIELD_MAPPING(unsigned long, UInt64);
105107
DEFINE_PROTOBUF_FIELD_MAPPING(float, Float);
106108
DEFINE_PROTOBUF_FIELD_MAPPING(double, Double);
107109
DEFINE_PROTOBUF_FIELD_MAPPING(bool, Bool);

decibel-cpp/include/decibel/messaging/ProtobufProtocolFactory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ProtobufProtocolFactory : public IProtocolFactory
5151
{
5252
auto protocol = std::make_unique<ProtocolT>(mDispatcher);
5353
protocol->RegisterSendErrorCallback(*mSendErrorCallback);
54-
return protocol;
54+
return std::move(protocol);
5555
}
5656
else
5757
{

decibel-cpp/include/decibel/messaging/RabbitMQMessageHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RabbitMQMessageHandler : public IRabbitMQMessageHandler
1818
virtual void HandleData(AMQP::Message&& message, uint64_t, bool)
1919
{
2020
MessageType protobufMessage;
21-
protobufMessage.ParseFromString(message.message());
21+
protobufMessage.ParseFromString(std::string(message.body()));
2222
HandleMessage(std::move(protobufMessage));
2323
}
2424

decibel-cpp/include/decibel/messaging/Reactor.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace messaging
2222
class Protocol;
2323
class IProtocolFactory;
2424

25-
class Reactor : public folly::Executor, public folly::Timekeeper
25+
class Reactor : public folly::Timekeeper
2626
{
2727
public:
2828
Reactor();
@@ -70,8 +70,9 @@ class Reactor : public folly::Executor, public folly::Timekeeper
7070
return pPromise->getFuture();
7171
}
7272

73-
// folly::Executor
74-
virtual void add(folly::Func fn);
73+
// This is kept around for posterity should anyone want to add back
74+
// folly::Executor functionality
75+
// virtual void add(folly::Func fn);
7576

7677
// folly::TimeKeeper
7778
virtual folly::Future<folly::Unit> after(folly::Duration duration);

decibel-cpp/include/decibel/stdlib.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <memory>
44

5-
#ifndef __cpp_lib_make_unique
5+
#if !defined __cpp_lib_make_unique && !defined __APPLE__
66

77
namespace std
88
{

decibel-cpp/src/decibel/messaging/Reactor.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace decibel
2828
namespace messaging
2929
{
3030
Reactor::Reactor()
31-
: folly::Executor()
32-
, folly::Timekeeper()
31+
: folly::Timekeeper()
3332
, mEventLoop()
3433
, mpTimer(
3534
std::make_unique<EventLoopTimer>(niceuv::EventLoopTimer(&mEventLoop)))
@@ -153,10 +152,12 @@ void Reactor::CancelCall(std::shared_ptr<OneShotTimerEvent> pTimer)
153152
pTimer->Stop();
154153
}
155154

156-
void Reactor::add(folly::Func fn)
157-
{
158-
CallSoon(fn);
159-
}
155+
// This is kept around for posterity should anyone want to add back
156+
// folly::Executor functionality
157+
// void Reactor::add(folly::Func fn)
158+
// {
159+
// CallSoon(fn);
160+
// }
160161

161162
folly::Future<folly::Unit> Reactor::after(folly::Duration duration)
162163
{

decibel-cpp/src/decibel/messaging/TcpServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TcpServer::TcpServer(niceuv::EventLoop* loop,
2323
: mServer(new niceuv::TcpServer(loop)), mProtocols()
2424
{
2525
auto connectCb = [factory, this, host, port](niceuv::TcpConnPtr conn) {
26-
auto pProtocol = std::move(factory->Construct());
26+
auto pProtocol = factory->Construct();
2727
auto rawpConn = conn.get();
2828
auto pTransport =
2929
std::make_unique<TcpTransport>(std::move(conn), host, port);

decibel-cpp/src/decibel/niceuv/WorkCancellable.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "decibel/niceuv/WorkCancellable.h"
22

3+
#include <exception>
4+
#include <stdexcept>
5+
36
namespace decibel
47
{
58
namespace niceuv

decibel-cpp/test/test_reactor.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ TEST(TestSelfConnectMultiClients, ConnectTcp)
153153
ASSERT_EQ(1, rawpProto2->mConnectionLostCalls);
154154
}
155155

156-
TEST(TestReactor, FollyExecutorAdd)
157-
{
158-
dm::Reactor r;
159-
bool then_called = false;
160-
auto fut = folly::makeFuture().via(&r).then([&]() { then_called = true; });
161-
ASSERT_FALSE(then_called);
162-
r.Start();
163-
ASSERT_TRUE(then_called);
164-
}
156+
// This is kept around for posterity should anyone want to add back
157+
// folly::Executor functionality
158+
// TEST(TestReactor, FollyExecutorAdd)
159+
// {
160+
// dm::Reactor r;
161+
// bool then_called = false;
162+
// auto fut = folly::makeFuture().via(&r).then([&]() { then_called = true; });
163+
// ASSERT_FALSE(then_called);
164+
// r.Start();
165+
// ASSERT_TRUE(then_called);
166+
// }

src/ConfigTypes.h

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ class ConfigValue
7373
}
7474
}
7575

76+
template <typename T>
77+
ConfigType<T> ToConfigType() const
78+
{
79+
BOOST_ASSERT_MSG(!mEmpty, "Can't dereference Empty Value");
80+
try
81+
{
82+
return boost::get<ConfigType<T>>(mValue);
83+
}
84+
catch (const boost::bad_get& ex)
85+
{
86+
BOOST_ASSERT_MSG(false, "Requested incorrect type from variant");
87+
return ConfigType<T>({});
88+
}
89+
}
90+
7691
template <typename T>
7792
bool Is() const
7893
{

src/LocalYAMLStorage.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ namespace
2525
namespace dm = decibel::messaging;
2626
namespace bfs = boost::filesystem;
2727

28+
namespace YAML
29+
{
30+
31+
Node convert<ConfigType<std::vector<bool>>>::encode(const ConfigType<std::vector<bool>>& val)
32+
{
33+
Node output;
34+
for (const auto& iter : val.mValue)
35+
{
36+
output.push_back(bool(iter));
37+
}
38+
return output;
39+
}
40+
41+
}
42+
2843
YAML::Node LoadOrCreate(boost::filesystem::path path)
2944
{
3045
YAML::Node config;

src/LocalYAMLStorage.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212

1313
#include <yaml-cpp/yaml.h>
1414

15+
// Strictly speaking, this specialization is only necessary on macOS. The C++ headers included
16+
// in osx are opinionated enough about the bool vector specialization that they don't use
17+
// the same proxy reference methodology the gnu stdlib uses, or something like that.
18+
// Subsequently, we need to do this bool casting badness to get yaml-cpp's assignment to work
19+
// Chere here for more details: https://stackoverflow.com/questions/31974237/why-is-libcs-vectorboolconst-reference-not-bool
20+
namespace YAML
21+
{
22+
23+
template<>
24+
struct convert<ConfigType<std::vector<bool>>>
25+
{
26+
static Node encode(const ConfigType<std::vector<bool>>& val);
27+
};
28+
29+
}
30+
1531
#define DYNAMIC_UNPACK(value, storage) \
1632
if (value.Is<int32_t>()) \
1733
{ \
@@ -35,7 +51,7 @@
3551
} \
3652
else if (value.Is<std::vector<bool>>()) \
3753
{ \
38-
storage = value.Unpack<std::vector<bool>>(); \
54+
storage = value.ToConfigType<std::vector<bool>>(); \
3955
}
4056

4157
std::pair<boost::filesystem::path, std::string> TranslateKeyToPathPair(const ConfigPair::Key& key);

0 commit comments

Comments
 (0)