blob: 9af4d83e1f8fd7aab2ce52bdcbd76c28e0e3b6bf [file] [log] [blame]
Adam Snaider48a62f32023-10-02 15:49:23 -07001#include "aos/init_for_rust.h"
2
3#include "gflags/gflags.h"
4#include "glog/logging.h"
5
6#include "aos/init.h"
7
8namespace aos {
9
10void InitFromRust(const char *argv0) {
11 CHECK(!IsInitialized()) << "Only initialize once.";
12
13 google::InitGoogleLogging(argv0);
14
15 // TODO(Brian): Where should Rust binaries be configured to write coredumps?
16
17 // TODO(Brian): Figure out what to do with allocator hooks for C++ and Rust.
18
19 MarkInitialized();
20}
21
22std::vector<FlagInfo> GetCppFlags() {
23 std::vector<gflags::CommandLineFlagInfo> info;
24 gflags::GetAllFlags(&info);
25 std::vector<FlagInfo> out;
26 for (const auto &flag : info) {
27 FlagInfo out_flag = {
28 .name_ = flag.name,
29 .type_ = flag.type,
30 .description_ = flag.description,
31 .default_value_ = flag.default_value,
32 .filename_ = flag.filename,
33 };
34 out.push_back(out_flag);
35 }
36 return out;
37}
38
39bool SetCommandLineOption(const char *name, const char *value) {
40 return !gflags::SetCommandLineOption(name, value).empty();
41}
42
43std::string GetCommandLineOption(const char *name) {
44 std::string out;
45 CHECK(gflags::GetCommandLineOption(name, &out)) << "Unknown flag " << name;
46 return out;
47}
48
49} // namespace aos