extension work + static library linking

This commit is contained in:
Hunter 2024-09-28 10:16:00 -04:00
parent ffa0f40652
commit b6ee9d0dc3
20 changed files with 568 additions and 131 deletions

3
include/grbc/ext.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
#define GRBC_EXT_pkg_config_NAME "GRBC_EXT_pkg_config"

View file

@ -3,6 +3,12 @@
#include <string>
#include <vector>
enum GeneratorTargetType {
GeneratorTargetType_Executable,
GeneratorTargetType_SharedLibrary,
GeneratorTargetType_StaticLibrary
};
struct GeneratorResult {
std::string file_name;
std::string content;
@ -17,17 +23,18 @@ struct GeneratorCompileCommand {
std::string compiler_flags;
};
struct GeneratorLinkExecutableCommand {
struct GeneratorLinkTargetCommand {
std::vector<std::string> object_files;
std::string output_exe;
std::string linker_flags;
std::string output_name;
GeneratorTargetType target_type;
};
struct GeneratorTarget {
std::vector<GeneratorCompileCommand> compile_commands;
std::vector<GeneratorLinkExecutableCommand> link_executable_commands;
std::vector<GeneratorLinkTargetCommand> link_target_commands;
};
typedef GeneratorResult (*Generator_Run)();

View file

@ -22,6 +22,11 @@ std::string ninja_build_rule_link_cxx();
*/
std::string ninja_build_rule_link_cc();
/**
* Generate the build rule for archiving object files into a shared library
*/
std::string ninja_build_rule_archive_library();
/**
* Generate a line which builds the given file
*/
@ -34,7 +39,13 @@ ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd);
std::string ninja_build_default_variables();
/**
* Generate a line which links the given file
* Generate a line which links the given file to an executable
*/
std::string ninja_build_rule_link_exe_target(
const GeneratorLinkExecutableCommand &link_cmd);
std::string
ninja_build_rule_link_exe_target(const GeneratorLinkTargetCommand &link_cmd);
/**
* Generate a line which links the given file to a library
*/
std::string
ninja_build_rule_link_lib_target(const GeneratorLinkTargetCommand &link_cmd);

View file

@ -1,11 +1,13 @@
#pragma once
#include <sol/table.hpp>
#include <sol/types.hpp>
#include <string>
#include <vector>
#define GRBC_VERSION "1.0"
enum LanguageType { LanguageType_CPP, LanguageType_C };
enum LibraryType { LibraryType_Shared, LibraryType_Static };
struct TargetInfo {
/// Name of the target
@ -19,6 +21,8 @@ struct Package {
linker_flags = table.get<std::string>("linker_flags");
}
Package() = default;
std::string name;
std::string compiler_flags;
@ -27,6 +31,16 @@ struct Package {
};
struct PackageConfig {
PackageConfig(const sol::table &table) {
name = table.get<std::string>("name");
libraries = table.get<std::vector<Package>>("libraries");
include_dirs = table.get<std::vector<std::string>>("include_dirs");
compile_flags = table.get<std::vector<std::string>>("compile_flags");
linker_flags = table.get<std::vector<std::string>>("linker_flags");
}
PackageConfig() = default;
std::string name;
std::vector<Package> libraries;
@ -50,21 +64,21 @@ struct GlobalConfig {
/// Build directory
std::string build_dir = "build";
/// System that we are targetting
PlatformType target;
/// Path to the target.hcfg
std::string target_config;
/// Path to the platform.hcfg, in_memory if not on-disk
std::string platform_config;
};
struct ExecutableConfig {
ExecutableConfig(const sol::table &table) {
name = table.get<std::string>("name");
files = table.get<std::vector<std::string>>("files");
requirements = table.get<std::vector<Package>>("requirements");
compile_flags = table.get<std::vector<std::string>>("compile_flags");
linker_flags = table.get<std::vector<std::string>>("linker_flags");
include_dirs = table.get<std::vector<std::string>>("include_dirs");
language_type = table.get<LanguageType>("language_type");
@ -77,19 +91,67 @@ struct ExecutableConfig {
LanguageType language_type;
/// List of files to compile
std::vector<std::string> files;
std::vector<std::string> files{};
/// Requirments of the executable
std::vector<Package> requirements;
std::vector<Package> requirements{};
/// Compiler flags
std::vector<std::string> compile_flags;
std::vector<std::string> compile_flags{};
/// Linker flags
std::vector<std::string> linker_flags;
std::vector<std::string> linker_flags{};
/// Include directories
std::vector<std::string> include_dirs;
std::vector<std::string> include_dirs{};
};
struct LibraryConfig {
LibraryConfig(const sol::table &table) {
name = table.get<std::string>("name");
files = table.get<std::vector<std::string>>("files");
requirements = table.get<std::vector<Package>>("requirements");
compile_flags = table.get<std::vector<std::string>>("compile_flags");
linker_flags = table.get<std::vector<std::string>>("linker_flags");
include_dirs = table.get<std::vector<std::string>>("include_dirs");
language_type = table.get<LanguageType>("language_type");
lib_type = table.get<LibraryType>("lib_type");
if (!table["package_config"].is<sol::nil_t>())
package_config = table.get<PackageConfig>("package_config");
}
/// Name of the executable
std::string name;
/// Type of language
LanguageType language_type;
/// Type of library
LibraryType lib_type;
/// Package config
PackageConfig package_config{};
/// List of files to compile
std::vector<std::string> files{};
/// Requirments of the executable
std::vector<Package> requirements{};
/// Compiler flags
std::vector<std::string> compile_flags{};
/// Linker flags
std::vector<std::string> linker_flags{};
/// Include directories
std::vector<std::string> include_dirs{};
};
struct Platform {
@ -115,12 +177,14 @@ void grbc_want_version(const std::string &version);
void grbc_exception(const std::string &exception_string);
GlobalConfig grbc_get_config();
GlobalConfig& grbc_get_config();
std::string grbc_file(const std::string &file_path);
TargetInfo grbc_executable(const ExecutableConfig &executable_config);
TargetInfo grbc_library(const LibraryConfig &library_config);
void grbc_load_platform(const std::string &file_path);
void grbc_set_platform(const Platform &platform);
@ -147,4 +211,13 @@ PlatformType grbc_get_platform();
bool grbc_is_64bit();
bool grbc_is_32bit();
bool grbc_is_32bit();
std::string grbc_compiler_define(const std::string &define,
const std::string &value);
std::string grbc_get_lib_extension(LibraryType lib_type);
Package grbc_bake_package_config(const PackageConfig &config);
Package grbc_pkg(const std::string &package_name);

View file

@ -2,15 +2,18 @@
#include "grbc/generator.h"
#include "grbc/spec.h"
#include <sol/sol.hpp>
#include <string>
#include <unordered_map>
struct GState {
Platform current_platform;
sol::state lua;
std::vector<GeneratorTarget> targets;
std::vector<Generator> generators;
std::unordered_map<std::string, Package> packages;
std::string ninja_output;
static GState& get() {