From 774fc54355abe70a1ba045ade99649ba0e98c930 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:17:26 +1000 Subject: start adding rust bindgen --- scripts/amalgamation/gen_amalgamation.py | 55 ++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'scripts/amalgamation/gen_amalgamation.py') diff --git a/scripts/amalgamation/gen_amalgamation.py b/scripts/amalgamation/gen_amalgamation.py index 45a1c21..4a4d946 100644 --- a/scripts/amalgamation/gen_amalgamation.py +++ b/scripts/amalgamation/gen_amalgamation.py @@ -2,23 +2,58 @@ # # This makes including and linking Celeritas very easy. import re -import sys +import os +from pathlib import Path -def find_pub_functions(filepath): +categories = { + "RAL": "src/ral", + "Render": "src/new_render", + "Maths": "src/maths" +} + +def find_pub_functions_in_folder(folder_path): + functions = [] + for filename in os.listdir(folder_path): + filepath = os.path.join(folder_path, filename) + if os.path.isfile(filepath): + file_funcs = find_pub_functions_in_file(filepath) + functions.extend(file_funcs) + + return functions + +def find_pub_functions_in_file(file_path): pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)' - with open(filepath, 'r') as file: + with open(file_path, 'r') as file: content = file.read() matches = re.finditer(pattern, content, re.MULTILINE) + # Collect all the functions into an array + functions = [] for match in matches: - print(match.group(0)) + signature = match.group(0) + if signature.startswith("PUB "): + signature = signature[4:] -if __name__ == "__main__": - if len(sys.argv) != 2: - print("Usage: python script.py ") - sys.exit(1) + print(signature) + functions.append(signature) + + return functions - file_path = sys.argv[1] - find_pub_functions(file_path) +def generate_header(): + header_path = "celeritas.h" + + script_dir = Path(__file__).resolve().parent + grandparent_dir = script_dir.parents[1] + + with open(header_path, 'w') as export_file: + for category in categories.keys(): + folder = os.path.join(grandparent_dir, categories[category]) + category_funcs = find_pub_functions_in_folder(folder) + for func in category_funcs: + export_file.write(func) + export_file.write(';\n') + +if __name__ == "__main__": + generate_header() -- cgit v1.2.3-70-g09d2