Skip to content

Commit 9d0a777

Browse files
authored
Merge pull request #67 from rtbot-dev/RB-214
RB-214 Implement serialization of the state of an rtbot program
2 parents 76fc2b7 + deb7bfb commit 9d0a777

File tree

89 files changed

+1350
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1350
-336
lines changed

.bazelrc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ test --notest_verbose_timeout_warnings
1919
build --action_env=EMCC_CFLAGS="-fexceptions -Wno-c++11-narrowing -Wno-unused-const-variable"
2020
build --incompatible_enable_cc_toolchain_resolution
2121

22+
build --enable_platform_specific_config
23+
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
24+
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
25+
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain
2226

2327
# -- platform specific --
24-
# linux
25-
build:linux --workspace_status_command=tools/bazel_workspace_status.sh
26-
build:linux --action_env=BAZEL_CXXOPTS="-std=c++17"
27-
28-
# macos
29-
build:macos --workspace_status_command=tools/bazel_workspace_status.sh
30-
build:macos --cxxopt='-std=c++17'
28+
# unix
29+
build --workspace_status_command=tools/bazel_workspace_status.sh
30+
build --action_env=BAZEL_CXXOPTS="-std=c++17"
31+
build --cxxopt=-std=c++17
32+
build --repo_env=CC=clang
3133

3234
# windows
3335
# MSVC
3436
build:windows --cxxopt='/std:c++17'
3537
# see https://bazel.build/configure/windows
3638
startup --windows_enable_symlinks
3739

40+
# allow to use network while building
41+
build --sandbox_default_allow_network
3842

.clangd

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# this file is added mainly for intellisense purposes
2+
If:
3+
PathMatch: .*\.h
4+
CompileFlags:
5+
Add:
6+
- -DLOCAL
7+
- -Wall
8+
- -O2
9+
- -Wextra
10+
- -Wshadow
11+
- -Wconversion
12+
- -Wfloat-equal
13+
- -Wno-unused-const-variable
14+
- -Wno-sign-conversion
15+
- -std=c++17
16+
- -I./dist/bin/libs/api/proto
17+
- -I./libs/api/include
18+
- -I./libs/core/include
19+
- -I./libs/std/include
20+
Index:
21+
Background: Skip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ venv/
4343
settings.json
4444
.firebase
4545
.envrc
46+
compile_commands.json

WORKSPACE

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@ load("//:deps.bzl", "deps")
44

55
deps()
66

7+
load(
8+
"@build_bazel_apple_support//lib:repositories.bzl",
9+
"apple_support_dependencies",
10+
)
11+
12+
apple_support_dependencies()
13+
14+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
15+
16+
bazel_features_deps()
17+
18+
load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains")
19+
20+
rules_buf_dependencies()
21+
22+
rules_buf_toolchains(
23+
version = "v1.32.1",
24+
)
25+
26+
# rules_proto
27+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
28+
29+
rules_proto_dependencies()
30+
31+
load("@rules_proto//proto:setup.bzl", "rules_proto_setup")
32+
33+
rules_proto_setup()
34+
35+
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
36+
37+
rules_proto_toolchains()
38+
39+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
40+
41+
protobuf_deps()
42+
743
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
844

945
python_configure(
@@ -27,7 +63,7 @@ load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
2763

2864
nodejs_register_toolchains(
2965
name = "nodejs",
30-
node_version = '18.13.0',
66+
node_version = "18.13.0",
3167
)
3268

3369
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

deps.bzl

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ def deps():
115115
strip_prefix = "bazel-lib-1.34.0",
116116
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.34.0/bazel-lib-v1.34.0.tar.gz",
117117
)
118-
118+
119119
http_archive(
120120
name = "emsdk",
121-
strip_prefix = "emsdk-3.1.34/bazel",
122-
sha256 = "e03ed88f9f8075c78f49c43241e3586798300593e7ea873f766e9403e662516c",
123-
url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.34.tar.gz",
121+
sha256 = "97f21c32c0c1eecb963d19d1cacf58538086ce28eb28274993ab21d3673b5c29",
122+
strip_prefix = "emsdk-3.1.68/bazel",
123+
url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.68.tar.gz",
124124
)
125125

