From 6132d2c6a751ebffc29f950ca3755a05595dd99e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 19 Nov 2025 09:18:08 +0100 Subject: feat: new documented codebase and improvements. Signed-off-by: Amlal El Mahrouss --- GNUmakefile | 2 +- dev/BuildKit/Defines.h | 8 ++- dev/BuildKit/IManifestBuilder.h | 24 ++++--- dev/BuildKit/Imports.h | 4 ++ dev/BuildKit/JSONManifestBuilder.h | 18 ++++-- dev/BuildKit/TOMLManifestBuilder.h | 18 ++++-- dev/cli/App.cc | 83 ------------------------- dev/cli/AppMain.cc | 83 +++++++++++++++++++++++++ dev/src/JSONManifestBuilder.cc | 8 ++- dev/src/TOMLManifestBuilder.cc | 17 +++-- examples/example_01_hello_world/posix.json | 2 +- examples/example_02_libnebuild/posix.json | 2 +- examples/example_03_hello_world_toml/posix.toml | 2 +- osx-dylib.json | 2 +- osx.json | 2 +- posix.json | 2 +- 16 files changed, 158 insertions(+), 119 deletions(-) delete mode 100644 dev/cli/App.cc create mode 100644 dev/cli/AppMain.cc diff --git a/GNUmakefile b/GNUmakefile index 44dbfeb..bcdc8e9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,7 +4,7 @@ # // ============================================================= // SUDO=sudo -GCC=g++ +GCC=clang++ GCC_MINGW=x86_64-w64-mingw32-g++ CXXFLAGS=-I./dev -I./vendor CXXSTD= -std=c++20 diff --git a/dev/BuildKit/Defines.h b/dev/BuildKit/Defines.h index 4774c85..1c88ceb 100644 --- a/dev/BuildKit/Defines.h +++ b/dev/BuildKit/Defines.h @@ -7,12 +7,16 @@ #include +/// =========================================================== /// +/// @brief Defines file +/// =========================================================== /// + #define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) #define UNLIKELY(ARG) LIKELY(!(ARG)) -#define LIBNEBUILD_VERSION "v0.0.1-libNeBuild" +#define LIBNEBUILD_VERSION "v0.0.7-buildkit" -#define LIBNEBUILD_VERSION_BCD 0x0001 +#define LIBNEBUILD_VERSION_BCD 0x0007 #define LIBNEBUILD_VERSION_MAJOR 1 #define LIBNEBUILD_VERSION_MINOR 1 diff --git a/dev/BuildKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h index 8f9b2cf..abb389f 100644 --- a/dev/BuildKit/IManifestBuilder.h +++ b/dev/BuildKit/IManifestBuilder.h @@ -7,11 +7,13 @@ #include -#define NEBUILD_MANIFEST_BUILDER : public NeBuild::IManifestBuilder +#define NEBUILD_MANIFEST_BUILDER : public ::NeBuild::IManifestBuilder namespace NeBuild { +/// =========================================================== /// /// @brief Builder interface class. /// @note This class is meant to be used as an interface. +/// =========================================================== /// class IManifestBuilder { public: IManifestBuilder() = default; @@ -20,12 +22,18 @@ class IManifestBuilder { IManifestBuilder& operator=(const IManifestBuilder&) = default; IManifestBuilder(const IManifestBuilder&) = default; - /// @brief Builds a target using the implemented laguage. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true succeeded. - /// @retval false failed. - virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; - virtual const char* BuildSystem() = 0; + /// =========================================================== /// + /// @brief Builds a TOML target from a file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid language file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// + virtual const char* BuildSystem() = 0; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/Imports.h b/dev/BuildKit/Imports.h index e22c933..33e1e31 100644 --- a/dev/BuildKit/Imports.h +++ b/dev/BuildKit/Imports.h @@ -6,6 +6,10 @@ #ifndef NEBUILD_INCLUDES_H #define NEBUILD_INCLUDES_H +/// =========================================================== /// +/// @brief Imports file +/// =========================================================== /// + #include #include #include diff --git a/dev/BuildKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h index 81643e3..438bdab 100644 --- a/dev/BuildKit/JSONManifestBuilder.h +++ b/dev/BuildKit/JSONManifestBuilder.h @@ -22,12 +22,18 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { JSONManifestBuilder(const JSONManifestBuilder&) = default; public: - /// @brief Builds a JSON target. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true build succeeded. - /// @retval false failed to build. - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + /// =========================================================== /// + /// @brief Builds a JSON target from a JSON file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid JSON file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// const char* BuildSystem() override; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/TOMLManifestBuilder.h b/dev/BuildKit/TOMLManifestBuilder.h index 6baa9f5..7c508fc 100644 --- a/dev/BuildKit/TOMLManifestBuilder.h +++ b/dev/BuildKit/TOMLManifestBuilder.h @@ -22,12 +22,18 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { TOMLManifestBuilder(const TOMLManifestBuilder&) = default; public: - /// @brief Builds a TOML target. - /// @param arg_sz filename size - /// @param arg_val filename path. - /// @retval true build succeeded. - /// @retval false failed to build. - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + /// =========================================================== /// + /// @brief Builds a TOML target from a TOML file. + /// @param arg_sz filename size (must be 1 or greater). + /// @param arg_val filename path (must be a valid TOML file). + /// @retval true building has succeeded. + /// @retval false fail to build, see error message. + /// =========================================================== /// + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + + /// =========================================================== /// + /// @brief Returns the build system name. + /// =========================================================== /// const char* BuildSystem() override; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/cli/App.cc b/dev/cli/App.cc deleted file mode 100644 index d78ad69..0000000 --- a/dev/cli/App.cc +++ /dev/null @@ -1,83 +0,0 @@ - -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#include -#include - -static bool kFailed = false; -static bool kDryRun = false; - -int main(int argc, char** argv) { - if (argc <= 1) return EXIT_FAILURE; - - for (size_t index = 1; index < argc; ++index) { - std::string index_path = argv[index]; - - if (index_path == "-v" || index_path == "--version") { - NeBuild::Logger::info() << "NeKernel Build Tool.\n"; - NeBuild::Logger::info() - << "Bugs or issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; - - return EXIT_SUCCESS; - } else if (index_path == "--dry-run" || index_path == "-n") { - kDryRun = true; - continue; - } else if (index_path == "-h" || index_path == "--help") { - NeBuild::Logger::info() << "usage: nebuild \n"; - - return EXIT_SUCCESS; - } - - if (index_path.starts_with("-")) { - NeBuild::Logger::info() << "error: unknown option '" << index_path << "'\n"; - - return EXIT_FAILURE; - } - - std::thread job_build_thread( - [](std::string index_path) -> void { - NeBuild::IManifestBuilder* builder = nullptr; - - const auto kJsonExtension = ".json"; - - if (index_path.ends_with(kJsonExtension)) { - builder = new NeBuild::JSONManifestBuilder(); - - if (!builder) { - kFailed = true; - return; - } - } else { - const auto kTomlExtension = ".toml"; - builder = new NeBuild::TOMLManifestBuilder(); - - if (index_path.ends_with(kTomlExtension)) { - goto end; - } else { - NeBuild::Logger::info() - << "error: file '" << index_path << "' is not a JSON file!" << std::endl; - kFailed = true; - return; - } - } - - end: - NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - - if (builder && !builder->BuildTarget(index_path, kDryRun)) { - kFailed = true; - } - - delete builder; - builder = nullptr; - }, - index_path); - - job_build_thread.join(); - } - - return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; -} diff --git a/dev/cli/AppMain.cc b/dev/cli/AppMain.cc new file mode 100644 index 0000000..53cbdf3 --- /dev/null +++ b/dev/cli/AppMain.cc @@ -0,0 +1,83 @@ + +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#include +#include + +static bool kFailed = false; +static bool kDryRun = false; + +int main(int argc, char** argv) { + if (argc <= 1) return EXIT_FAILURE; + + for (size_t index = 1; index < argc; ++index) { + std::string index_path = argv[index]; + + if (index_path == "-v" || index_path == "--version") { + NeBuild::Logger::info() << "NeKernel Build.\n"; + NeBuild::Logger::info() + << "Bugs or issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; + + return EXIT_SUCCESS; + } else if (index_path == "--dry-run" || index_path == "-n") { + kDryRun = true; + continue; + } else if (index_path == "-h" || index_path == "--help") { + NeBuild::Logger::info() << "usage: nebuild \n"; + + return EXIT_SUCCESS; + } + + if (index_path.starts_with("-")) { + NeBuild::Logger::info() << "error: unknown option '" << index_path << "'\n"; + + return EXIT_FAILURE; + } + + std::thread job_build_thread( + [](std::string index_path) -> void { + NeBuild::IManifestBuilder* builder = nullptr; + + const auto kJsonExtension = ".json"; + + if (index_path.ends_with(kJsonExtension)) { + builder = new NeBuild::JSONManifestBuilder(); + + if (!builder) { + kFailed = true; + return; + } + } else { + const auto kTomlExtension = ".toml"; + builder = new NeBuild::TOMLManifestBuilder(); + + if (index_path.ends_with(kTomlExtension)) { + goto end; + } else { + NeBuild::Logger::info() + << "error: file '" << index_path << "' is not a manifest file!" << std::endl; + kFailed = true; + return; + } + } + + end: + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; + + if (builder && !builder->BuildTarget(index_path, kDryRun)) { + kFailed = true; + } + + delete builder; + builder = nullptr; + }, + index_path); + + job_build_thread.join(); + } + + return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index dba5b37..8eaf20a 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -10,11 +10,13 @@ namespace FS = std::filesystem; using namespace NeBuild; +/// =========================================================== /// /// @brief Builds a JSON target from a JSON file. /// @param arg_sz filename size (must be 1 or greater). /// @param arg_val filename path (must be a valid JSON file). /// @retval true building has succeeded. /// @retval false fail to build, see error message. +/// =========================================================== /// bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { std::string path; @@ -84,7 +86,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr auto target = json_obj["output_name"].get(); NeBuild::Logger::info() << "output path: " << target << "\n"; - NeBuild::Logger::info() << "command: " << command << "\n"; auto ret_exec = std::system(command.c_str()); @@ -94,13 +95,16 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr return false; } } catch (std::runtime_error& err) { - NeBuild::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; return false; } return true; } +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// const char* JSONManifestBuilder::BuildSystem() { return "NeBuild (JSON)"; } diff --git a/dev/src/TOMLManifestBuilder.cc b/dev/src/TOMLManifestBuilder.cc index 53034e8..f264ade 100644 --- a/dev/src/TOMLManifestBuilder.cc +++ b/dev/src/TOMLManifestBuilder.cc @@ -9,11 +9,13 @@ namespace FS = std::filesystem; using namespace NeBuild; +/// =========================================================== /// /// @brief Builds a TOML target from a TOML file. /// @param arg_sz filename size (must be 1 or greater). /// @param arg_val filename path (must be a valid TOML file). /// @retval true building has succeeded. /// @retval false fail to build, see error message. +/// =========================================================== /// bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { std::string path; @@ -77,15 +79,17 @@ bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr } } - if (toml_file["compiler_std"].is_string()) - command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + if (!toml_file["compiler_std"].is_string()) return false; + + command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + + if (toml_file["output_name"].as_string() == nullptr) return false; command += "-o " + toml_file["output_name"].as_string()->get(); auto target = toml_file["output_name"].as_string()->get(); - NeBuild::Logger::info() << "output path: " << target << "\n"; - NeBuild::Logger::info() << "command: " << command << "\n"; + NeBuild::Logger::info() << "output: " << target << "\n"; auto ret_exec = std::system(command.c_str()); @@ -95,13 +99,16 @@ bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr return false; } } catch (std::runtime_error& err) { - NeBuild::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl; return false; } return true; } +/// =========================================================== /// +/// @brief Returns the build system name. +/// =========================================================== /// const char* TOMLManifestBuilder::BuildSystem() { return "NeBuild (TOML)"; } diff --git a/examples/example_01_hello_world/posix.json b/examples/example_01_hello_world/posix.json index c3c8151..09cbef7 100644 --- a/examples/example_01_hello_world/posix.json +++ b/examples/example_01_hello_world/posix.json @@ -1,5 +1,5 @@ { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["lib"], "sources_path": ["hello_world.cc"], diff --git a/examples/example_02_libnebuild/posix.json b/examples/example_02_libnebuild/posix.json index 989e712..b8145bd 100644 --- a/examples/example_02_libnebuild/posix.json +++ b/examples/example_02_libnebuild/posix.json @@ -1,5 +1,5 @@ { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": [ "../../dev", diff --git a/examples/example_03_hello_world_toml/posix.toml b/examples/example_03_hello_world_toml/posix.toml index 4f71f7d..e8595d4 100644 --- a/examples/example_03_hello_world_toml/posix.toml +++ b/examples/example_03_hello_world_toml/posix.toml @@ -1,4 +1,4 @@ -compiler_path = "g++" +compiler_path = "clang++" compiler_std = "c++20" headers_path = [ "lib" ] sources_path = [ "hello_world.cc" ] diff --git a/osx-dylib.json b/osx-dylib.json index 7f7648d..f9e2274 100644 --- a/osx-dylib.json +++ b/osx-dylib.json @@ -1,5 +1,5 @@ { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["dev", "vendor"], "sources_path": ["dev/src/*.cc"], diff --git a/osx.json b/osx.json index 8e247d9..3819ea7 100644 --- a/osx.json +++ b/osx.json @@ -1,5 +1,5 @@ { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["dev", "vendor"], "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], diff --git a/posix.json b/posix.json index 5281d4d..b6dc247 100644 --- a/posix.json +++ b/posix.json @@ -1,5 +1,5 @@ { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["dev/", "vendor"], "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], -- cgit v1.2.3