Skip to content

Commit

Permalink
Merge pull request #763 from davidgiven/protos
Browse files Browse the repository at this point in the history
Encode all the protos in one go (per library), as it's vastly faster.
  • Loading branch information
davidgiven authored Aug 12, 2024
2 parents 7a3a31a + dc6af48 commit 3c3d8d0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ choices because they can store multiple types of file system.
| [`rolandd20`](doc/disk-rolandd20.md) | Roland D20: 3.5" electronic synthesiser disks | 🦄 | 🦖 | ROLAND |
| [`rx50`](doc/disk-rx50.md) | Digital RX50: 400kB 5.25" 80-track 10-sector SSDD | 🦖 | 🦖 | |
| [`smaky6`](doc/disk-smaky6.md) | Smaky 6: 308kB 5.25" 77-track 16-sector SSDD, hard sectored | 🦖 | | SMAKY6 |
| [`tartu`](doc/disk-tartu.md) | Tartu: The Palivere and variations | 🦄 | | CPMFS |
| [`tartu`](doc/disk-tartu.md) | Tartu: The Palivere and variations | 🦄 | 🦖 | CPMFS |
| [`tids990`](doc/disk-tids990.md) | Texas Instruments DS990: 1126kB 8" DSSD | 🦖 | 🦖 | |
| [`tiki`](doc/disk-tiki.md) | Tiki 100: CP/M | | | CPMFS |
| [`victor9k`](doc/disk-victor9k.md) | Victor 9000 / Sirius One: 1224kB 5.25" DSDD GCR | 🦖 | 🦖 | |
Expand Down
2 changes: 1 addition & 1 deletion doc/disk-tartu.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ density, using MFM and with up to 780kB on a double-sided 80 track disk.
<img src="tartu-fdc.jpg" alt="The Tartu FDC with Soviet TTL logic chips."/>
</div>

FluxEngine supports reading Tartu disks with CP/M filesystem access.
FluxEngine supports reading and writing Tartu disks with CP/M filesystem access.

## Options

Expand Down
25 changes: 23 additions & 2 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from build.ab import Rule, normalrule, Targets
from build.ab import Rule, normalrule, Targets, TargetsMap
from build.c import cxxprogram, HostToolchain

encoders = {}


@Rule
def protoencode(self, name, srcs: Targets, proto, symbol):
def protoencode_single(self, name, srcs: Targets, proto, symbol):
if proto not in encoders:
r = cxxprogram(
name="protoencode_" + proto,
Expand Down Expand Up @@ -34,6 +34,27 @@ def protoencode(self, name, srcs: Targets, proto, symbol):
)


@Rule
def protoencode(self, name, proto, srcs: TargetsMap, symbol):
encoded = [
protoencode_single(
name=f"{k}_cc",
srcs=[v],
proto=proto,
symbol=f"{symbol}_{k}_pb",
)
for k, v in srcs.items()
]

normalrule(
replaces=self,
ins=encoded,
outs=[name + ".cc"],
commands=["cat {ins} > {outs}"],
label="CONCAT",
)


cxxprogram(
name="mkdoc",
srcs=["./mkdoc.cc"],
Expand Down
13 changes: 7 additions & 6 deletions scripts/protoencode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ int main(int argc, const char* argv[])
}

auto data = message.SerializeAsString();
auto name = argv[3];

output << "#include \"lib/globals.h\"\n"
<< "#include \"lib/proto.h\"\n"
<< "#include <string_view>\n"
<< "static const uint8_t rawData[] = {";
<< "static const uint8_t " << name << "_rawData[] = {";

int count = 0;
for (char c : data)
Expand All @@ -140,12 +141,12 @@ int main(int argc, const char* argv[])
}

output << "\n};\n";
output << "extern const std::string_view " << argv[3] << "_data;\n";
output << "const std::string_view " << argv[3]
<< "_data = std::string_view((const char*)rawData, " << data.size()
output << "extern const std::string_view " << name << "_data;\n";
output << "const std::string_view " << name
<< "_data = std::string_view((const char*)" << name << "_rawData, " << data.size()
<< ");\n";
output << "extern const ConfigProto " << argv[3] << ";\n";
output << "const ConfigProto " << argv[3] << " = parseConfigBytes("
output << "extern const ConfigProto " << name << ";\n";
output << "const ConfigProto " << name << " = parseConfigBytes("
<< argv[3] << "_data);\n";

return 0;
Expand Down
17 changes: 7 additions & 10 deletions src/formats/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@
label="MKTABLE",
)

encoded = [
protoencode(
name=f"{name}_cc",
srcs=[f"./{name}.textpb"],
proto="ConfigProto",
symbol=f"formats_{name}_pb",
)
for name in formats
]
protoencode(
name="formats_cc",
srcs={name: f"./{name}.textpb" for name in formats},
proto="ConfigProto",
symbol="formats",
)

cxxlibrary(
name="formats",
srcs=[".+table_cc"] + encoded,
srcs=[".+formats_cc", ".+table_cc"],
deps=["+lib", "lib+config_proto_lib"],
)

Expand Down
24 changes: 13 additions & 11 deletions src/gui/drivetypes/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]

normalrule(
name="drivetypes_cc",
name="drivetypes_table_cc",
ins=[f"./{name}.textpb" for name in drivetypes],
deps=["scripts/mktable.sh"],
outs=["table.cc"],
Expand All @@ -21,14 +21,16 @@
label="MKTABLE",
)

encoded = [
protoencode(
name=f"{name}_cc",
srcs=[f"./{name}.textpb"],
proto="ConfigProto",
symbol=f"drivetypes_{name}_pb",
)
for name in drivetypes
]

cxxlibrary(name="drivetypes", srcs=[".+drivetypes_cc"] + encoded, deps=["+lib"])
protoencode(
name="drivetypes_cc",
srcs={name: f"./{name}.textpb" for name in drivetypes},
proto="ConfigProto",
symbol="drivetypes",
)

cxxlibrary(
name="drivetypes",
srcs=[".+drivetypes_cc", ".+drivetypes_table_cc"],
deps=["+lib"],
)
4 changes: 2 additions & 2 deletions tests/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from build.c import cxxprogram
from build.protobuf import proto, protocc
from build.utils import test
from scripts.build import protoencode
from scripts.build import protoencode_single


proto(
Expand Down Expand Up @@ -49,7 +49,7 @@
name="proto_test_exe",
srcs=[
"./proto.cc",
protoencode(
protoencode_single(
name="testproto_cc",
srcs=["./testproto.textpb"],
proto="TestProto",
Expand Down

0 comments on commit 3c3d8d0

Please sign in to comment.