commit 45c2bf9426524d4c096c9c3740e2061d5ef95641 Author: Interfiber Date: Fri Sep 27 20:02:30 2024 -0400 init diff --git a/.gdb_history b/.gdb_history new file mode 100644 index 0000000..c7e43df --- /dev/null +++ b/.gdb_history @@ -0,0 +1,14 @@ +q +r +up +up +up +up +up +up +up +up +up +up +bt +q diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..876e81d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +.cache +vendor/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..21ee70d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "Lua.diagnostics.globals": [ + "grbc_file", + "grbc_executable", + "grbc_want_version", + "grbc_build", + "grbc_load_platform" + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9dd117c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.28) + +project(grbc) + +add_subdirectory("vendor/sol2") + +include_directories("include") +include_directories("vendor/sol2/include") + +add_executable(grbc src/main.cc src/utils.cc src/file.cc src/target_exe.cc src/platform.cc src/ninja.cc src/generator.cc) +target_link_libraries(grbc sol2 lua) \ No newline at end of file diff --git a/HConfig b/HConfig new file mode 100644 index 0000000..22d3311 --- /dev/null +++ b/HConfig @@ -0,0 +1,33 @@ +grbc_want_version("1.0") +grbc_load_platform("platform.hcfg") + +local grbc_exe = grbc_executable(ExecutableConfig.new({ + name = "grbc", + language_type = LanguageType.Cpp, + files = { + grbc_file("src/main.cc"), + grbc_file("src/file.cc"), + grbc_file("src/ninja.cc"), + grbc_file("src/platform.cc"), + grbc_file("src/target_exe.cc"), + grbc_file("src/utils.cc"), + grbc_file("src/generator.cc") + }, + + requirements = { + Package.new({ + name = "lua", + compiler_flags = "", + linker_flags = "-llua -lm -ldl" + }) + }, + compile_flags = {}, + linker_flags = {}, + include_dirs = { + grbc_file("include"), + grbc_file("vendor/sol2/include") + } +})) + +-- Output the final build script +grbc_build("ninja") \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2eb7e9b --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# GRBC +GRaphite Build Configurator + +## About +GRBC is a predictable build system. \ No newline at end of file diff --git a/build.ninja b/build.ninja new file mode 100644 index 0000000..23268c8 --- /dev/null +++ b/build.ninja @@ -0,0 +1,77 @@ +### GRBC BUILT-IN NINJA GENERATOR ### + +## Default variables ## + +builddir = build + +## build_rule_compile_cc ## + +cc_path = /usr/lib64/ccache/gcc +rule cc + command = $cc_path -MMD -MT $out -MF $out.d $p_cflags -c $in -o $out + description = Compiling C object $in + depfile = $out.d + deps = gcc + +## build_rule_compile_cxx ## + +cxx_path = /usr/lib64/ccache/g++ +rule cxx + command = $cxx_path -MMD -MT $out -MF $out.d $p_cflags -c $in -o $out + description = Compiling C++ object $in + depfile = $out.d + deps = gcc + +## build_rule_link_cc ## + +rule link_cc + command = $cc_path $p_cflags -o $out $in $p_linker_flags + description = Linking C executables $out + +## build_rule_link_cxx ## + +rule link_cxx + command = $cxx_path $p_cflags -o $out $in $p_linker_flags + description = Linking C++ executables $out + +## Compile: src/main.cc ## + +build $builddir/src/main.o: cxx src/main.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/file.cc ## + +build $builddir/src/file.o: cxx src/file.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/ninja.cc ## + +build $builddir/src/ninja.o: cxx src/ninja.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/platform.cc ## + +build $builddir/src/platform.o: cxx src/platform.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/target_exe.cc ## + +build $builddir/src/target_exe.o: cxx src/target_exe.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/utils.cc ## + +build $builddir/src/utils.o: cxx src/utils.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Compile: src/generator.cc ## + +build $builddir/src/generator.o: cxx src/generator.cc + p_cflags = -Iinclude -Ivendor/sol2/include + +## Link: grbc ## + +build grbc: link_cxx $builddir/src/main.o $builddir/src/file.o $builddir/src/ninja.o $builddir/src/platform.o $builddir/src/target_exe.o $builddir/src/utils.o $builddir/src/generator.o + p_linker_flags = -llua -lm -ldl + p_cflags = + diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..e47e92b --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,506 @@ +[ + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/grbc.dir", + "output": "cmake_object_order_depends_target_grbc" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/main.cc.o -MF CMakeFiles/grbc.dir/src/main.cc.o.d -o CMakeFiles/grbc.dir/src/main.cc.o -c /home/interfiber/dev/grbc/src/main.cc", + "file": "/home/interfiber/dev/grbc/src/main.cc", + "output": "CMakeFiles/grbc.dir/src/main.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/utils.cc.o -MF CMakeFiles/grbc.dir/src/utils.cc.o.d -o CMakeFiles/grbc.dir/src/utils.cc.o -c /home/interfiber/dev/grbc/src/utils.cc", + "file": "/home/interfiber/dev/grbc/src/utils.cc", + "output": "CMakeFiles/grbc.dir/src/utils.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/file.cc.o -MF CMakeFiles/grbc.dir/src/file.cc.o.d -o CMakeFiles/grbc.dir/src/file.cc.o -c /home/interfiber/dev/grbc/src/file.cc", + "file": "/home/interfiber/dev/grbc/src/file.cc", + "output": "CMakeFiles/grbc.dir/src/file.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/target_exe.cc.o -MF CMakeFiles/grbc.dir/src/target_exe.cc.o.d -o CMakeFiles/grbc.dir/src/target_exe.cc.o -c /home/interfiber/dev/grbc/src/target_exe.cc", + "file": "/home/interfiber/dev/grbc/src/target_exe.cc", + "output": "CMakeFiles/grbc.dir/src/target_exe.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/platform.cc.o -MF CMakeFiles/grbc.dir/src/platform.cc.o.d -o CMakeFiles/grbc.dir/src/platform.cc.o -c /home/interfiber/dev/grbc/src/platform.cc", + "file": "/home/interfiber/dev/grbc/src/platform.cc", + "output": "CMakeFiles/grbc.dir/src/platform.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/ninja.cc.o -MF CMakeFiles/grbc.dir/src/ninja.cc.o.d -o CMakeFiles/grbc.dir/src/ninja.cc.o -c /home/interfiber/dev/grbc/src/ninja.cc", + "file": "/home/interfiber/dev/grbc/src/ninja.cc", + "output": "CMakeFiles/grbc.dir/src/ninja.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/lib64/ccache/g++ -I/home/interfiber/dev/grbc/include -isystem /home/interfiber/dev/grbc/vendor/sol2/include -g -MD -MT CMakeFiles/grbc.dir/src/generator.cc.o -MF CMakeFiles/grbc.dir/src/generator.cc.o.d -o CMakeFiles/grbc.dir/src/generator.cc.o -c /home/interfiber/dev/grbc/src/generator.cc", + "file": "/home/interfiber/dev/grbc/src/generator.cc", + "output": "CMakeFiles/grbc.dir/src/generator.cc.o" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": ": && /usr/lib64/ccache/g++ -g CMakeFiles/grbc.dir/src/main.cc.o CMakeFiles/grbc.dir/src/utils.cc.o CMakeFiles/grbc.dir/src/file.cc.o CMakeFiles/grbc.dir/src/target_exe.cc.o CMakeFiles/grbc.dir/src/platform.cc.o CMakeFiles/grbc.dir/src/ninja.cc.o CMakeFiles/grbc.dir/src/generator.cc.o -o grbc -llua && :", + "file": "CMakeFiles/grbc.dir/src/main.cc.o", + "output": "grbc" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/edit_cache.util", + "output": "edit_cache" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/rebuild_cache.util", + "output": "rebuild_cache" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build && /usr/bin/cmake -P cmake_install.cmake", + "file": "all", + "output": "CMakeFiles/install.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/install.util", + "output": "install" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build && /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake", + "file": "all", + "output": "CMakeFiles/install/local.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/install/local.util", + "output": "install/local" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build && /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake", + "file": "all", + "output": "CMakeFiles/install/strip.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "CMakeFiles/install/strip.util", + "output": "install/strip" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/Experimental", + "output": "vendor/sol2/Experimental" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/Nightly", + "output": "vendor/sol2/Nightly" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/Continuous", + "output": "vendor/sol2/Continuous" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyMemoryCheck", + "output": "vendor/sol2/NightlyMemoryCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyStart", + "output": "vendor/sol2/NightlyStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyUpdate", + "output": "vendor/sol2/NightlyUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyConfigure", + "output": "vendor/sol2/NightlyConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyBuild", + "output": "vendor/sol2/NightlyBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyTest", + "output": "vendor/sol2/NightlyTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyCoverage", + "output": "vendor/sol2/NightlyCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlyMemCheck", + "output": "vendor/sol2/NightlyMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/NightlySubmit", + "output": "vendor/sol2/NightlySubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalStart", + "output": "vendor/sol2/ExperimentalStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalUpdate", + "output": "vendor/sol2/ExperimentalUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalConfigure", + "output": "vendor/sol2/ExperimentalConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalBuild", + "output": "vendor/sol2/ExperimentalBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalTest", + "output": "vendor/sol2/ExperimentalTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalCoverage", + "output": "vendor/sol2/ExperimentalCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalMemCheck", + "output": "vendor/sol2/ExperimentalMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ExperimentalSubmit", + "output": "vendor/sol2/ExperimentalSubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousStart", + "output": "vendor/sol2/ContinuousStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousUpdate", + "output": "vendor/sol2/ContinuousUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousConfigure", + "output": "vendor/sol2/ContinuousConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousBuild", + "output": "vendor/sol2/ContinuousBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousTest", + "output": "vendor/sol2/ContinuousTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousCoverage", + "output": "vendor/sol2/ContinuousCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousMemCheck", + "output": "vendor/sol2/ContinuousMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/ContinuousSubmit", + "output": "vendor/sol2/ContinuousSubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/edit_cache.util", + "output": "vendor/sol2/edit_cache" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/rebuild_cache.util", + "output": "vendor/sol2/rebuild_cache" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build/vendor/sol2 && /usr/bin/cmake -P cmake_install.cmake", + "file": "vendor/sol2/all", + "output": "vendor/sol2/CMakeFiles/install.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/install.util", + "output": "vendor/sol2/install" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build/vendor/sol2 && /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake", + "file": "vendor/sol2/all", + "output": "vendor/sol2/CMakeFiles/install/local.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/install/local.util", + "output": "vendor/sol2/install/local" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "cd /home/interfiber/dev/grbc/build/vendor/sol2 && /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake", + "file": "vendor/sol2/all", + "output": "vendor/sol2/CMakeFiles/install/strip.util" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/CMakeFiles/install/strip.util", + "output": "vendor/sol2/install/strip" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/Continuous", + "output": "Continuous" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousBuild", + "output": "ContinuousBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousConfigure", + "output": "ContinuousConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousCoverage", + "output": "ContinuousCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousMemCheck", + "output": "ContinuousMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousStart", + "output": "ContinuousStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousSubmit", + "output": "ContinuousSubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousTest", + "output": "ContinuousTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ContinuousUpdate", + "output": "ContinuousUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/Experimental", + "output": "Experimental" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalBuild", + "output": "ExperimentalBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalConfigure", + "output": "ExperimentalConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalCoverage", + "output": "ExperimentalCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalMemCheck", + "output": "ExperimentalMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalStart", + "output": "ExperimentalStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalSubmit", + "output": "ExperimentalSubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalTest", + "output": "ExperimentalTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/ExperimentalUpdate", + "output": "ExperimentalUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/Nightly", + "output": "Nightly" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyBuild", + "output": "NightlyBuild" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyConfigure", + "output": "NightlyConfigure" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyCoverage", + "output": "NightlyCoverage" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyMemCheck", + "output": "NightlyMemCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyMemoryCheck", + "output": "NightlyMemoryCheck" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyStart", + "output": "NightlyStart" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlySubmit", + "output": "NightlySubmit" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyTest", + "output": "NightlyTest" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "vendor/sol2/NightlyUpdate", + "output": "NightlyUpdate" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "", + "file": "grbc", + "output": "all" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/bin/cmake -P /home/interfiber/dev/grbc/build/CMakeFiles/VerifyGlobs.cmake", + "file": "/home/interfiber/dev/grbc/build/CMakeFiles/VerifyGlobs.cmake_force", + "output": "/home/interfiber/dev/grbc/build/CMakeFiles/cmake.verify_globs" + }, + { + "directory": "/home/interfiber/dev/grbc/build", + "command": "/usr/bin/cmake --regenerate-during-build -S/home/interfiber/dev/grbc -B/home/interfiber/dev/grbc/build", + "file": "/home/interfiber/dev/grbc/build/CMakeFiles/cmake.verify_globs", + "output": "build.ninja" + } +] diff --git a/include/grbc/generator.h b/include/grbc/generator.h new file mode 100644 index 0000000..df89be7 --- /dev/null +++ b/include/grbc/generator.h @@ -0,0 +1,46 @@ +#pragma once +#include "grbc/spec.h" +#include +#include + +struct GeneratorResult { + std::string file_name; + std::string content; +}; + +struct GeneratorCompileCommand { + LanguageType language_type; + + std::string source_file; + std::string object_file; + + std::string compiler_flags; +}; + +struct GeneratorLinkExecutableCommand { + std::vector object_files; + + std::string output_exe; + + std::string linker_flags; +}; + +struct GeneratorTarget { + std::vector compile_commands; + std::vector link_executable_commands; +}; + +typedef GeneratorResult (*Generator_Run)(); + +struct Generator { + /// Name of the generator, used in grbc_build(...) + std::string name; + + /// Function pointer for this generator + Generator_Run func; +}; + +/** + * Ninja generator main function + */ +GeneratorResult ninja_generator(); \ No newline at end of file diff --git a/include/grbc/helpers.h b/include/grbc/helpers.h new file mode 100644 index 0000000..bbdd5e8 --- /dev/null +++ b/include/grbc/helpers.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#define log_msg(message) printf("> %s\n", message); + +inline std::vector split_string(std::string s, + std::string delimiter) { + size_t pos_start = 0, pos_end, delim_len = delimiter.length(); + std::string token; + std::vector res; + + while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) { + token = s.substr(pos_start, pos_end - pos_start); + pos_start = pos_end + delim_len; + res.push_back(token); + } + + res.push_back(s.substr(pos_start)); + return res; +} \ No newline at end of file diff --git a/include/grbc/ninja.h b/include/grbc/ninja.h new file mode 100644 index 0000000..569aad2 --- /dev/null +++ b/include/grbc/ninja.h @@ -0,0 +1,40 @@ +#pragma once +#include "grbc/generator.h" +#include + +/** + * Generate the build rule for compiling c++ files + */ +std::string ninja_build_rule_compile_cxx(); + +/** + * Generate the build rule for compiling c files + */ +std::string ninja_build_rule_compile_cc(); + +/** + * Generate the build rule for linking c++ object files + */ +std::string ninja_build_rule_link_cxx(); + +/** + * Generate the build rule for linking c object files + */ +std::string ninja_build_rule_link_cc(); + +/** + * Generate a line which builds the given file + */ +std::string +ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd); + +/** + * Default variables such as builddir + */ +std::string ninja_build_default_variables(); + +/** + * Generate a line which links the given file + */ +std::string ninja_build_rule_link_exe_target( + const GeneratorLinkExecutableCommand &link_cmd); \ No newline at end of file diff --git a/include/grbc/spec.h b/include/grbc/spec.h new file mode 100644 index 0000000..4031e92 --- /dev/null +++ b/include/grbc/spec.h @@ -0,0 +1,150 @@ +#pragma once +#include +#include +#include + +#define GRBC_VERSION "1.0" + +enum LanguageType { LanguageType_CPP, LanguageType_C }; + +struct TargetInfo { + /// Name of the target + std::string name; +}; + +struct Package { + Package(const sol::table &table) { + name = table.get("name"); + compiler_flags = table.get("compiler_flags"); + linker_flags = table.get("linker_flags"); + } + + std::string name; + + std::string compiler_flags; + + std::string linker_flags; +}; + +struct PackageConfig { + std::string name; + + std::vector libraries; + + std::vector include_dirs; + + std::vector compile_flags; + + std::vector linker_flags; +}; + +enum PlatformType { PlatformType_Win32, PlatformType_Linux }; + +struct GlobalConfig { + /// Version of the grbc executable + std::string engine_version = GRBC_VERSION; + + /// Architecture string + std::string architecture; + + /// Build directory + std::string build_dir = "build"; + + /// System that we are targetting + PlatformType target; + + /// Path to the target.hcfg + std::string target_config; +}; + +struct ExecutableConfig { + ExecutableConfig(const sol::table &table) { + name = table.get("name"); + files = table.get>("files"); + requirements = table.get>("requirements"); + + compile_flags = table.get>("compile_flags"); + linker_flags = table.get>("linker_flags"); + include_dirs = table.get>("include_dirs"); + + language_type = table.get("language_type"); + } + + /// Name of the executable + std::string name; + + /// Type of language + LanguageType language_type; + + /// List of files to compile + std::vector files; + + /// Requirments of the executable + std::vector requirements; + + /// Compiler flags + std::vector compile_flags; + + /// Linker flags + std::vector linker_flags; + + /// Include directories + std::vector include_dirs; +}; + +struct Platform { + /// Name of the platform + std::string name; + + /// C++ compiler + std::string cxx_compiler; + + /// C compiler + std::string cc_compiler; + + /// Is this platform 64-bit? + bool is_64bit = true; + + /// Type of the platform + PlatformType platform_type; +}; + +/// Functions + +void grbc_want_version(const std::string &version); + +void grbc_exception(const std::string &exception_string); + +GlobalConfig grbc_get_config(); + +std::string grbc_file(const std::string &file_path); + +TargetInfo grbc_executable(const ExecutableConfig &executable_config); + +void grbc_load_platform(const std::string &file_path); + +void grbc_set_platform(const Platform &platform); + +std::string grbc_find_compiler(const std::string &compiler_name); + +void grbc_build(const std::string &generator_id); + +std::string grbc_object_file(const std::string &file_path); + +std::string grbc_replace_string(const std::string &string, char substring, + char replacement); + +std::string +grbc_include_dirs_to_cflags(const std::vector &include_dirs); + +void grbc_log(const std::string &message); + +bool grbc_is_win32(); + +bool grbc_is_linux(); + +PlatformType grbc_get_platform(); + +bool grbc_is_64bit(); + +bool grbc_is_32bit(); \ No newline at end of file diff --git a/include/grbc/state.h b/include/grbc/state.h new file mode 100644 index 0000000..fd16637 --- /dev/null +++ b/include/grbc/state.h @@ -0,0 +1,21 @@ +#pragma once +#include "grbc/generator.h" +#include "grbc/spec.h" +#include + +struct GState { + Platform current_platform; + sol::state lua; + + std::vector targets; + + std::vector generators; + + std::string ninja_output; + + static GState& get() { + static GState state{}; + + return state; + } +}; \ No newline at end of file diff --git a/platform.hcfg b/platform.hcfg new file mode 100644 index 0000000..2dc11dd --- /dev/null +++ b/platform.hcfg @@ -0,0 +1,12 @@ +-- Linux platform + +local platform = Platform.new() + +platform.name = "Linux64" +platform.cxx_compiler = grbc_find_compiler("g++") +platform.cc_compiler = grbc_find_compiler("gcc") +platform.is_64bit = true -- If set to false the compiler will need to produce 32bit code + +platform.platform_type = PlatformType.Linux + +return platform diff --git a/spec/datatypes.md b/spec/datatypes.md new file mode 100644 index 0000000..c30a363 --- /dev/null +++ b/spec/datatypes.md @@ -0,0 +1,165 @@ +# GRBC datatypes + +## PackageConfig +```c++ +struct PackageConfig { + /// Name of the package + string name; + + /// List of libraries to include + Array libraries; + + /// List of include directories + Array include_dirs; + + /// Extra compiler flags + Array compile_flags; + + /// Extra linker flags + Array linker_flags; +}; +``` + +## Package +```c++ +struct Package { + /// Name of the package + string name; + + /// Compiler flags used in this package + string compile_flags; + + /// Linker flags used in this package + string linker_flags; +}; +``` + +## LibraryConfig +```c++ +struct LibraryConfig { + /// Name of the library + string name; + + /// List of files to compile + Array files; + + /// Type of library + LibraryType lib_type; + + /// Requirments of the library + Array requirements; + + /// Compiler flags + Array compile_flags; + + /// Linker flags + Array linker_flags; + + /// Include directories + Array include_dirs; +}; +``` + +## LibraryType +```c++ +enum LibraryType { + LibraryType_Shared, + LibraryType_Static +}; +``` + +## ExecutableConfig +```c++ +struct ExecutableConfig { + /// Name of the executable + string name; + + /// Type of language + LanguageType language_type; + + /// List of files to compile + Array files; + + /// Requirments of the executable + Array requirements; + + /// Compiler flags + Array compile_flags; + + /// Linker flags + Array linker_flags; + + /// Include directories + Array include_dirs; +}; +``` + +## TargetInfo +```c++ +struct TargetInfo { + /// Name of the target + string name; + + /// List of compile commands for this target. should produce an executable, or library. + Array compile_commands; +}; +``` + +## PlatformType +```c++ +enum PlatformType { + PlatformType_Win32, + PlatformType_Linux +}; +``` + +## GlobalConfig +```c++ +struct GlobalConfig { + /// Version of the grbc executable + string engine_version; + + /// Architecture string + string architecture; + + /// Platform to target (pulled from the target config) + PlatformTarget target; + + /// Path to the target.hcfg + path target_config; +}; +``` + +## OptionalFileType +``` +enum OptionalFileType { + OFileType_IsWin32, + OFileType_IsUnix, + OFileType_IsLinux +}; +``` + +## Platform +```c++ +struct Platform { + /// Name of the platform + string name; + + /// C++ compiler + string cxx_compiler; + + /// C compiler + string cc_compiler; + + /// Type of the platform + PlatformType platform_type; +}; +``` + +## LanguageType +```c++ +enum LanguageType { + LanguageType_CPP, + LanguageType_C +}; +``` \ No newline at end of file diff --git a/spec/ext.md b/spec/ext.md new file mode 100644 index 0000000..a9127de --- /dev/null +++ b/spec/ext.md @@ -0,0 +1,16 @@ +# GRBC extensions +Extensions can be loaded at runtime using grbc_ext(...), functions are then dumped into the runtime + +## How extensions work +Extensions are built into the grbc executable, or can be compiled as a shared library and put into ```/usr/local/share/grbc/extensions```, ```C:\GRBC\Extensions\```, or ```~/.local/share/grbc/extensions``` + +## Extension list +* GRBC_EXT_pkg_config [NOSUPPORT] +* GRBC_EXT_multi_file [NOSUPPORT] +* GRBC_EXT_cmake [NOSUPPORT] + +## GRBC_EXT_pkg_config +Pkg config support. UNIX only + +## GRBC_EXT_multi_file +Multi file GRBC scripts, supported on all systems. \ No newline at end of file diff --git a/spec/ext/GRBC_EXT_multi_file.md b/spec/ext/GRBC_EXT_multi_file.md new file mode 100644 index 0000000..cfc9477 --- /dev/null +++ b/spec/ext/GRBC_EXT_multi_file.md @@ -0,0 +1,23 @@ +# GRBC_EXT_multi_file +Multiple file support + +## Support +GRBC_EXT_multi_file is supported on all systems + +## Example +```lua +-- No need to check since its always present! +grbc_ext("GRBC_EXT_multi_file") + + +-- Load a project from a folder which contains an HConfig file +grbc_multi_file_import("FusionVk") + +-- Load a project from a file besides HConfig +grbc_multi_file_import("OtherProject.hcfg") +``` + +## Functions + +### grbc_multi_file_import(file_path: String) -> Void +Import a project from the given folder \ No newline at end of file diff --git a/spec/functions.md b/spec/functions.md new file mode 100644 index 0000000..70cfb36 --- /dev/null +++ b/spec/functions.md @@ -0,0 +1,71 @@ +# GRBC functions +See [datatypes.md](./datatypes.md) for data types/structures + +## [X] grbc_get_config() -> GlobalConfig +Get the config + +## [X] grbc_want_version(version: String) -> Void +Assure grbc is running on ```version``` + +## [X] grbc_log(message: String) -> Void +Log ```message``` to the console + +## grbc_is_win32() -> Boolean +Check if we are targeting win32 + +## grbc_is_linux() -> Boolean +Check if we are targeting a Linux system + +## grbc_get_platform() -> PlatformType +Return the current platform + +## grbc_is_64bit() -> Boolean +Check if we are targeting a 64bit system + +## grbc_is_32bit() -> Boolean +Check if we are targeting a 32bit system + +## [X] grbc_executable(executable_config: ExecutableConfig) -> TargetInfo +Create a new executable and add it to the build list + +## grbc_library(library_config: LibraryConfig) -> TargetInfo +Create a new library and add it to the build list + +## [X] grbc_create_package(package_config: PackageConfig) -> Package +Create a new package + +## [X] grbc_file(file_path: String) -> Path +Used when listing source files, should perform pre-checks on the file and return its path + +## grbc_file_optional(file_type: OptionalFileType, file_path: String) -> Path +If file_type is true then file_path is returned, otherwise a blank string + +## grbc_has_ext(extension_name: String) -> Boolean +Check if the given extension is supported + +## grbc_ext(extension_name: String) -> Void +Load the given extension into the script + +## [X] grbc_exception(exception_string: String) -> Void +Throw an exception + +## [X] grbc_set_platform(current_platform: Platform) -> Void +Set the current platform + +## [X] grbc_load_platform(file_path: String) -> Void +Load a platform config file from file_path + +## [X] grbc_find_compiler(compiler_name: String) -> String +Find the given executable in the users PATH, and return the full path + +## [X] grbc_build(generator_id: String) -> Void +Output the final build script, using the given generator. "ninja" is the one provided by default + +## [X] grbc_object_file(file_path: String) -> String +Convert the given file path to an object file path + +## [X] grbc_replace_string(string: String, substring: Char, replacement: Char) -> String +Replace substring in string with replacement + +## [X] grbc_include_dirs_to_cflags(include_dirs: Array) -> String +Generate compiler flags to include the given directories \ No newline at end of file diff --git a/src/file.cc b/src/file.cc new file mode 100644 index 0000000..158a0a8 --- /dev/null +++ b/src/file.cc @@ -0,0 +1,10 @@ +#include "grbc/spec.h" +#include + +std::string grbc_file(const std::string &file_path) { + if (!std::filesystem::exists(file_path)) { + grbc_exception("grbc_file gave path '" + file_path + "', which does not exist!"); + } + + return file_path; +} \ No newline at end of file diff --git a/src/generator.cc b/src/generator.cc new file mode 100644 index 0000000..61d11be --- /dev/null +++ b/src/generator.cc @@ -0,0 +1,22 @@ +#include "grbc/generator.h" +#include "grbc/helpers.h" +#include "grbc/spec.h" +#include "grbc/state.h" +#include + +void grbc_build(const std::string &generator_id) { + log_msg(("finding generator with name: " + generator_id).c_str()); + + for (auto &gen : GState::get().generators) { + if (gen.name == generator_id) { + GeneratorResult result = gen.func(); + + std::ofstream ofs(result.file_name); + ofs << result.content; + + return; + } + } + + grbc_exception("Could not find valid generator!"); +} \ No newline at end of file diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..6e50158 --- /dev/null +++ b/src/main.cc @@ -0,0 +1,93 @@ +#include "grbc/state.h" +#define SOL_ALL_SAFETIES_ON 1 + +#include "grbc/helpers.h" +#include "grbc/spec.h" +#include + +int main() { + log_msg("opening lua libraries..."); + + auto &lua = GState::get().lua; + + lua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::string, + sol::lib::io, sol::lib::package, sol::lib::math); + + log_msg("setting up runtime..."); + + // TargetInfo + lua.new_usertype("TargetInfo", "name", &TargetInfo::name); + + // PackageConfig + lua.new_usertype( + "PackageConfig", "name", &PackageConfig::name, "libraries", + &PackageConfig::libraries, "include_dirs", &PackageConfig::include_dirs, + "compile_flags", &PackageConfig::compile_flags, "linker_flags", + &PackageConfig::linker_flags); + + // GlobalConfig + lua.new_usertype( + "GlobalConfig", "engine_version", &GlobalConfig::engine_version, + "architecture", &GlobalConfig::architecture, "target", + &GlobalConfig::target, "target_config", &GlobalConfig::target_config); + + // Platform + lua.new_usertype("Platform", "name", &Platform::name, + "cxx_compiler", &Platform::cxx_compiler, + "cc_compiler", &Platform::cc_compiler, + "platform_type", &Platform::platform_type, "is_64bit", &Platform::is_64bit); + + // PlatformType + lua.new_enum("PlatformType", {{"Win32", PlatformType_Win32}, + {"Linux", PlatformType_Linux}}); + + // LanguageType + lua.new_enum("LanguageType", { + { "Cpp", LanguageType_CPP }, + { "C", LanguageType_C } + }); + + // ExecutableConfig + lua.new_usertype( + "ExecutableConfig", sol::constructors(), + "name", &ExecutableConfig::name, "files", &ExecutableConfig::files, + "requirments", &ExecutableConfig::requirements, "compile_flags", + &ExecutableConfig::compile_flags, "linker_flags", + &ExecutableConfig::linker_flags, "include_dirs", + &ExecutableConfig::include_dirs, "language_type", &ExecutableConfig::language_type); + + // Package + lua.new_usertype("Package", sol::constructors(), "name", &Package::name, "compiler_flags", + &Package::compiler_flags, "linker_flags", + &Package::linker_flags); + + lua.set("grbc_want_version", grbc_want_version); + lua.set("grbc_exception", grbc_exception); + lua.set("grbc_get_config", grbc_get_config); + lua.set("grbc_file", grbc_file); + lua.set("grbc_executable", grbc_executable); + lua.set("grbc_load_platform", grbc_load_platform); + lua.set("grbc_set_platform", grbc_set_platform); + lua.set("grbc_find_compiler", grbc_find_compiler); + lua.set("grbc_build", grbc_build); + lua.set("grbc_replace_string", grbc_replace_string); + lua.set("grbc_object_file", grbc_object_file); + lua.set("grbc_include_dirs_to_clflags", grbc_include_dirs_to_cflags); + lua.set("grbc_log", grbc_log); + lua.set("grbc_is_32bit", grbc_is_32bit); + lua.set("grbc_is_64bit", grbc_is_64bit); + lua.set("grbc_is_linux", grbc_is_linux); + lua.set("grbc_is_win32", grbc_is_win32); + lua.set("grbc_get_platform", grbc_get_platform); + + // Load generators + + GState::get().generators.push_back({ + .name = "ninja", + .func = ninja_generator + }); + + log_msg("loading HConfig..."); + + lua.script_file("HConfig"); +} \ No newline at end of file diff --git a/src/ninja.cc b/src/ninja.cc new file mode 100644 index 0000000..ff87618 --- /dev/null +++ b/src/ninja.cc @@ -0,0 +1,128 @@ +#include "grbc/ninja.h" +#include "grbc/generator.h" +#include "grbc/helpers.h" +#include "grbc/spec.h" +#include "grbc/state.h" + +std::string ninja_build_rule_compile_cxx() { + std::string compiler_path = GState::get().current_platform.cxx_compiler; + + std::string result = + "## build_rule_compile_cxx ##\n\ncxx_path = " + compiler_path + "\n"; + result += "rule cxx\n"; + result += " command = $cxx_path -MMD -MT $out -MF $out.d $p_cflags -c $in " + "-o $out\n"; + result += " description = Compiling C++ object $in\n"; + result += " depfile = $out.d\n"; + result += " deps = gcc\n"; + result += "\n"; + + return result; +} + +std::string ninja_build_rule_compile_cc() { + std::string compiler_path = GState::get().current_platform.cc_compiler; + + std::string result = + "## build_rule_compile_cc ##\n\ncc_path = " + compiler_path + "\n"; + result += "rule cc\n"; + result += " command = $cc_path -MMD -MT $out -MF $out.d $p_cflags -c $in " + "-o $out\n"; + result += " description = Compiling C object $in\n"; + result += " depfile = $out.d\n"; + result += " deps = gcc\n"; + result += "\n"; + + return result; +} + +std::string ninja_build_rule_link_cxx() { + std::string result = "## build_rule_link_cxx ##\n\n"; + result += "rule link_cxx\n"; + result += " command = $cxx_path $p_cflags -o $out $in $p_linker_flags\n"; + result += " description = Linking C++ executables $out\n\n"; + + return result; +} + +std::string ninja_build_rule_link_cc() { + std::string result = "## build_rule_link_cc ##\n\n"; + result += "rule link_cc\n"; + result += " command = $cc_path $p_cflags -o $out $in $p_linker_flags\n"; + result += " description = Linking C executables $out\n\n"; + + return result; +} + +std::string +ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd) { + std::string result = "## Compile: " + compile_cmd.source_file + " ##\n\n"; + + std::string compiler_rule = "cxx"; + + if (compile_cmd.language_type == LanguageType_C) + compiler_rule = "cc"; + + result += "build $builddir/" + compile_cmd.object_file + ": " + + compiler_rule + " " + compile_cmd.source_file + "\n"; + result += " p_cflags = " + compile_cmd.compiler_flags + "\n\n"; + + return result; +} + +std::string ninja_build_default_variables() { + std::string result = "## Default variables ##\n\n"; + result += "builddir = " + grbc_get_config().build_dir + "\n"; + + result += "\n"; // keep as the last line + + return result; +} + +std::string ninja_build_rule_link_exe_target( + const GeneratorLinkExecutableCommand &link_cmd) { + std::string result = "## Link: " + link_cmd.output_exe + " ##\n\n"; + + std::string file_list; + + for (auto &file : link_cmd.object_files) { + file_list += "$builddir/" + file + " "; + } + + file_list.pop_back(); + + result += "build " + link_cmd.output_exe + ": link_cxx " + file_list + "\n"; + result += " p_linker_flags = " + link_cmd.linker_flags + "\n"; + result += " p_cflags = \n\n"; + + return result; +} + +// Ninja generator entry + +GeneratorResult ninja_generator() { + GeneratorResult result{}; + + log_msg("running ninja final generation..."); + + result.file_name = "build.ninja"; + + result.content += "### GRBC BUILT-IN NINJA GENERATOR ###\n\n"; + result.content += ninja_build_default_variables(); + result.content += ninja_build_rule_compile_cc(); + result.content += ninja_build_rule_compile_cxx(); + result.content += ninja_build_rule_link_cc(); + result.content += ninja_build_rule_link_cxx(); + + for (auto &target : GState::get().targets) { + for (auto &compile_cmd : target.compile_commands) { + result.content += ninja_build_rule_compile_file(compile_cmd); + } + + for (auto &link_cmd : target.link_executable_commands) { + result.content += ninja_build_rule_link_exe_target(link_cmd); + } + } + + return result; +} \ No newline at end of file diff --git a/src/platform.cc b/src/platform.cc new file mode 100644 index 0000000..ee01ec3 --- /dev/null +++ b/src/platform.cc @@ -0,0 +1,89 @@ +#include "grbc/helpers.h" +#include "grbc/spec.h" +#include "grbc/state.h" +#include +#include + +void grbc_set_platform(const Platform &platform) { + GState::get().current_platform = platform; + + if (!std::filesystem::exists(platform.cxx_compiler)) { + grbc_exception("C++ compiler path does not exist at '" + + platform.cxx_compiler + "'"); + } + + if (!std::filesystem::exists(platform.cc_compiler)) { + grbc_exception("C compiler path does not exist at '" + + platform.cc_compiler + "'"); + } + + log_msg("--- Platform config: ---"); + + log_msg(("C++ compiler = " + platform.cxx_compiler).c_str()); + log_msg(("C compiler = " + platform.cc_compiler).c_str()); +} + +void grbc_load_platform(const std::string &file_path) { + Platform platform = GState::get().lua.script_file(file_path); + + grbc_set_platform(platform); +} + +std::string grbc_find_compiler(const std::string &compiler_name) { +#if defined(WIN32) + std::string path_var = std::getenv("Path"); + + std::vector paths = split_string(path_var, ";"); + + for (auto ¤t_path : paths) { + if (std::filesystem::exists( + std::filesystem::path(current_path) / + std::filesystem::path(compiler_name + ".exe"))) { + return std::filesystem::path(current_path) / + std::filesystem::path(compiler_name + ".exe"); + } + } + + grbc_exception("Failed to locate compiler with name '" + compiler_name + "'"); + +#elif defined(__linux__) + std::string path_var = std::getenv("PATH"); + + std::vector paths = split_string(path_var, ":"); + + for (auto ¤t_path : paths) { + if (std::filesystem::exists(std::filesystem::path(current_path) / + std::filesystem::path(compiler_name))) { + return std::filesystem::path(current_path) / + std::filesystem::path(compiler_name); + } + } + + grbc_exception("Failed to locate compiler with name '" + compiler_name + "'"); + +#else + #error Invalid platform for grbc_find_compiler +#endif + + return "NoPlatform"; +} + +bool grbc_is_win32() { + return grbc_get_platform() == PlatformType_Win32; +} + +bool grbc_is_linux() { + return grbc_get_platform() == PlatformType_Linux; +} + +PlatformType grbc_get_platform() { + return GState::get().current_platform.platform_type; +} + +bool grbc_is_64bit() { + return GState::get().current_platform.is_64bit; +} + +bool grbc_is_32bit() { + return !grbc_is_64bit(); +} \ No newline at end of file diff --git a/src/target_exe.cc b/src/target_exe.cc new file mode 100644 index 0000000..117ae9b --- /dev/null +++ b/src/target_exe.cc @@ -0,0 +1,57 @@ +#include "grbc/generator.h" +#include "grbc/spec.h" +#include "grbc/state.h" + +TargetInfo grbc_executable(const ExecutableConfig &executable_config) { + TargetInfo target_config{}; + + std::string exe_name = executable_config.name; + std::string compiler_args; + std::string linker_args; + + for (auto &package : executable_config.requirements) { + compiler_args += package.compiler_flags + " "; + linker_args += package.linker_flags + " "; + } + + for (auto &linker_arg : executable_config.linker_flags) { + linker_args += linker_arg + " "; + } + + for (auto &compiler_arg : executable_config.compile_flags) { + compiler_args += compiler_arg + " "; + } + + // Include directories + + compiler_args += grbc_include_dirs_to_cflags(executable_config.include_dirs); + + GeneratorTarget target{}; + + std::vector object_files; + + for (auto &src_file : executable_config.files) { + GeneratorCompileCommand compile_cmd{}; + compile_cmd.source_file = src_file; + compile_cmd.object_file = grbc_object_file(src_file); + compile_cmd.compiler_flags = compiler_args; + compile_cmd.language_type = executable_config.language_type; + + object_files.push_back(compile_cmd.object_file); + + target.compile_commands.push_back(compile_cmd); + } + + // Final executable link + + GeneratorLinkExecutableCommand executable_link_cmd{}; + executable_link_cmd.linker_flags = linker_args; + executable_link_cmd.object_files = object_files; + executable_link_cmd.output_exe = exe_name; + + target.link_executable_commands.push_back(executable_link_cmd); + + GState::get().targets.push_back(target); + + return target_config; +} \ No newline at end of file diff --git a/src/utils.cc b/src/utils.cc new file mode 100644 index 0000000..387edc1 --- /dev/null +++ b/src/utils.cc @@ -0,0 +1,70 @@ +#include "grbc/helpers.h" +#include "grbc/spec.h" +#include +#include +#include + +void grbc_exception(const std::string &exception_string) { + printf("--- GRBC EXCEPTION: ---\n"); + printf("Message: %s\n", exception_string.c_str()); + printf("Timestamp: %ld", time(nullptr)); + + exit(EXIT_FAILURE); +} + +void grbc_want_version(const std::string &version) { + if (grbc_get_config().engine_version != version) { + grbc_exception("Expected engine_version " + version + ", got " + + grbc_get_config().engine_version); + } +} + +std::string grbc_object_file(const std::string &file_path) { + std::filesystem::path path(file_path); + path.replace_extension(".o"); + + std::string path_str = path.generic_string(); + + // Strip out stuff + std::string no_spaces = grbc_replace_string(path_str, ' ', '_'); + + return no_spaces; +} + +std::string grbc_replace_string(const std::string &string, char substring, + char replacement) { + + std::string res; + + for (char cChar : string) { + if (cChar == substring) { + res += replacement; + } else { + res += cChar; + } + } + + return res; +} + +GlobalConfig grbc_get_config() { + static GlobalConfig cfg{}; + + return cfg; +} + +std::string grbc_include_dirs_to_cflags(const std::vector &include_dirs) { + std::string result; + + for (auto &include_dir : include_dirs) { + result += "-I" + include_dir + " "; + } + + result.pop_back(); // Remove trailing space + + return result; +} + +void grbc_log(const std::string &message) { + log_msg(message.c_str()); +} \ No newline at end of file