allow building with zig cc/c++

This commit is contained in:
2025-05-29 23:10:28 +03:00
parent 4ad8861572
commit 61481a1fac
8 changed files with 44 additions and 22 deletions

View File

@@ -6,8 +6,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED)
set(BUILD_AUDITOR OFF)
set(BUILD_TESTS OFF)
set(BUILD_AUDITOR OFF CACHE BOOL "Build the independent auditor library.")
set(BUILD_TESTS OFF CACHE BOOL "Build tests.")
# Conditionally define _GNU_SOURCE for Linux systems
if(UNIX AND NOT APPLE)
@@ -47,7 +49,9 @@ target_compile_options(hiload PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wno-declaration-after-statement -Wno-padded>
)
target_link_libraries(hiload dl elf)
target_link_libraries(hiload
dl
elf)
# Specify the public headers location
target_include_directories(hiload PUBLIC

View File

@@ -0,0 +1,6 @@
set (CMAKE_C_COMPILER zig cc)
set (CMAKE_CXX_COMPILER zig c++)
set (CMAKE_C_COMPILER_TARGET ${TARGET})
set (CMAKE_CXX_COMPILER_TARGET ${TARGET})
set (USING_ZIG TRUE)

View File

@@ -179,7 +179,7 @@ static void file_watcher_ctx_destroy(FileWatcherContext *ctx) {
// Declare the thread func
int file_watcher_watch(void *arg);
FileWatcher *filewatcher_create() {
FileWatcher *filewatcher_create(void) {
// Allocate context
FileWatcher *fw = malloc(sizeof(FileWatcher));

View File

@@ -236,7 +236,7 @@ int hi_init(size_t n, const char **enabled_modules) {
return 0;
}
void hi_deinit() {
void hi_deinit(void) {
moduler_deinit();
module_data_free(&context.modules);
filewatcher_destroy(context.filewatcher);
@@ -244,7 +244,7 @@ void hi_deinit() {
memset(&context, 0, sizeof(context));
}
HiResult hi_reload() {
HiResult hi_reload(void) {
handle_file_events(context.filewatcher, &context.modules);
reload_dirty_modules(&context);

View File

@@ -8,6 +8,6 @@ void log_set_verbose(bool value) {
atomic_store_explicit(&hiload_verbose_log, value, memory_order_relaxed);
}
bool log_get_verbose() {
bool log_get_verbose(void) {
return atomic_load_explicit(&hiload_verbose_log, memory_order_relaxed);
}

View File

@@ -3,7 +3,7 @@
#include "../3rd/sc/logger/sc_log.h"
void log_set_verbose(bool value);
bool log_get_verbose();
bool log_get_verbose(void);
#define log_init() (sc_log_init())
#define log_set_level(level) (sc_log_set_level((level)))
@@ -14,12 +14,27 @@ bool log_get_verbose();
#define log_warn(...) (sc_log_warn(__VA_ARGS__))
#define log_error(...) (sc_log_error(__VA_ARGS__))
#define log_debugv(...) do { if (log_get_verbose()) { \
log_debug(__VA_ARGS__); } } while(0)
#define log_infov(...) do { if (log_get_verbose()) { \
log_info(__VA_ARGS__); } } while(0)
#define log_warnv(...) do { if (log_get_verbose()) { \
log_warn(__VA_ARGS__); } } while(0)
#define log_errorv(...) do { if (log_get_verbose()) { \
log_error(__VA_ARGS__); } } while(0)
#define log_debugv(...) \
do { \
if (log_get_verbose()) { \
log_debug(__VA_ARGS__); \
} \
} while (0)
#define log_infov(...) \
do { \
if (log_get_verbose()) { \
log_info(__VA_ARGS__); \
} \
} while (0)
#define log_warnv(...) \
do { \
if (log_get_verbose()) { \
log_warn(__VA_ARGS__); \
} \
} while (0)
#define log_errorv(...) \
do { \
if (log_get_verbose()) { \
log_error(__VA_ARGS__); \
} \
} while (0)

View File

@@ -243,7 +243,6 @@ static HiResult moduler_patch_functions(VectorSymbol *psymbols,
return HI_FAIL;
}
int found_count = 0;
size_t rela_count = relasz / sizeof(ElfW(Rela));
printf("Processing %zu relocations\n", rela_count);
@@ -277,8 +276,6 @@ static HiResult moduler_patch_functions(VectorSymbol *psymbols,
*got_entry = s->address;
log_debug("Found GOT entry for '%s' at %p (points to %p)\n", name,
got_entry, *got_entry);
found_count++;
}
}
}
@@ -438,7 +435,7 @@ void moduler_init(const VectorModuleData *modules) {
}
}
void moduler_deinit() {
void moduler_deinit(void) {
SymbolData symdata = {0};
vector_foreach(&symbol_data, symdata) { symbols_term(&symdata.symbols); }
vector_term(&symbol_data);

View File

@@ -5,7 +5,7 @@ namespace minimal_lib {
int getNewValue(int x) {
static int value = 0;
value = value + x;
value = 42;
return value;
}