From 11ea29334a52ef33dbd04b1f320c033ebf31f37b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 25 Oct 2025 21:42:41 +0200 Subject: wip: working on a new nebuild system. Signed-off-by: Amlal El Mahrouss --- GNUmakefile | 1 + dev/src/JSONManifestBuilder.cc | 38 +++++++++++++++----------------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index a195f86..b05411c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,6 +18,7 @@ build-nebuild-windows: .PHONY: help help: + @echo "NEBUILD => HELP" @echo "=> help: Show this help message." @echo "=> build-nebuild-windows: Build NeBuild for Windows." @echo "=> build-nebuild: Build NeBuild for POSIX." diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index 0b010fe..5ea96a7 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -9,8 +9,7 @@ #include #endif -using JSON = nlohmann::json; - +using JSON = nlohmann::json; namespace FS = std::filesystem; using namespace NeBuild; @@ -49,19 +48,27 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr std::string compiler = json_obj["compiler_path"].get(); - JSON header_search_path = json_obj["headers_path"]; - JSON sources_files = json_obj["sources_path"]; + if (compiler != "g++" || !compiler.starts_with("clang")) { + NeBuild::Logger::info() << "nebuild: error: compiler '" << compiler << "' is not a valid C/C++ compiler!" + << std::endl; + return false; + } std::string command = compiler + " "; - for (auto& sources : sources_files) { - command += sources.get() + " "; - } + 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"]; + 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) { @@ -109,7 +116,7 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr if (dll) { int (*entrypoint)(void) = nullptr; - entrypoint = (decltype(entrypoint))dlsym(dll, "shared_runner"); + entrypoint = (decltype(entrypoint)) dlsym(dll, "shared_runner"); if (entrypoint) entrypoint(); @@ -121,21 +128,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr return false; } else { - std::ifstream file = std::ifstream(target); - std::stringstream ss; - - ss << file.rdbuf(); - - if (ss.str()[0] == 'O' && ss.str()[1] == 'p' && ss.str()[2] == 'e' && ss.str()[3] == 'n') - NeBuild::Logger::info() - << "error: can't open PEF dynamic library, it mayn't contain an entrypoint" - << std::endl; - else if (ss.str()[0] == 'n' && ss.str()[1] == 'e' && ss.str()[2] == 'p' && - ss.str()[3] == 'O') - NeBuild::Logger::info() - << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" - << std::endl; - return false; } -- cgit v1.2.3 From 1350d6381de4c2b2c56a69f0dc20ce54fab7be8b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 29 Oct 2025 12:05:32 +0100 Subject: feat: new NeBuild JSON API. Signed-off-by: Amlal El Mahrouss --- dev/src/JSONManifestBuilder.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index 5ea96a7..e045f6c 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -49,8 +49,8 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr std::string compiler = json_obj["compiler_path"].get(); if (compiler != "g++" || !compiler.starts_with("clang")) { - NeBuild::Logger::info() << "nebuild: error: compiler '" << compiler << "' is not a valid C/C++ compiler!" - << std::endl; + NeBuild::Logger::info() << "nebuild: error: compiler '" << compiler + << "' is not a valid C/C++ compiler!" << std::endl; return false; } @@ -62,8 +62,8 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr command += "-I" + headers.get() + " "; } - JSON headers_path = json_obj["headers_path"]; - JSON sources_files = json_obj["sources_path"]; + JSON headers_path = json_obj["headers_path"]; + JSON sources_files = json_obj["sources_path"]; for (auto& sources : sources_files) { command += sources.get() + " "; @@ -126,8 +126,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr } #endif - return false; - } else { return false; } @@ -137,12 +135,12 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr std::system(("./" + target).c_str()); #endif } - } catch (...) { - return true; + } catch (std::runtime_error& err) { + NeBuild::Logger::info() << "error: " << err.what() << std::endl; + return false; } } catch (std::runtime_error& err) { NeBuild::Logger::info() << "error: " << err.what() << std::endl; - return false; } -- cgit v1.2.3 From 67f502af0e8194d4dfd9010c297e51b40a85e7fc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 16 Nov 2025 10:25:44 +0100 Subject: feat: wip TOML support for NeBuild TOML files. fix: JSON: fix broken JSON implementation. Signed-off-by: Amlal El Mahrouss --- dev/BuildKit/TOMLManifestBuilder.h | 2 +- dev/cli/App.cc | 83 ++++++++++++++++++ dev/cli/Tool.cc | 76 ----------------- dev/src/JSONManifestBuilder.cc | 56 ++----------- dev/src/TOMLManifestBuilder.cc | 98 ++++++++++++++++++++++ .../example_03_hello_world_toml/hello_world.cc | 7 ++ examples/example_03_hello_world_toml/posix.toml | 8 ++ examples/example_03_hello_world_toml/win64.toml | 8 ++ 8 files changed, 210 insertions(+), 128 deletions(-) create mode 100644 dev/cli/App.cc delete mode 100644 dev/cli/Tool.cc create mode 100644 dev/src/TOMLManifestBuilder.cc create mode 100644 examples/example_03_hello_world_toml/hello_world.cc create mode 100644 examples/example_03_hello_world_toml/posix.toml create mode 100644 examples/example_03_hello_world_toml/win64.toml diff --git a/dev/BuildKit/TOMLManifestBuilder.h b/dev/BuildKit/TOMLManifestBuilder.h index 10a8200..9c4a3a0 100644 --- a/dev/BuildKit/TOMLManifestBuilder.h +++ b/dev/BuildKit/TOMLManifestBuilder.h @@ -27,7 +27,7 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { /// @param arg_val filename path. /// @retval true build succeeded. /// @retval false failed to build. - bool BuildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; const char* BuildSystem() override; }; } // namespace NeBuild \ No newline at end of file diff --git a/dev/cli/App.cc b/dev/cli/App.cc new file mode 100644 index 0000000..ca81d4e --- /dev/null +++ b/dev/cli/App.cc @@ -0,0 +1,83 @@ + +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#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") { + 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/Tool.cc b/dev/cli/Tool.cc deleted file mode 100644 index 1d49c9f..0000000 --- a/dev/cli/Tool.cc +++ /dev/null @@ -1,76 +0,0 @@ - -// ============================================================= // -// nebuild -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#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() << "Brought to you by Amlal El Mahrouss for NeKernel.org.\n"; - NeBuild::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\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") { - 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 { - NeBuild::Logger::info() - << "error: file '" << index_path << "' is not a JSON file!" << std::endl; - kFailed = true; - return; - } - - 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 e045f6c..daf47af 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -5,10 +5,6 @@ #include -#if defined(NEBUILD_POSIX) -#include -#endif - using JSON = nlohmann::json; namespace FS = std::filesystem; @@ -48,12 +44,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr std::string compiler = json_obj["compiler_path"].get(); - if (compiler != "g++" || !compiler.starts_with("clang")) { - NeBuild::Logger::info() << "nebuild: error: compiler '" << compiler - << "' is not a valid C/C++ compiler!" << std::endl; - return false; - } - std::string command = compiler + " "; JSON header_search_path = json_obj["compiler_headers_path"]; @@ -63,6 +53,11 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr } 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) { @@ -91,15 +86,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr NeBuild::Logger::info() << "output path: " << target << "\n"; NeBuild::Logger::info() << "command: " << command << "\n"; - try { - if (json_obj["dry_run"].get()) return true; - } catch (...) { - } - - if (dry_run) { - return true; - } - auto ret_exec = std::system(command.c_str()); if (ret_exec > 0) { @@ -107,38 +93,6 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr << std::endl; return false; } - - try { - if (json_obj["run_after_build"].get()) { - if (target.ends_with(".so") || target.ends_with(".dylib")) { -#if defined(NEBUILD_POSIX) - auto dll = dlopen(target.c_str(), RTLD_LAZY); - - if (dll) { - int (*entrypoint)(void) = nullptr; - entrypoint = (decltype(entrypoint)) dlsym(dll, "shared_runner"); - - if (entrypoint) entrypoint(); - - dlclose(dll); - - return true; - } -#endif - - return false; - } - -#if defined(NEBUILD_WINDOWS) - std::system((".\\" + target).c_str()); -#else - std::system(("./" + target).c_str()); -#endif - } - } catch (std::runtime_error& err) { - NeBuild::Logger::info() << "error: " << err.what() << std::endl; - return false; - } } catch (std::runtime_error& err) { NeBuild::Logger::info() << "error: " << err.what() << std::endl; return false; diff --git a/dev/src/TOMLManifestBuilder.cc b/dev/src/TOMLManifestBuilder.cc new file mode 100644 index 0000000..d975adf --- /dev/null +++ b/dev/src/TOMLManifestBuilder.cc @@ -0,0 +1,98 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#include + +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; + + 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(); + + for (auto& headers : header_search_path) { + command += "-I" + headers.as_string()->get() + " "; + } + + auto headers_path = *toml_file["headers_path"].as_array(); + + for (auto& headers : headers_path) { + command += "-I" + headers.as_string()->get() + " "; + } + + + auto sources_files = *toml_file["sources_path"].as_array(); + + for (auto& sources : sources_files) { + command += sources.as_string()->get() + " "; + } + + auto macros_list = *toml_file["cpp_macros"].as_array(); + + for (auto& macro : macros_list) { + command += "-D" + macro.as_string()->get() + " "; + } + + auto compiler_flags = *toml_file["compiler_flags"].as_array(); + + for (auto& flag : compiler_flags) { + command += flag.as_string()->get() + " "; + } + + if (toml_file["compiler_std"].is_string()) + command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; + + 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"; + + 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: " << err.what() << std::endl; + return false; + } + + return true; +} + +const char* TOMLManifestBuilder::BuildSystem() { + return "NeBuild (TOML)"; +} diff --git a/examples/example_03_hello_world_toml/hello_world.cc b/examples/example_03_hello_world_toml/hello_world.cc new file mode 100644 index 0000000..ae47ce8 --- /dev/null +++ b/examples/example_03_hello_world_toml/hello_world.cc @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char** argv) { + std::cout << "hello, world!\n"; + return 0; +} diff --git a/examples/example_03_hello_world_toml/posix.toml b/examples/example_03_hello_world_toml/posix.toml new file mode 100644 index 0000000..4f71f7d --- /dev/null +++ b/examples/example_03_hello_world_toml/posix.toml @@ -0,0 +1,8 @@ +compiler_path = "g++" +compiler_std = "c++20" +headers_path = [ "lib" ] +sources_path = [ "hello_world.cc" ] +output_name = "hello_world.elf" +compiler_flags = [ "-fPIC" ] +cpp_macros = [ "FOO_MACRO" ] +run_after_build = true diff --git a/examples/example_03_hello_world_toml/win64.toml b/examples/example_03_hello_world_toml/win64.toml new file mode 100644 index 0000000..c8001a4 --- /dev/null +++ b/examples/example_03_hello_world_toml/win64.toml @@ -0,0 +1,8 @@ +compiler_path = "x86_64-w64-mingw32-g++" +compiler_std = "c++20" +headers_path = [ "lib" ] +sources_path = [ "hello_world.cc" ] +output_name = "hello_world.elf" +compiler_flags = [ "-fPIC" ] +cpp_macros = [ "FOO_MACRO" ] +run_after_build = true -- cgit v1.2.3 From 00b91cf6a99656e244dc4c5d37d645bd5343c040 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 16 Nov 2025 11:20:03 +0100 Subject: feat: TOML support. Signed-off-by: Amlal El Mahrouss --- dev/src/TOMLManifestBuilder.cc | 45 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/dev/src/TOMLManifestBuilder.cc b/dev/src/TOMLManifestBuilder.cc index d975adf..e35416a 100644 --- a/dev/src/TOMLManifestBuilder.cc +++ b/dev/src/TOMLManifestBuilder.cc @@ -34,39 +34,48 @@ bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr 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(); + auto header_search_path = toml_file["compiler_headers_path"].as_array(); - for (auto& headers : header_search_path) { - command += "-I" + headers.as_string()->get() + " "; + 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(); + auto headers_path = toml_file["headers_path"].as_array(); - for (auto& headers : headers_path) { - command += "-I" + headers.as_string()->get() + " "; + if (headers_path) { + for (auto& headers : *headers_path) { + command += "-I" + headers.as_string()->get() + " "; + } } + auto sources_files = toml_file["sources_path"].as_array(); - auto sources_files = *toml_file["sources_path"].as_array(); - - for (auto& sources : sources_files) { - command += sources.as_string()->get() + " "; + if (sources_files) { + for (auto& sources : *sources_files) { + command += sources.as_string()->get() + " "; + } } - auto macros_list = *toml_file["cpp_macros"].as_array(); + auto macros_list = toml_file["cpp_macros"].as_array(); - for (auto& macro : macros_list) { - command += "-D" + macro.as_string()->get() + " "; + if (macros_list) { + for (auto& macro : *macros_list) { + command += "-D" + macro.as_string()->get() + " "; + } } - auto compiler_flags = *toml_file["compiler_flags"].as_array(); + auto compiler_flags = toml_file["compiler_flags"].as_array(); - for (auto& flag : compiler_flags) { - command += flag.as_string()->get() + " "; - } + if (compiler_flags) { + for (auto& flag : *compiler_flags) { + command += flag.as_string()->get() + " "; + } + } if (toml_file["compiler_std"].is_string()) command += "-std=" + toml_file["compiler_std"].as_string()->get() + " "; -- cgit v1.2.3 From c782117221f0b8f0bb018df673f935c1791fee32 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 17 Nov 2025 10:05:45 +0100 Subject: feat: NeBuild ReadMe improvements. Signed-off-by: Amlal El Mahrouss --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index d134b83..8516959 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -16,4 +16,4 @@ - Run `nebuild` and pass the path to the manifest file. -###### Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel.org Authors, all rights reserved. +###### Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel.org Authors, licensed under the BSD 3 Clause license. -- cgit v1.2.3