From 4f27819fa2c9156a66593c0bf713e2d736e74c7b Mon Sep 17 00:00:00 2001 From: Kevin Trogant Date: Thu, 8 Feb 2024 16:57:01 +0100 Subject: [PATCH] Improve dll build Still not perfect, but more user friendly now. --- meson.build | 14 ++++++++++++++ src/asset_compiler/pipeline_processor.c | 16 +++++++++------- src/game/meson.build | 7 +++++-- src/renderer/vk/meson.build | 6 +++++- src/runtime/gfx_main.c | 2 +- src/runtime/meson.build | 6 +++++- src/runtime/runtime.h | 2 ++ 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index f1acedd..707003f 100644 --- a/meson.build +++ b/meson.build @@ -45,6 +45,8 @@ if buildtype == 'debug' or buildtype == 'debugoptimized' add_project_arguments([ '-DRT_DEBUG'], language : ['c', 'cpp']) endif +fs = import('fs') + # Gather dependencies thread_dep = dependency('threads') m_dep = compiler.find_library('m', required : false) @@ -63,6 +65,10 @@ engine_incdir = include_directories('src') contrib_dir = meson.project_source_root() / 'contrib' +# Targets append to this, to enable us to run shared library builds from IDEs +engine_lib_paths = [] +engine_libs = [] + subdir('src') # Handle linking against both runtime and renderer if we build static libs @@ -90,4 +96,12 @@ assetc_dep = declare_dependency(link_with : asset_compiler, # "inline" game if get_option('game_as_subdir') subdir('src/game') + + # If we are building shared libraries, copy them to the games output directory. + # This ensures that we can debug with visual studio. + foreach lib_path : engine_lib_paths + run_target('copy'+fs.name(lib_path), + command : [copy_util, lib_path, join_paths(game_build_dir, fs.name(lib_path))], + depends : engine_libs) + endforeach endif diff --git a/src/asset_compiler/pipeline_processor.c b/src/asset_compiler/pipeline_processor.c index 354a169..db32faf 100644 --- a/src/asset_compiler/pipeline_processor.c +++ b/src/asset_compiler/pipeline_processor.c @@ -1,5 +1,5 @@ -#include "processor.h" #include "description_parser.h" +#include "processor.h" #include "shader_compiler.h" #include "runtime/buffer_manager.h" @@ -10,8 +10,8 @@ #include #include -#include #include +#include typedef struct { rt_attribute_binding *uniform_bindings; @@ -39,7 +39,7 @@ enum { RT_SHADER_NOT_PRESENT = RT_ASSET_PROCESSING_FAILED + 1 }; -extern rt_cvar rt_Renderer; +extern RT_DLLIMPORT rt_cvar rt_Renderer; static bool ParseBindingIndex(rt_text_span span, unsigned int *index) { if (span.length == 0) @@ -446,8 +446,10 @@ RT_ASSET_PROCESSOR_FN(PipelineProcessor) { goto out; rt_resource_id shader_resources[3] = {0}; - result = rtCreateResources(pipeline.shader_count, pipeline.shader_names, pipeline.shaders, - shader_resources); + result = rtCreateResources(pipeline.shader_count, + pipeline.shader_names, + pipeline.shaders, + shader_resources); if (result != RT_SUCCESS) goto out; @@ -494,7 +496,7 @@ RT_ASSET_PROCESSOR_FN(PipelineProcessor) { } rt_resource_id pipeline_id; const char *name = rtGetFilePath(file); - result = rtCreateResources(1, &name, &pipeline_resource, &pipeline_id); + result = rtCreateResources(1, &name, &pipeline_resource, &pipeline_id); if (result == RT_SUCCESS) { new_resources[0] = pipeline_id; memcpy(&new_resources[1], shader_resources, sizeof(shader_resources)); @@ -503,4 +505,4 @@ RT_ASSET_PROCESSOR_FN(PipelineProcessor) { out: rtReleaseBuffer(asset.buffer, asset.size); return result; -} \ No newline at end of file +} diff --git a/src/game/meson.build b/src/game/meson.build index ec0003c..7a4dd4d 100644 --- a/src/game/meson.build +++ b/src/game/meson.build @@ -1,10 +1,13 @@ vy_link_libs = engine_link_libs vy_link_libs += asset_compiler -executable('voyage', +game = executable('voyage', 'entry.c', 'main.c', link_with : vy_link_libs, include_directories : engine_incdir, c_pch : 'pch/game_pch.h', - win_subsystem : 'windows') + win_subsystem : 'windows', + install : true) + +game_build_dir = fs.parent(game.full_path()) \ No newline at end of file diff --git a/src/renderer/vk/meson.build b/src/renderer/vk/meson.build index b367410..438f1f7 100644 --- a/src/renderer/vk/meson.build +++ b/src/renderer/vk/meson.build @@ -31,6 +31,10 @@ if vk_dep.found() c_pch : 'pch/vk_pch.h', c_args : platform_defs, cpp_pch : 'pch/vk_pch.h', - cpp_args : platform_defs) + cpp_args : platform_defs, + install : true) + + engine_libs = vk_renderer_lib + engine_lib_paths += vk_renderer_lib.full_path() endif diff --git a/src/runtime/gfx_main.c b/src/runtime/gfx_main.c index 8688961..80b39f8 100644 --- a/src/runtime/gfx_main.c +++ b/src/runtime/gfx_main.c @@ -18,7 +18,7 @@ rt_renderer_api g_renderer; static rt_dynlib _renderer_lib; static bool _renderer_loaded = false; -RT_CVAR_S(rt_Renderer, "Select the render backend. Available options: [vk], Default: vk", "vk"); +RT_DLLEXPORT RT_CVAR_S(rt_Renderer, "Select the render backend. Available options: [vk], Default: vk", "vk"); #ifdef RT_STATIC_LIB extern void RT_RENDERER_API_FN(RegisterCVars)(void); diff --git a/src/runtime/meson.build b/src/runtime/meson.build index 1988f4a..9af01cb 100644 --- a/src/runtime/meson.build +++ b/src/runtime/meson.build @@ -52,4 +52,8 @@ runtime_lib = library('rt', contrib_dir / 'lz4/lz4.c', dependencies : runtime_deps, include_directories : [engine_incdir, runtime_incdirs], - c_pch : 'pch/rt_pch.h') + c_pch : 'pch/rt_pch.h', + install : true) + +engine_libs += runtime_lib +engine_lib_paths += runtime_lib.full_path() \ No newline at end of file diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 44af197..7a7f2b0 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -13,8 +13,10 @@ extern "C" { #if defined(_MSC_VER) && !defined(RT_STATIC_LIB) #define RT_DLLEXPORT __declspec(dllexport) +#define RT_DLLIMPORT __declspec(dllimport) #else #define RT_DLLEXPORT +#define RT_DLLIMPORT #endif #if defined(_MSC_VER)