126126
http_archive(
@@ -142,3 +142,42 @@ def deps():
142142
sha256 = "aeec52381284ec3752505a220d36096954c869da4573c2e1df3642d2f0a4aac6",
143143
strip_prefix = "benchmark-1.7.1",
144144
)
145+
146+
http_archive(
147+
name = "build_bazel_apple_support",
148+
sha256 = "b53f6491e742549f13866628ddffcc75d1f3b2d6987dc4f14a16b242113c890b",
149+
url = "https://github.com/bazelbuild/apple_support/releases/download/1.17.1/apple_support.1.17.1.tar.gz",
150+
)
151+
152+
http_archive(
153+
name = "com_google_protobuf",
154+
# notice that when we change the version here we also have to change the version as well for
155+
# the buf plugin buf.build/protocolbuffers/cpp in the files:
156+
# - libs/api/proto/buf.gen.yaml
157+
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protobuf-27.3.zip",
158+
strip_prefix = "protobuf-27.3",
159+
sha256 = "a49147217f69e8d19aab0cc5c0059d6201261f5cb62145f8ab4ac8b94e7ffa86",
160+
)
161+
162+
http_archive(
163+
name = "rules_buf",
164+
integrity = "sha256-Hr64Q/CaYr0E3ptAjEOgdZd1yc+cBjp7OG1wzuf3DIs=",
165+
strip_prefix = "rules_buf-0.3.0",
166+
urls = [
167+
"https://github.com/bufbuild/rules_buf/archive/refs/tags/v0.3.0.zip",
168+
],
169+
)
170+
171+
http_archive(
172+
name = "rules_proto",
173+
sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
174+
strip_prefix = "rules_proto-6.0.2",
175+
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
176+
)
177+
178+
http_archive(
179+
name = "protovalidate",
180+
sha256 = "6e49ffdf4502d32472b568cf1b279d113cc8548ffb19134f800f903d5148184b",
181+
url = "https://github.com/bufbuild/protovalidate/archive/refs/tags/v0.8.2.zip",
182+
strip_prefix = "protovalidate-0.8.2",
183+
)

libs/api/BUILD.bazel

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
22
load("@rules_cc//cc:defs.bzl", "cc_library")
33
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
4-
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
4+
load("@aspect_rules_js//npm:defs.bzl", "npm_package", "stamped_package_json")
55
load("//tools/generator:generator.bzl", "rtbot_generate")
6-
load("@aspect_rules_js//npm:defs.bzl", "stamped_package_json")
76

87
package(default_visibility = ["//visibility:public"])
98

