#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()); grbc_get_config().platform_config = "in_memory"; } void grbc_load_platform(const std::string &file_path) { Platform platform = GState::get().lua.script_file(file_path); grbc_set_platform(platform); grbc_get_config().platform_config = file_path; } 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")).generic_string(); } } 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(); }