*/
#include <filesystem>
+#include <fstream>
+#include <iostream>
#include "declarations.h"
bool generate_rust_source_one_file(
__attribute__((unused)) const Declarations& decls,
- __attribute__((unused)) const std::filesystem::path& input_file,
- __attribute__((unused)) const std::filesystem::path& include_dir,
- __attribute__((unused)) const std::filesystem::path& out_dir,
+ const std::filesystem::path& input_file,
+ const std::filesystem::path& include_dir,
+ const std::filesystem::path& out_dir,
__attribute__((unused)) const std::string& root_namespace) {
- // TODO do fun things
+ auto gen_relative_path = input_file.lexically_relative(include_dir).parent_path();
+
+ auto input_filename = input_file.filename().string().substr(0, input_file.filename().string().find(".pdl"));
+ auto gen_path = out_dir / gen_relative_path;
+
+ std::filesystem::create_directories(gen_path);
+
+ auto gen_file = gen_path / (input_filename + ".rs");
+
+ std::cout << "generating " << gen_file << std::endl;
+
+ std::ofstream out_file;
+ out_file.open(gen_file);
+ if (!out_file.is_open()) {
+ std::cerr << "can't open " << gen_file << std::endl;
+ return false;
+ }
+
+ out_file << "// @generated rust packets from " << input_file.filename().string();
+
+ out_file.close();
return true;
}