@@ -38,8 +37,9 @@ cc_library(
3837
includes = ["include"],
3938
visibility = ["//visibility:public"],
4039
deps = [
41-
"//libs/finance:rtbot-finance",
40+
"//libs/api/proto",
4241
"//libs/core:rtbot",
42+
"//libs/finance:rtbot-finance",
4343
"//libs/std:rtbot-std",
4444
"@json-cpp//:lib",
4545
"@json-schema-validator//:lib",
@@ -50,11 +50,13 @@ cc_library(
5050
BASE_LINKOPTS = [
5151
"-O3",
5252
"-lembind", # Enable embind
53-
"-s MODULARIZE",
54-
"--embind-emit-tsd",
55-
"-s ALLOW_MEMORY_GROWTH",
53+
"-sMODULARIZE",
54+
# TODO: enable typescript emit, although this is non blocking
55+
#"--emit-tsd",
56+
"-sALLOW_MEMORY_GROWTH",
5657
#"-s MEMORY64=2",
57-
"-s NO_DISABLE_EXCEPTION_CATCHING",
58+
"-sWASM_BIGINT",
59+
"-sNO_DISABLE_EXCEPTION_CATCHING",
5860
#"-s EXPORT_ES6=1",
5961
]
6062

@@ -101,14 +103,14 @@ stamped_package_json(
101103
npm_package(
102104
name = "js",
103105
srcs = [
104-
":package",
105106
":declarations",
107+
":package",
106108
":rtbot-wasm",
107109
],
110+
# this is needed if we want to use this package in another bazel workspace
111+
include_external_repositories = ["**"],
108112
package = "@rtbot-dev/wasm",
109113
replace_prefixes = {
110-
"rtbot-wasm": "."
114+
"rtbot-wasm": ".",
111115
},
112-
# this is needed if we want to use this package in another bazel workspace
113-
include_external_repositories = ["**"]
114116
)

libs/api/include/rtbot/FactoryOp.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using namespace std;
1616

1717
class FactoryOp {
1818
map<string, Program> programs;
19-
map<string, map<string, vector<Message<uint64_t, double>>>> messageBuffer;
19+
ProgramMessage<uint64_t, double> messageBuffer;
2020

2121
public:
2222
FactoryOp();
@@ -54,8 +54,13 @@ class FactoryOp {
5454

5555
static Op_ptr<uint64_t, double> readOp(string const& json_string);
5656
static string writeOp(Op_ptr<uint64_t, double> const& op);
57+
5758
static Program createProgram(string const& json_string) { return Program(json_string); }
5859

60+
Bytes serialize(string const& programId);
61+
62+
string createProgram(string const& id, Bytes const& bytes);
63+
5964
string createProgram(string const& id, string const& json_program);
6065

6166
bool deleteProgram(string const& id) { return (programs.erase(id) == 1) ? true : false; }
@@ -66,7 +71,7 @@ class FactoryOp {
6671
return true;
6772
}
6873

69-
map<string, map<string, vector<Message<uint64_t, double>>>> processMessageBuffer(const string& apId) {
74+
ProgramMessage<uint64_t, double> processMessageBuffer(const string& apId) {
7075
if (this->programs.count(apId) == 0) throw runtime_error("Program " + apId + " was not found");
7176
if (this->messageBuffer.count(apId) > 0) {
7277
if (!this->messageBuffer.at(apId).empty()) {
@@ -79,7 +84,7 @@ class FactoryOp {
7984
return {};
8085
}
8186

82-
map<string, map<string, vector<Message<uint64_t, double>>>> processMessageBufferDebug(const string& apId) {
87+
ProgramMessage<uint64_t, double> processMessageBufferDebug(const string& apId) {
8388
if (this->programs.count(apId) == 0) throw runtime_error("Program " + apId + " was not found");
8489
if (this->messageBuffer.count(apId) > 0) {
8590
if (!this->messageBuffer.at(apId).empty()) {
@@ -107,15 +112,15 @@ class FactoryOp {
107112
return this->programs.at(apId).getProgramOutputFilter();
108113
}
109114

110-
map<string, map<string, vector<Message<uint64_t, double>>>> processMessageMap(
111-
string const& apId, const map<string, vector<Message<uint64_t, double>>>& messagesMap) {
115+
ProgramMessage<uint64_t, double> processMessageMap(string const& apId,
116+
const OperatorMessage<uint64_t, double>& messagesMap) {
112117
auto it = programs.find(apId);
113118
if (it == programs.end()) return {};
114119
return it->second.receive(messagesMap);
115120
}
116121

117-
map<string, map<string, vector<Message<uint64_t, double>>>> processMessageMapDebug(
118-
string const& apId, const map<string, vector<Message<uint64_t, double>>>& messagesMap) {
122+
ProgramMessage<uint64_t, double> processMessageMapDebug(string const& apId,
123+
const OperatorMessage<uint64_t, double>& messagesMap) {
119124
auto it = programs.find(apId);
120125
if (it == programs.end()) return {};
121126
return it->second.receiveDebug(messagesMap);

0 commit comments

Comments
 (0)