From 64b8a6bf04095d80b1ca52415ea954b933f47098 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 02:33:21 +0100 Subject: feat! breaking changes, merging to stable. Signed-off-by: Amlal El Mahrouss --- GNUmakefile | 4 +- dev/BuildKit/Defines.h | 34 -------- dev/BuildKit/IManifestBuilder.h | 39 --------- dev/BuildKit/Imports.h | 23 ------ dev/BuildKit/JSONManifestBuilder.h | 39 --------- dev/BuildKit/TOMLManifestBuilder.h | 39 --------- dev/cli/AppMain.cc | 83 ------------------- dev/src/IManifestBuilder.cc | 6 -- dev/src/JSONManifestBuilder.cc | 111 -------------------------- dev/src/TOMLManifestBuilder.cc | 115 --------------------------- examples/example_02_libnebuild/libnebuild.cc | 2 +- examples/example_02_libnebuild/posix.json | 2 +- examples/example_02_libnebuild/win64.json | 2 +- include/NeBuildKit/Defines.h | 34 ++++++++ include/NeBuildKit/IManifestBuilder.h | 39 +++++++++ include/NeBuildKit/Imports.h | 23 ++++++ include/NeBuildKit/JSONManifestBuilder.h | 39 +++++++++ include/NeBuildKit/TOMLManifestBuilder.h | 39 +++++++++ osx-dylib.json | 6 +- osx.json | 4 +- posix-dylib.json | 10 +++ posix.json | 4 +- src/cli/AppMain.cc | 83 +++++++++++++++++++ src/lib/IManifestBuilder.cc | 6 ++ src/lib/JSONManifestBuilder.cc | 111 ++++++++++++++++++++++++++ src/lib/TOMLManifestBuilder.cc | 115 +++++++++++++++++++++++++++ win64.json | 4 +- 27 files changed, 513 insertions(+), 503 deletions(-) delete mode 100644 dev/BuildKit/Defines.h delete mode 100644 dev/BuildKit/IManifestBuilder.h delete mode 100644 dev/BuildKit/Imports.h delete mode 100644 dev/BuildKit/JSONManifestBuilder.h delete mode 100644 dev/BuildKit/TOMLManifestBuilder.h delete mode 100644 dev/cli/AppMain.cc delete mode 100644 dev/src/IManifestBuilder.cc delete mode 100644 dev/src/JSONManifestBuilder.cc delete mode 100644 dev/src/TOMLManifestBuilder.cc create mode 100644 include/NeBuildKit/Defines.h create mode 100644 include/NeBuildKit/IManifestBuilder.h create mode 100644 include/NeBuildKit/Imports.h create mode 100644 include/NeBuildKit/JSONManifestBuilder.h create mode 100644 include/NeBuildKit/TOMLManifestBuilder.h create mode 100644 posix-dylib.json create mode 100644 src/cli/AppMain.cc create mode 100644 src/lib/IManifestBuilder.cc create mode 100644 src/lib/JSONManifestBuilder.cc create mode 100644 src/lib/TOMLManifestBuilder.cc diff --git a/GNUmakefile b/GNUmakefile index bcdc8e9..c0bc97f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,9 +6,9 @@ SUDO=sudo GCC=clang++ GCC_MINGW=x86_64-w64-mingw32-g++ -CXXFLAGS=-I./dev -I./vendor +CXXFLAGS=-I./include -I./vendor CXXSTD= -std=c++20 -SRC=$(wildcard dev/cli/*.cc) $(wildcard dev/src/*.cc) +SRC=$(wildcard src/cli/*.cc) $(wildcard src/lib/*.cc) OUT=nebuild CP=cp diff --git a/dev/BuildKit/Defines.h b/dev/BuildKit/Defines.h deleted file mode 100644 index 1c88ceb..0000000 --- a/dev/BuildKit/Defines.h +++ /dev/null @@ -1,34 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#pragma once - -#include - -/// =========================================================== /// -/// @brief Defines file -/// =========================================================== /// - -#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) -#define UNLIKELY(ARG) LIKELY(!(ARG)) - -#define LIBNEBUILD_VERSION "v0.0.7-buildkit" - -#define LIBNEBUILD_VERSION_BCD 0x0007 - -#define LIBNEBUILD_VERSION_MAJOR 1 -#define LIBNEBUILD_VERSION_MINOR 1 -#define LIBNEBUILD_VERSION_PATCH 0 - -#define LIBNEBUILD_UNUSED(X) ((void) X) - -namespace NeBuild::Logger { -/// @brief replacement for std::cout for NeBuild logging. -inline std::ostream& info() noexcept { - auto& out = std::cout; - out << rang::fg::red << "nebuild: " << rang::style::reset; - return out; -} -} // namespace NeBuild::Logger diff --git a/dev/BuildKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h deleted file mode 100644 index abb389f..0000000 --- a/dev/BuildKit/IManifestBuilder.h +++ /dev/null @@ -1,39 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#pragma once - -#include - -#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; - virtual ~IManifestBuilder() = default; - - IManifestBuilder& operator=(const IManifestBuilder&) = default; - IManifestBuilder(const IManifestBuilder&) = default; - - /// =========================================================== /// - /// @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 deleted file mode 100644 index 33e1e31..0000000 --- a/dev/BuildKit/Imports.h +++ /dev/null @@ -1,23 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#ifndef NEBUILD_INCLUDES_H -#define NEBUILD_INCLUDES_H - -/// =========================================================== /// -/// @brief Imports file -/// =========================================================== /// - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // NEBUILD_INCLUDES_H diff --git a/dev/BuildKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h deleted file mode 100644 index 438bdab..0000000 --- a/dev/BuildKit/JSONManifestBuilder.h +++ /dev/null @@ -1,39 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#pragma once - -#include -#include - -/// @file JSONManifestBuilder.h -/// @brief JSON manifest builder header file. - -namespace NeBuild { -/// @brief JSON builder -class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { - public: - JSONManifestBuilder() = default; - ~JSONManifestBuilder() override = default; - - JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default; - JSONManifestBuilder(const JSONManifestBuilder&) = default; - - public: - /// =========================================================== /// - /// @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 deleted file mode 100644 index 7c508fc..0000000 --- a/dev/BuildKit/TOMLManifestBuilder.h +++ /dev/null @@ -1,39 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#pragma once - -#include -#include - -/// @file TOMLManifestBuilder.h -/// @brief TOML manifest builder header file. - -namespace NeBuild { -/// @brief TOML builder -class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { - public: - TOMLManifestBuilder() = default; - ~TOMLManifestBuilder() override = default; - - TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default; - TOMLManifestBuilder(const TOMLManifestBuilder&) = default; - - public: - /// =========================================================== /// - /// @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/AppMain.cc b/dev/cli/AppMain.cc deleted file mode 100644 index afd912e..0000000 --- a/dev/cli/AppMain.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.\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/IManifestBuilder.cc b/dev/src/IManifestBuilder.cc deleted file mode 100644 index 745e81d..0000000 --- a/dev/src/IManifestBuilder.cc +++ /dev/null @@ -1,6 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#include diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc deleted file mode 100644 index d54653b..0000000 --- a/dev/src/JSONManifestBuilder.cc +++ /dev/null @@ -1,111 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#include - -using namespace NeBuild; -using namespace nlohmann; - -using JSON = json; -namespace FS = std::filesystem; - -/// =========================================================== /// -/// @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; - - if (argv_val.empty()) { - NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; - return false; - } else { - path = argv_val; - - if (!FS::exists(path)) { - NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" - << std::endl; - return false; - } - } - - try { - std::ifstream json(path); - - if (!json.good()) { - NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" - << std::endl; - return false; - } - - JSON json_obj = JSON::parse(json); - - std::string compiler = json_obj["compiler_path"].get(); - - std::string command = compiler + " "; - - JSON header_search_path = json_obj["compiler_headers_path"]; - - for (auto& headers : header_search_path) { - command += "-I" + headers.get() + " "; - } - - JSON headers_path = json_obj["headers_path"]; - - for (auto& headers : headers_path) { - command += "-I" + headers.get() + " "; - } - - JSON sources_files = json_obj["sources_path"]; - - for (auto& sources : sources_files) { - command += sources.get() + " "; - } - - JSON macros_list = json_obj["cpp_macros"]; - - for (auto& macro : macros_list) { - command += "-D" + macro.get() + " "; - } - - JSON compiler_flags = json_obj["compiler_flags"]; - - for (auto& flag : compiler_flags) { - command += flag.get() + " "; - } - - if (json_obj["compiler_std"].is_string()) - command += "-std=" + json_obj["compiler_std"].get() + " "; - - command += "-o " + json_obj["output_name"].get(); - - auto target = json_obj["output_name"].get(); - - NeBuild::Logger::info() << "output path: " << target << "\n"; - - auto ret_exec = std::system(command.c_str()); - - if (ret_exec > 0) { - NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" - << std::endl; - return false; - } - } catch (std::runtime_error& err) { - 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 deleted file mode 100644 index 49de8eb..0000000 --- a/dev/src/TOMLManifestBuilder.cc +++ /dev/null @@ -1,115 +0,0 @@ -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. -// ============================================================= // - -#include -#include - -using namespace NeBuild; - -namespace FS = std::filesystem; - -/// =========================================================== /// -/// @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; - - if (argv_val.empty()) { - NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; - return false; - } else { - path = argv_val; - - if (!FS::exists(path)) { - NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" - << std::endl; - return false; - } - } - - try { - auto toml_file = toml::parse_file(path); - - std::string compiler = toml_file["compiler_path"].as_string()->get(); - - std::string command = compiler + " "; - - auto header_search_path = toml_file["compiler_headers_path"].as_array(); - - if (header_search_path) { - for (auto& headers : *header_search_path) { - command += "-I" + headers.as_string()->get() + " "; - } - } - - auto headers_path = toml_file["headers_path"].as_array(); - - if (headers_path) { - for (auto& headers : *headers_path) { - command += "-I" + headers.as_string()->get() + " "; - } - } - - auto sources_files = toml_file["sources_path"].as_array(); - - if (sources_files) { - for (auto& sources : *sources_files) { - command += sources.as_string()->get() + " "; - } - } - - auto macros_list = toml_file["cpp_macros"].as_array(); - - if (macros_list) { - for (auto& macro : *macros_list) { - command += "-D" + macro.as_string()->get() + " "; - } - } - - auto compiler_flags = toml_file["compiler_flags"].as_array(); - - if (compiler_flags) { - for (auto& flag : *compiler_flags) { - command += flag.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: " << target << "\n"; - - auto ret_exec = std::system(command.c_str()); - - if (ret_exec > 0) { - NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" - << std::endl; - return false; - } - } catch (std::runtime_error& err) { - 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_02_libnebuild/libnebuild.cc b/examples/example_02_libnebuild/libnebuild.cc index 5540503..c5f13fe 100644 --- a/examples/example_02_libnebuild/libnebuild.cc +++ b/examples/example_02_libnebuild/libnebuild.cc @@ -1,4 +1,4 @@ -#include +#include #include #ifndef _WIN32 diff --git a/examples/example_02_libnebuild/posix.json b/examples/example_02_libnebuild/posix.json index b8145bd..262d358 100644 --- a/examples/example_02_libnebuild/posix.json +++ b/examples/example_02_libnebuild/posix.json @@ -2,7 +2,7 @@ "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": [ - "../../dev", + "../../include", "../../vendor" ], "sources_path": [ diff --git a/examples/example_02_libnebuild/win64.json b/examples/example_02_libnebuild/win64.json index 3118a36..dcd1142 100644 --- a/examples/example_02_libnebuild/win64.json +++ b/examples/example_02_libnebuild/win64.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": [ - "../../dev", + "../../include", "../../vendor" ], "sources_path": [ diff --git a/include/NeBuildKit/Defines.h b/include/NeBuildKit/Defines.h new file mode 100644 index 0000000..06d936f --- /dev/null +++ b/include/NeBuildKit/Defines.h @@ -0,0 +1,34 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#pragma once + +#include + +/// =========================================================== /// +/// @brief Defines file +/// =========================================================== /// + +#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) +#define UNLIKELY(ARG) LIKELY(!(ARG)) + +#define LIBNEBUILD_VERSION "v0.0.7-buildkit" + +#define LIBNEBUILD_VERSION_BCD 0x0007 + +#define LIBNEBUILD_VERSION_MAJOR 1 +#define LIBNEBUILD_VERSION_MINOR 1 +#define LIBNEBUILD_VERSION_PATCH 0 + +#define LIBNEBUILD_UNUSED(X) ((void) X) + +namespace NeBuild::Logger { +/// @brief replacement for std::cout for NeBuild logging. +inline std::ostream& info() noexcept { + auto& out = std::cout; + out << rang::fg::red << "nebuild: " << rang::style::reset; + return out; +} +} // namespace NeBuild::Logger diff --git a/include/NeBuildKit/IManifestBuilder.h b/include/NeBuildKit/IManifestBuilder.h new file mode 100644 index 0000000..96c80c3 --- /dev/null +++ b/include/NeBuildKit/IManifestBuilder.h @@ -0,0 +1,39 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#pragma once + +#include + +#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; + virtual ~IManifestBuilder() = default; + + IManifestBuilder& operator=(const IManifestBuilder&) = default; + IManifestBuilder(const IManifestBuilder&) = default; + + /// =========================================================== /// + /// @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/include/NeBuildKit/Imports.h b/include/NeBuildKit/Imports.h new file mode 100644 index 0000000..33e1e31 --- /dev/null +++ b/include/NeBuildKit/Imports.h @@ -0,0 +1,23 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#ifndef NEBUILD_INCLUDES_H +#define NEBUILD_INCLUDES_H + +/// =========================================================== /// +/// @brief Imports file +/// =========================================================== /// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // NEBUILD_INCLUDES_H diff --git a/include/NeBuildKit/JSONManifestBuilder.h b/include/NeBuildKit/JSONManifestBuilder.h new file mode 100644 index 0000000..ccd5f6e --- /dev/null +++ b/include/NeBuildKit/JSONManifestBuilder.h @@ -0,0 +1,39 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#pragma once + +#include +#include + +/// @file JSONManifestBuilder.h +/// @brief JSON manifest builder header file. + +namespace NeBuild { +/// @brief JSON builder +class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { + public: + JSONManifestBuilder() = default; + ~JSONManifestBuilder() override = default; + + JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default; + JSONManifestBuilder(const JSONManifestBuilder&) = default; + + public: + /// =========================================================== /// + /// @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/include/NeBuildKit/TOMLManifestBuilder.h b/include/NeBuildKit/TOMLManifestBuilder.h new file mode 100644 index 0000000..c6a12bc --- /dev/null +++ b/include/NeBuildKit/TOMLManifestBuilder.h @@ -0,0 +1,39 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#pragma once + +#include +#include + +/// @file TOMLManifestBuilder.h +/// @brief TOML manifest builder header file. + +namespace NeBuild { +/// @brief TOML builder +class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { + public: + TOMLManifestBuilder() = default; + ~TOMLManifestBuilder() override = default; + + TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default; + TOMLManifestBuilder(const TOMLManifestBuilder&) = default; + + public: + /// =========================================================== /// + /// @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/osx-dylib.json b/osx-dylib.json index f9e2274..d5b87bc 100644 --- a/osx-dylib.json +++ b/osx-dylib.json @@ -1,9 +1,9 @@ { "compiler_path": "clang++", "compiler_std": "c++20", - "headers_path": ["dev", "vendor"], - "sources_path": ["dev/src/*.cc"], - "output_name": "libNeBuild.dylib", + "headers_path": ["include", "vendor"], + "sources_path": ["src/lib/*.cc"], + "output_name": "libNeBuildKit.dylib", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": ["NEBUILD_DYLIB", "NEBUILD_OSX"], "run_after_build": false diff --git a/osx.json b/osx.json index 3819ea7..bdcab49 100644 --- a/osx.json +++ b/osx.json @@ -1,8 +1,8 @@ { "compiler_path": "clang++", "compiler_std": "c++20", - "headers_path": ["dev", "vendor"], - "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "headers_path": ["include", "vendor"], + "sources_path": ["src/lib/*.cc", "src/cli/*.cc"], "output_name": "nebuild", "compiler_flags": ["-fPIC"], "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_OSX"], diff --git a/posix-dylib.json b/posix-dylib.json new file mode 100644 index 0000000..3326b3e --- /dev/null +++ b/posix-dylib.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": ["include/", "vendor"], + "sources_path": ["src/lib/*.cc"], + "output_name": "libNeBuildKit.so", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_DYLIB"], + "run_after_build": false +} diff --git a/posix.json b/posix.json index b6dc247..679296c 100644 --- a/posix.json +++ b/posix.json @@ -1,8 +1,8 @@ { "compiler_path": "clang++", "compiler_std": "c++20", - "headers_path": ["dev/", "vendor"], - "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "headers_path": ["include/", "vendor"], + "sources_path": ["src/lib/*.cc", "src/cli/*.cc"], "output_name": "nebuild", "compiler_flags": ["-fPIC"], "cpp_macros": ["NEBUILD_POSIX"], diff --git a/src/cli/AppMain.cc b/src/cli/AppMain.cc new file mode 100644 index 0000000..173820b --- /dev/null +++ b/src/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, 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/src/lib/IManifestBuilder.cc b/src/lib/IManifestBuilder.cc new file mode 100644 index 0000000..464004e --- /dev/null +++ b/src/lib/IManifestBuilder.cc @@ -0,0 +1,6 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#include diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc new file mode 100644 index 0000000..9de6608 --- /dev/null +++ b/src/lib/JSONManifestBuilder.cc @@ -0,0 +1,111 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#include + +using namespace NeBuild; +using namespace nlohmann; + +using JSON = json; +namespace FS = std::filesystem; + +/// =========================================================== /// +/// @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; + + if (argv_val.empty()) { + NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; + return false; + } else { + path = argv_val; + + if (!FS::exists(path)) { + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" + << std::endl; + return false; + } + } + + try { + std::ifstream json(path); + + if (!json.good()) { + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" + << std::endl; + return false; + } + + JSON json_obj = JSON::parse(json); + + std::string compiler = json_obj["compiler_path"].get(); + + std::string command = compiler + " "; + + JSON header_search_path = json_obj["compiler_headers_path"]; + + for (auto& headers : header_search_path) { + command += "-I" + headers.get() + " "; + } + + JSON headers_path = json_obj["headers_path"]; + + for (auto& headers : headers_path) { + command += "-I" + headers.get() + " "; + } + + JSON sources_files = json_obj["sources_path"]; + + for (auto& sources : sources_files) { + command += sources.get() + " "; + } + + JSON macros_list = json_obj["cpp_macros"]; + + for (auto& macro : macros_list) { + command += "-D" + macro.get() + " "; + } + + JSON compiler_flags = json_obj["compiler_flags"]; + + for (auto& flag : compiler_flags) { + command += flag.get() + " "; + } + + if (json_obj["compiler_std"].is_string()) + command += "-std=" + json_obj["compiler_std"].get() + " "; + + command += "-o " + json_obj["output_name"].get(); + + auto target = json_obj["output_name"].get(); + + NeBuild::Logger::info() << "output path: " << target << "\n"; + + auto ret_exec = std::system(command.c_str()); + + if (ret_exec > 0) { + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" + << std::endl; + return false; + } + } catch (std::runtime_error& err) { + 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/src/lib/TOMLManifestBuilder.cc b/src/lib/TOMLManifestBuilder.cc new file mode 100644 index 0000000..fc10c88 --- /dev/null +++ b/src/lib/TOMLManifestBuilder.cc @@ -0,0 +1,115 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under BSD-3 license. +// ============================================================= // + +#include +#include + +using namespace NeBuild; + +namespace FS = std::filesystem; + +/// =========================================================== /// +/// @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; + + if (argv_val.empty()) { + NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; + return false; + } else { + path = argv_val; + + if (!FS::exists(path)) { + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" + << std::endl; + return false; + } + } + + try { + auto toml_file = toml::parse_file(path); + + std::string compiler = toml_file["compiler_path"].as_string()->get(); + + std::string command = compiler + " "; + + auto header_search_path = toml_file["compiler_headers_path"].as_array(); + + if (header_search_path) { + for (auto& headers : *header_search_path) { + command += "-I" + headers.as_string()->get() + " "; + } + } + + auto headers_path = toml_file["headers_path"].as_array(); + + if (headers_path) { + for (auto& headers : *headers_path) { + command += "-I" + headers.as_string()->get() + " "; + } + } + + auto sources_files = toml_file["sources_path"].as_array(); + + if (sources_files) { + for (auto& sources : *sources_files) { + command += sources.as_string()->get() + " "; + } + } + + auto macros_list = toml_file["cpp_macros"].as_array(); + + if (macros_list) { + for (auto& macro : *macros_list) { + command += "-D" + macro.as_string()->get() + " "; + } + } + + auto compiler_flags = toml_file["compiler_flags"].as_array(); + + if (compiler_flags) { + for (auto& flag : *compiler_flags) { + command += flag.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: " << target << "\n"; + + auto ret_exec = std::system(command.c_str()); + + if (ret_exec > 0) { + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" + << std::endl; + return false; + } + } catch (std::runtime_error& err) { + 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/win64.json b/win64.json index 6585723..75c025a 100644 --- a/win64.json +++ b/win64.json @@ -1,8 +1,8 @@ { "compiler_path": "x86_64-w64-mingw32-g++.exe", "compiler_std": "c++20", - "headers_path": ["dev", "vendor"], - "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "headers_path": ["include", "vendor"], + "sources_path": ["src/lib/*.cc", "src/cli/*.cc"], "output_name": "nebuild.exe", "compiler_flags": ["-fPIC"], "cpp_macros": ["NEBUILD_WINDOWS"], -- cgit v1.2.3