Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# // ============================================================= //
# // nebuild
# // Copyright (C) 2025, Amlal El Mahrouss, licensed under BSD-3 license.
# // ============================================================= //

cmake_minimum_required(VERSION 3.16)

project(nebuild VERSION 0.1 LANGUAGES CXX)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# NeBuild

![CI](https://github.com/nekernel-org/nebuild/actions/workflows/c-cpp.yml/badge.svg)
![CI](https://github.com/nekernel-org/nebuild/actions/workflows/c-cpp-dev.yml/badge.svg)
[![License: GPL-3.0](https://img.shields.io/badge/license-BSD--3.0-blue.svg)](LICENSE)

Expand Down
2 changes: 1 addition & 1 deletion examples/example_01_hello_world/posix.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["hello_world.cc"],
"output_name": "hello_world.elf",
"output_name": "./hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
Expand Down
2 changes: 1 addition & 1 deletion examples/example_01_hello_world/win64.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["hello_world.cc"],
"output_name": "hello_world.elf",
"output_name": "./hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
Expand Down
2 changes: 1 addition & 1 deletion examples/example_02_libnebuild/posix.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sources_path": [
"libnebuild.cc"
],
"output_name": "libnebuild.elf",
"output_name": "./libnebuild.elf",
"compiler_flags": [
"-L/usr/lib",
"-lNeBuildKit"
Expand Down
2 changes: 1 addition & 1 deletion examples/example_02_libnebuild/win64.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sources_path": [
"libbtb.cc"
],
"output_name": "libbtb.exe",
"output_name": "./libbtb.exe",
"compiler_flags": [
"-lNeBuild"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/example_03_hello_world_toml/posix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ compiler_path = "clang++"
compiler_std = "c++20"
headers_path = [ "lib" ]
sources_path = [ "hello_world.cc" ]
output_name = "hello_world.elf"
output_name = "./hello_world.elf"
compiler_flags = [ "-fPIC" ]
cpp_macros = [ "FOO_MACRO" ]
run_after_build = true
2 changes: 1 addition & 1 deletion examples/example_03_hello_world_toml/win64.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ compiler_path = "x86_64-w64-mingw32-g++"
compiler_std = "c++20"
headers_path = [ "lib" ]
sources_path = [ "hello_world.cc" ]
output_name = "hello_world.elf"
output_name = "./hello_world.elf"
compiler_flags = [ "-fPIC" ]
cpp_macros = [ "FOO_MACRO" ]
run_after_build = true
6 changes: 3 additions & 3 deletions include/NeBuildKit/IManifestBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <NeBuildKit/Detail/Config.h>
#include <string_view>

#define NEBUILD_MANIFEST_BUILDER : public ::NeBuild::IManifestBuilder
#define NEBUILD_MANIFEST_BUILDER final : public ::NeBuild::IManifestBuilder

namespace NeBuild {
/// =========================================================== ///
Expand All @@ -29,11 +29,11 @@ class IManifestBuilder {
/// @retval true building has succeeded.
/// @retval false fail to build, see error message.
/// =========================================================== ///
virtual bool BuildTarget(BuildConfig& config) = 0;
virtual bool BuildTarget(BuildConfig& config) { return false; }

/// =========================================================== ///
/// @brief Returns the build system name.
/// =========================================================== ///
virtual const std::string_view BuildSystem() = 0;
virtual const std::string_view BuildSystem() { return "(null)"; }
};
} // namespace NeBuild
2 changes: 1 addition & 1 deletion include/NeBuildKit/JSONManifestBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace NeBuild {
/// @brief JSON builder
class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER {
class JSONManifestBuilder NEBUILD_MANIFEST_BUILDER {
public:
JSONManifestBuilder() = default;
~JSONManifestBuilder() override = default;
Expand Down
2 changes: 1 addition & 1 deletion include/NeBuildKit/TOMLManifestBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace NeBuild {
/// @brief TOML builder
class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER {
class TOMLManifestBuilder NEBUILD_MANIFEST_BUILDER {
public:
TOMLManifestBuilder() = default;
~TOMLManifestBuilder() override = default;
Expand Down
38 changes: 26 additions & 12 deletions src/lib/JSONManifestBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
#include <fstream>

namespace NeBuild {
using JSON = nlohmann::json;
namespace FS = std::filesystem;

/// =========================================================== ///
/// @brief Builds a JSON target from a JSON file.
/// @brief Builds a nlohmann::json target from a nlohmann::json file.
/// @param arg_sz filename size (must be 1 or greater).
/// @param arg_val filename path (must be a valid JSON file).
/// @param arg_val filename path (must be a valid nlohmann::json file).
/// @retval true building has succeeded.
/// @retval false fail to build, see error message.
/// =========================================================== ///
Expand All @@ -38,42 +37,42 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
std::ifstream json(path);

if (!json.good()) {
NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON"
<< std::endl;
NeBuild::Logger::info() << "nebuild: error: file '" << path
<< "' is not a valid nlohmann::json" << std::endl;
return false;
}

JSON json_obj = JSON::parse(json);
nlohmann::json json_obj = nlohmann::json::parse(json);

std::string compiler = json_obj["compiler_path"].get<std::string>();

std::string command = compiler + " ";

JSON header_search_path = json_obj["compiler_headers_path"];
nlohmann::json header_search_path = json_obj["compiler_headers_path"];

for (auto& headers : header_search_path) {
command += "-I" + headers.get<std::string>() + " ";
}

JSON headers_path = json_obj["headers_path"];
nlohmann::json headers_path = json_obj["headers_path"];

for (auto& headers : headers_path) {
command += "-I" + headers.get<std::string>() + " ";
}

JSON sources_files = json_obj["sources_path"];
nlohmann::json sources_files = json_obj["sources_path"];

for (auto& sources : sources_files) {
command += sources.get<std::string>() + " ";
}

JSON macros_list = json_obj["cpp_macros"];
nlohmann::json macros_list = json_obj["cpp_macros"];

for (auto& macro : macros_list) {
command += "-D" + macro.get<std::string>() + " ";
}

JSON compiler_flags = json_obj["compiler_flags"];
nlohmann::json compiler_flags = json_obj["compiler_flags"];

for (auto& flag : compiler_flags) {
command += flag.get<std::string>() + " ";
Expand All @@ -96,6 +95,21 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}

if (!config.dry_run_) {
auto run_after_build = json_obj["run_after_build"].get<bool>();

if (run_after_build) {
ret_exec = std::system(target.c_str());

if (ret_exec > 0) {
NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << ""
<< std::endl;
config.has_failed_ = true;
return false;
}
}
}
} catch (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;
Expand All @@ -109,6 +123,6 @@ bool JSONManifestBuilder::BuildTarget(BuildConfig& config) {
/// @brief Returns the build system name.
/// =========================================================== ///
const std::string_view JSONManifestBuilder::BuildSystem() {
return "NeBuild (JSON)";
return "NeBuild (nlohmann::json)";
}
} // namespace NeBuild
17 changes: 17 additions & 0 deletions src/lib/TOMLManifestBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) {
config.has_failed_ = true;
return false;
}

if (!config.dry_run_) {
auto run_after_build = toml_file["run_after_build"].as_boolean();
if (!run_after_build) return true;

auto val = run_after_build->get();
if (val) {
ret_exec = std::system(target.c_str());

if (ret_exec > 0) {
NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << ""
<< std::endl;
config.has_failed_ = true;
return false;
}
}
}
} catch (std::runtime_error& err) {
NeBuild::Logger::info() << "error: exit with message: " << err.what() << "" << std::endl;
config.has_failed_ = true;
Expand Down