From b0691ad81eb51d9f9e3231fe2f24eef0d3a2553d Mon Sep 17 00:00:00 2001
From: Millian Poquet <millian.poquet@irit.fr>
Date: Tue, 8 Nov 2022 14:46:57 +0100
Subject: [PATCH] protobuf + nix setup

---
 .gitignore           |  2 ++
 default.nix          | 29 +++++++++++++++++++++++++++++
 protocol/hello.proto | 10 ++++++++++
 protocol/meson.build | 21 +++++++++++++++++++++
 4 files changed, 62 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 default.nix
 create mode 100644 protocol/hello.proto
 create mode 100644 protocol/meson.build

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..02f1769
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+result
+.vscode
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..0119eec
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,29 @@
+{ pkgs ? import (fetchTarball {
+    url = "https://github.com/NixOS/nixpkgs/archive/22.05.tar.gz";
+    sha256 = "0d643wp3l77hv2pmg2fi7vyxn4rwy0iyr8djcw1h5x72315ck9ik";
+  }) {}
+}:
+
+let self = rec {
+  pythonPackages = pkgs.python3Packages;
+  simgrid = pkgs.simgrid;
+  protocol-cpp = pkgs.stdenv.mkDerivation {
+    pname = "protocol-cpp";
+    version = "local";
+    src = pkgs.lib.sourceByRegex ./protocol [
+      "hello\.proto"
+      "meson\.build"
+    ];
+    propagatedBuildInputs = with pkgs; [
+      protobuf
+    ];
+    buildInputs = with pkgs; [
+      meson
+      pkg-config
+      ninja
+    ];
+  };
+
+};
+in
+  self
diff --git a/protocol/hello.proto b/protocol/hello.proto
new file mode 100644
index 0000000..2022766
--- /dev/null
+++ b/protocol/hello.proto
@@ -0,0 +1,10 @@
+syntax = "proto2";
+
+package hello;
+
+message Hello {
+  optional string name = 1;
+}
+
+message Bye {
+}
diff --git a/protocol/meson.build b/protocol/meson.build
new file mode 100644
index 0000000..747eac1
--- /dev/null
+++ b/protocol/meson.build
@@ -0,0 +1,21 @@
+project('protocol-cpp', 'cpp', version: '0.1.0', default_options: ['cpp_std=c++17'])
+
+protoc = find_program('protoc', required: true)
+protobuf_dep = dependency('protobuf', required: true)
+
+gen = generator(protoc, \
+  output    : ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
+  arguments : ['--proto_path=@CURRENT_SOURCE_DIR@', '--cpp_out=@BUILD_DIR@', '@INPUT@'])
+
+proto_generated_cpp = custom_target('protobuf-generated-sources',
+    input: ['hello.proto'],
+    output: ['hello.pb.h', 'hello.pb.cc'],
+    command: [protoc, '--proto_path=@CURRENT_SOURCE_DIR@', '--cpp_out=@OUTDIR@', '@INPUT@'],
+    install: true,
+    install_dir: [get_option('includedir'), false],
+)
+
+lib = shared_library('protocol', proto_generated_cpp, dependencies: protobuf_dep, install: true)
+
+pkg = import('pkgconfig')
+pkg.generate(lib)
-- 
GitLab