Update FlatBuffers codegen script for Nyma cores

uses latest (they switched from SemVer to dates, so 22.9.24 follows 2.0.8)
works on real Linux, using Nix if installed
This commit is contained in:
YoshiRulz 2022-09-28 07:51:49 +10:00
parent ddac50eb30
commit cf0053fd3c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 43 additions and 2 deletions

22
waterbox/nyma/run-flatc.sh Normal file → Executable file
View File

@ -1,3 +1,21 @@
#!/bin/sh
./flatc --cpp --gen-object-api NymaTypes.fbs
./flatc --csharp --gen-object-api -o ../../ExternalProjects/FlatBuffers.GenOutput NymaTypes.fbs
if ( uname -s | fgrep -i cygwin ); then
flatc=./flatc
else
flatc="$(command -v flatc)"
if [ -z "$flatc" ]; then
if ! ( command -v nix >/dev/null ); then
printf "You do not have flatc (the FlatBuffers schema compiler) installed.\nIf it's not available from your package manager, you will have to build from source:\n%s\n" "https://google.github.io/flatbuffers/flatbuffers_guide_building.html"
exit 1
fi
printf "Grabbing flatc via Nix...\n"
nix-shell --run "$0"
exit $?
fi
fi
"$flatc" --cpp --gen-object-api NymaTypes.fbs
"$flatc" --csharp --gen-object-api -o ../../ExternalProjects/FlatBuffers.GenOutput NymaTypes.fbs
if ! ( uname -s | fgrep -i cygwin ); then
unix2dos NymaTypes_generated.h
unix2dos ../../ExternalProjects/FlatBuffers.GenOutput/NymaTypes/*
fi

23
waterbox/nyma/shell.nix Normal file
View File

@ -0,0 +1,23 @@
{ pkgs ? import <nixpkgs> {} }:
let
versionAtLeast = exVer: acVer: builtins.compareVersions exVer acVer <= 0;
flatbuffersPatched = pkgs.flatbuffers.overrideAttrs (oldAttrs: {
version = "22.9.24";
src = pkgs.fetchFromGitHub {
owner = "google";
repo = "flatbuffers";
rev = "76ddae006f6e5068d2f26f235dbd167bd826a698";
sha256 = "1vycd1641id476qhmkrgdfiisxx7n2zn54p3r6nva6dm0bd58lc8";
};
patches = []; # single patch has since been merged upstream
postPatch = ''
# Fix default value of "test_data_path" to make tests work
substituteInPlace tests/test.cpp --replace '"tests/";' '"../tests/";'
'';
});
flatbuffersFinal = if versionAtLeast "22.9.24" pkgs.flatbuffers.version
then pkgs.flatbuffers
else assert versionAtLeast "2.0.0" pkgs.flatbuffers.version; flatbuffersPatched; # need base of >= Nixpkgs 21.11
in pkgs.mkShell {
packages = [ flatbuffersFinal ];
}