Add build files and generator script Adds a `generate_build_files.py` script that is used to generate build files for use in bazel, cmake, and GN. Additionally a clean json file is added for more generic usage. These files are intended to be included in downstream build systems to explicitly list out the files required by embossc and the C++ runtime. The generated build files are included as well.
diff --git a/gen/sources.bzl b/gen/sources.bzl new file mode 100644 index 0000000..3a1f135 --- /dev/null +++ b/gen/sources.bzl
@@ -0,0 +1,83 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Automatically generated by generate_build_files.py. +# Do not edit this file directly. + +EMBOSSC_SOURCES = [ + "compiler/__init__.py", + "compiler/back_end/__init__.py", + "compiler/back_end/cpp/__init__.py", + "compiler/back_end/cpp/attributes.py", + "compiler/back_end/cpp/emboss_codegen_cpp.py", + "compiler/back_end/cpp/generated_code_templates", + "compiler/back_end/cpp/header_generator.py", + "compiler/back_end/util/__init__.py", + "compiler/back_end/util/code_template.py", + "compiler/front_end/__init__.py", + "compiler/front_end/attribute_checker.py", + "compiler/front_end/attributes.py", + "compiler/front_end/constraints.py", + "compiler/front_end/dependency_checker.py", + "compiler/front_end/emboss_front_end.py", + "compiler/front_end/error_examples", + "compiler/front_end/expression_bounds.py", + "compiler/front_end/generated/cached_parser.py", + "compiler/front_end/glue.py", + "compiler/front_end/lr1.py", + "compiler/front_end/make_parser.py", + "compiler/front_end/module_ir.py", + "compiler/front_end/parser.py", + "compiler/front_end/prelude.emb", + "compiler/front_end/reserved_words", + "compiler/front_end/symbol_resolver.py", + "compiler/front_end/synthetics.py", + "compiler/front_end/tokenizer.py", + "compiler/front_end/type_check.py", + "compiler/front_end/write_inference.py", + "compiler/util/__init__.py", + "compiler/util/attribute_util.py", + "compiler/util/error.py", + "compiler/util/expression_parser.py", + "compiler/util/ir_data.py", + "compiler/util/ir_data_fields.py", + "compiler/util/ir_data_utils.py", + "compiler/util/ir_util.py", + "compiler/util/name_conversion.py", + "compiler/util/parser_types.py", + "compiler/util/parser_util.py", + "compiler/util/resources.py", + "compiler/util/simple_memoizer.py", + "compiler/util/traverse_ir.py", + "embossc", +] + +EMBOSS_RUNTIME_CPP_SOURCES = [ + "runtime/cpp/emboss_arithmetic.h", + "runtime/cpp/emboss_arithmetic_all_known_generated.h", + "runtime/cpp/emboss_arithmetic_maximum_operation_generated.h", + "runtime/cpp/emboss_array_view.h", + "runtime/cpp/emboss_bit_util.h", + "runtime/cpp/emboss_constant_view.h", + "runtime/cpp/emboss_cpp_types.h", + "runtime/cpp/emboss_cpp_util.h", + "runtime/cpp/emboss_defines.h", + "runtime/cpp/emboss_enum_view.h", + "runtime/cpp/emboss_maybe.h", + "runtime/cpp/emboss_memory_util.h", + "runtime/cpp/emboss_prelude.h", + "runtime/cpp/emboss_text_util.h", + "runtime/cpp/emboss_view_parameters.h", +]
diff --git a/gen/sources.cmake b/gen/sources.cmake new file mode 100644 index 0000000..60d009b --- /dev/null +++ b/gen/sources.cmake
@@ -0,0 +1,83 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Automatically generated by generate_build_files.py. +# Do not edit this file directly. + +set(EMBOSSC_SOURCES + "compiler/__init__.py" + "compiler/back_end/__init__.py" + "compiler/back_end/cpp/__init__.py" + "compiler/back_end/cpp/attributes.py" + "compiler/back_end/cpp/emboss_codegen_cpp.py" + "compiler/back_end/cpp/generated_code_templates" + "compiler/back_end/cpp/header_generator.py" + "compiler/back_end/util/__init__.py" + "compiler/back_end/util/code_template.py" + "compiler/front_end/__init__.py" + "compiler/front_end/attribute_checker.py" + "compiler/front_end/attributes.py" + "compiler/front_end/constraints.py" + "compiler/front_end/dependency_checker.py" + "compiler/front_end/emboss_front_end.py" + "compiler/front_end/error_examples" + "compiler/front_end/expression_bounds.py" + "compiler/front_end/generated/cached_parser.py" + "compiler/front_end/glue.py" + "compiler/front_end/lr1.py" + "compiler/front_end/make_parser.py" + "compiler/front_end/module_ir.py" + "compiler/front_end/parser.py" + "compiler/front_end/prelude.emb" + "compiler/front_end/reserved_words" + "compiler/front_end/symbol_resolver.py" + "compiler/front_end/synthetics.py" + "compiler/front_end/tokenizer.py" + "compiler/front_end/type_check.py" + "compiler/front_end/write_inference.py" + "compiler/util/__init__.py" + "compiler/util/attribute_util.py" + "compiler/util/error.py" + "compiler/util/expression_parser.py" + "compiler/util/ir_data.py" + "compiler/util/ir_data_fields.py" + "compiler/util/ir_data_utils.py" + "compiler/util/ir_util.py" + "compiler/util/name_conversion.py" + "compiler/util/parser_types.py" + "compiler/util/parser_util.py" + "compiler/util/resources.py" + "compiler/util/simple_memoizer.py" + "compiler/util/traverse_ir.py" + "embossc" +) + +set(EMBOSS_RUNTIME_CPP_SOURCES + "runtime/cpp/emboss_arithmetic.h" + "runtime/cpp/emboss_arithmetic_all_known_generated.h" + "runtime/cpp/emboss_arithmetic_maximum_operation_generated.h" + "runtime/cpp/emboss_array_view.h" + "runtime/cpp/emboss_bit_util.h" + "runtime/cpp/emboss_constant_view.h" + "runtime/cpp/emboss_cpp_types.h" + "runtime/cpp/emboss_cpp_util.h" + "runtime/cpp/emboss_defines.h" + "runtime/cpp/emboss_enum_view.h" + "runtime/cpp/emboss_maybe.h" + "runtime/cpp/emboss_memory_util.h" + "runtime/cpp/emboss_prelude.h" + "runtime/cpp/emboss_text_util.h" + "runtime/cpp/emboss_view_parameters.h" +)
diff --git a/gen/sources.gni b/gen/sources.gni new file mode 100644 index 0000000..6207e5b --- /dev/null +++ b/gen/sources.gni
@@ -0,0 +1,83 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Automatically generated by generate_build_files.py. +# Do not edit this file directly. + +embossc_sources = [ + "compiler/__init__.py", + "compiler/back_end/__init__.py", + "compiler/back_end/cpp/__init__.py", + "compiler/back_end/cpp/attributes.py", + "compiler/back_end/cpp/emboss_codegen_cpp.py", + "compiler/back_end/cpp/generated_code_templates", + "compiler/back_end/cpp/header_generator.py", + "compiler/back_end/util/__init__.py", + "compiler/back_end/util/code_template.py", + "compiler/front_end/__init__.py", + "compiler/front_end/attribute_checker.py", + "compiler/front_end/attributes.py", + "compiler/front_end/constraints.py", + "compiler/front_end/dependency_checker.py", + "compiler/front_end/emboss_front_end.py", + "compiler/front_end/error_examples", + "compiler/front_end/expression_bounds.py", + "compiler/front_end/generated/cached_parser.py", + "compiler/front_end/glue.py", + "compiler/front_end/lr1.py", + "compiler/front_end/make_parser.py", + "compiler/front_end/module_ir.py", + "compiler/front_end/parser.py", + "compiler/front_end/prelude.emb", + "compiler/front_end/reserved_words", + "compiler/front_end/symbol_resolver.py", + "compiler/front_end/synthetics.py", + "compiler/front_end/tokenizer.py", + "compiler/front_end/type_check.py", + "compiler/front_end/write_inference.py", + "compiler/util/__init__.py", + "compiler/util/attribute_util.py", + "compiler/util/error.py", + "compiler/util/expression_parser.py", + "compiler/util/ir_data.py", + "compiler/util/ir_data_fields.py", + "compiler/util/ir_data_utils.py", + "compiler/util/ir_util.py", + "compiler/util/name_conversion.py", + "compiler/util/parser_types.py", + "compiler/util/parser_util.py", + "compiler/util/resources.py", + "compiler/util/simple_memoizer.py", + "compiler/util/traverse_ir.py", + "embossc", +] + +emboss_runtime_cpp_sources = [ + "runtime/cpp/emboss_arithmetic.h", + "runtime/cpp/emboss_arithmetic_all_known_generated.h", + "runtime/cpp/emboss_arithmetic_maximum_operation_generated.h", + "runtime/cpp/emboss_array_view.h", + "runtime/cpp/emboss_bit_util.h", + "runtime/cpp/emboss_constant_view.h", + "runtime/cpp/emboss_cpp_types.h", + "runtime/cpp/emboss_cpp_util.h", + "runtime/cpp/emboss_defines.h", + "runtime/cpp/emboss_enum_view.h", + "runtime/cpp/emboss_maybe.h", + "runtime/cpp/emboss_memory_util.h", + "runtime/cpp/emboss_prelude.h", + "runtime/cpp/emboss_text_util.h", + "runtime/cpp/emboss_view_parameters.h", +]
diff --git a/gen/sources.json b/gen/sources.json new file mode 100644 index 0000000..46212da --- /dev/null +++ b/gen/sources.json
@@ -0,0 +1,66 @@ +{ + "embossc_sources": [ + "compiler/__init__.py", + "compiler/back_end/__init__.py", + "compiler/back_end/cpp/__init__.py", + "compiler/back_end/cpp/attributes.py", + "compiler/back_end/cpp/emboss_codegen_cpp.py", + "compiler/back_end/cpp/generated_code_templates", + "compiler/back_end/cpp/header_generator.py", + "compiler/back_end/util/__init__.py", + "compiler/back_end/util/code_template.py", + "compiler/front_end/__init__.py", + "compiler/front_end/attribute_checker.py", + "compiler/front_end/attributes.py", + "compiler/front_end/constraints.py", + "compiler/front_end/dependency_checker.py", + "compiler/front_end/emboss_front_end.py", + "compiler/front_end/error_examples", + "compiler/front_end/expression_bounds.py", + "compiler/front_end/generated/cached_parser.py", + "compiler/front_end/glue.py", + "compiler/front_end/lr1.py", + "compiler/front_end/make_parser.py", + "compiler/front_end/module_ir.py", + "compiler/front_end/parser.py", + "compiler/front_end/prelude.emb", + "compiler/front_end/reserved_words", + "compiler/front_end/symbol_resolver.py", + "compiler/front_end/synthetics.py", + "compiler/front_end/tokenizer.py", + "compiler/front_end/type_check.py", + "compiler/front_end/write_inference.py", + "compiler/util/__init__.py", + "compiler/util/attribute_util.py", + "compiler/util/error.py", + "compiler/util/expression_parser.py", + "compiler/util/ir_data.py", + "compiler/util/ir_data_fields.py", + "compiler/util/ir_data_utils.py", + "compiler/util/ir_util.py", + "compiler/util/name_conversion.py", + "compiler/util/parser_types.py", + "compiler/util/parser_util.py", + "compiler/util/resources.py", + "compiler/util/simple_memoizer.py", + "compiler/util/traverse_ir.py", + "embossc" + ], + "emboss_runtime_cpp_sources": [ + "runtime/cpp/emboss_arithmetic.h", + "runtime/cpp/emboss_arithmetic_all_known_generated.h", + "runtime/cpp/emboss_arithmetic_maximum_operation_generated.h", + "runtime/cpp/emboss_array_view.h", + "runtime/cpp/emboss_bit_util.h", + "runtime/cpp/emboss_constant_view.h", + "runtime/cpp/emboss_cpp_types.h", + "runtime/cpp/emboss_cpp_util.h", + "runtime/cpp/emboss_defines.h", + "runtime/cpp/emboss_enum_view.h", + "runtime/cpp/emboss_maybe.h", + "runtime/cpp/emboss_memory_util.h", + "runtime/cpp/emboss_prelude.h", + "runtime/cpp/emboss_text_util.h", + "runtime/cpp/emboss_view_parameters.h" + ] +}
diff --git a/scripts/build_helpers/generate_build_files.py b/scripts/build_helpers/generate_build_files.py new file mode 100755 index 0000000..480b3b2 --- /dev/null +++ b/scripts/build_helpers/generate_build_files.py
@@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generates build helper files from `build.json`.""" + +import json +import os + +COPYRIGHT_HEADER = """# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" + + +def read_build_json(file_path): + """Reads build.json, strips comments, and returns the parsed JSON data.""" + with open(file_path, "r") as f: + # Simple comment stripping for JSONC format + content = "".join(line for line in f if not line.strip().startswith("//")) + return json.loads(content) + + +def generate_sources_json(output_dir, data): + """Generates gen/sources.json.""" + output_path = os.path.join(output_dir, "sources.json") + with open(output_path, "w") as f: + json.dump(data, f, indent=4) + f.write("\n") + print(f"Generated {output_path}") + + +def generate_sources_bzl(output_dir, data): + """Generates gen/sources.bzl.""" + output_path = os.path.join(output_dir, "sources.bzl") + with open(output_path, "w") as f: + f.write(COPYRIGHT_HEADER) + f.write("\n\n") + f.write("# Automatically generated by generate_build_files.py.\n") + f.write("# Do not edit this file directly.\n") + f.write("\n") + f.write("EMBOSSC_SOURCES = [\n") + for source in data["embossc_sources"]: + f.write(f' "{source}",\n') + f.write("]\n\n") + f.write("EMBOSS_RUNTIME_CPP_SOURCES = [\n") + for source in data["emboss_runtime_cpp_sources"]: + f.write(f' "{source}",\n') + f.write("]\n") + print(f"Generated {output_path}") + + +def generate_sources_cmake(output_dir, data): + """Generates gen/sources.cmake.""" + output_path = os.path.join(output_dir, "sources.cmake") + with open(output_path, "w") as f: + f.write(COPYRIGHT_HEADER) + f.write("\n\n") + f.write("# Automatically generated by generate_build_files.py.\n") + f.write("# Do not edit this file directly.\n\n") + f.write("set(EMBOSSC_SOURCES\n") + for source in data["embossc_sources"]: + f.write(f' "{source}"\n') + f.write(")\n\n") + f.write("set(EMBOSS_RUNTIME_CPP_SOURCES\n") + for source in data["emboss_runtime_cpp_sources"]: + f.write(f' "{source}"\n') + f.write(")\n") + print(f"Generated {output_path}") + + +def generate_sources_gni(output_dir, data): + """Generates gen/sources.gni.""" + output_path = os.path.join(output_dir, "sources.gni") + with open(output_path, "w") as f: + f.write(COPYRIGHT_HEADER) + f.write("\n\n") + f.write("# Automatically generated by generate_build_files.py.\n") + f.write("# Do not edit this file directly.\n\n") + f.write("embossc_sources = [\n") + for source in data["embossc_sources"]: + f.write(f' "{source}",\n') + f.write("]\n\n") + f.write("emboss_runtime_cpp_sources = [\n") + for source in data["emboss_runtime_cpp_sources"]: + f.write(f' "{source}",\n') + f.write("]\n") + print(f"Generated {output_path}") + + +def main(): + workspace_root = os.environ.get("BUILD_WORKSPACE_DIRECTORY", os.getcwd()) + build_json_path = os.path.join(workspace_root, "build.json") + gen_dir = os.path.join(workspace_root, "gen") + + os.makedirs(gen_dir, exist_ok=True) + + data = read_build_json(build_json_path) + + generate_sources_json(gen_dir, data) + generate_sources_bzl(gen_dir, data) + generate_sources_cmake(gen_dir, data) + generate_sources_gni(gen_dir, data) + + +if __name__ == "__main__": + main()