From 87a3bf60c1a47614f00349edf38c8428fd30beaf Mon Sep 17 00:00:00 2001 From: LeonardoBizzoni Date: Thu, 21 Aug 2025 15:56:58 +0200 Subject: [PATCH] Updated `ProcessList` api & examples --- cbuild.h | 6 +++--- examples/02-async-commands/build.c | 10 +++++----- examples/03-stream-redirection/build.c | 5 +++-- examples/XX-codebase-build/build.c | 18 +++++++++--------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cbuild.h b/cbuild.h index 9664087..73a9f53 100755 --- a/cbuild.h +++ b/cbuild.h @@ -189,7 +189,7 @@ enum { .reset = true, \ __VA_ARGS__ \ }) -#define cb_processesslist_push(Dynarr, Value) cb_dyn_push(Dynarr, Value) +#define cb_proclist_push(Dynarr, Value) cb_dyn_push(Dynarr, Value) #define cb_dyn_free_custom(Dynarr, Values, Count) \ do { \ @@ -227,7 +227,7 @@ static void cb_print(CB_LogLevel level, const char *fmt, ...); static char* cb_getenv(char *varname); static bool cb_setenv(char *varname, char *value); static void cb_process_wait(CB_Process *handle); -static void cb_processesslist_wait(CB_ProcessList *procs); +static void cb_proclist_wait(CB_ProcessList *procs); static CB_Handle cb_handle_open(char *path, CB_AccessFlag permission); static void cb_handle_close(CB_Handle fd); static char* cb_handle_read(CB_Handle fd); @@ -334,7 +334,7 @@ static void cb_process_wait(CB_Process *proc) { #endif } -static void cb_processesslist_wait(CB_ProcessList *procs) { +static void cb_proclist_wait(CB_ProcessList *procs) { for (size_t i = 0; i < procs->count; ++i) { cb_process_wait(&procs->values[i]); } diff --git a/examples/02-async-commands/build.c b/examples/02-async-commands/build.c index f93fac3..5cfe60d 100644 --- a/examples/02-async-commands/build.c +++ b/examples/02-async-commands/build.c @@ -4,13 +4,13 @@ int main(int argc, char **argv) { cb_rebuild_self(argc, argv); cb_cmd cmd = {}; - cb_procs procs = {}; + CB_ProcessList procs = {}; cb_cmd_append(&cmd, "ls", "-lah", "."); - cb_procs_push(&procs, cb_run(&cmd, .async = true)); + cb_proclist_push(&procs, cb_run(&cmd, .async = true)); cb_cmd_append(&cmd, "ls", "-lah", "/"); - cb_procs_push(&procs, cb_run(&cmd, .async = true)); + cb_proclist_push(&procs, cb_run(&cmd, .async = true)); cb_cmd_append(&cmd, "pwd"); - cb_procs_push(&procs, cb_run(&cmd, .async = true)); + cb_proclist_push(&procs, cb_run(&cmd, .async = true)); - cb_procs_wait(&procs); + cb_proclist_wait(&procs); } diff --git a/examples/03-stream-redirection/build.c b/examples/03-stream-redirection/build.c index 6e024c9..82c39ee 100644 --- a/examples/03-stream-redirection/build.c +++ b/examples/03-stream-redirection/build.c @@ -3,7 +3,8 @@ int main(int argc, char **argv) { cb_rebuild_self(argc, argv); - cb_fd file = cb_open("ls-curdir-log", CB_ACF_READ | CB_ACF_WRITE); + CB_Handle file = cb_handle_open("ls-curdir-log", CB_AccessFlag_Read | + CB_AccessFlag_Write); cb_cmd cmd = {}; cb_cmd_append(&cmd, "ls", "-lah", "."); @@ -12,5 +13,5 @@ int main(int argc, char **argv) { cb_cmd_append(&cmd, "cat"); cb_run(&cmd, .stdin = file); - cb_close(file); + cb_handle_close(file); } diff --git a/examples/XX-codebase-build/build.c b/examples/XX-codebase-build/build.c index c1eb124..ab655c7 100644 --- a/examples/XX-codebase-build/build.c +++ b/examples/XX-codebase-build/build.c @@ -18,6 +18,7 @@ # define CppFlags "/TP", "/std:c++latest" # define CAnnoyingWarnings "/wd4477", "/wd4996" # define CppAnnoyingWarnings +# define OPENGL "gdi32.lib", "opengl32.lib" # define Output "/Fe" Outfile ".exe" #else # define SystemSharedLibs "-lpthread", "-lm" @@ -38,7 +39,6 @@ "-Wno-sign-conversion", \ "-Wno-unused-parameter" # define CppAnnoyingWarnings CAnnoyingWarnings \ - "-Wno-gnu-anonymous-struct", \ "-Wno-gnu-anonymous-struct", \ "-Wno-nested-anon-types" # define Output "-o", Outfile @@ -80,7 +80,7 @@ int main(int argc, char **argv) { cb_cmd cmd = {}; cb_cmd_append(&cmd, "git", "submodule", "update", "--recursive"); - cb_proc_handle codebase_updater = cb_run(&cmd, .async = true); + CB_Process codebase_updater = cb_run(&cmd, .async = true); #if OS_WINDOWS cb_cmd_push(&cmd, "cl.exe"); @@ -93,8 +93,7 @@ int main(int argc, char **argv) { #endif cb_cmd_append(&cmd, Output); - cb_cmd_append(&cmd, Infile, Codebase_Path); - cb_cmd_append(&cmd, GenericFlags, SystemSharedLibs); + cb_cmd_append(&cmd, Infile, Codebase_Path, GenericFlags); if (cpp) { cb_cmd_append(&cmd, CppFlags, CppAnnoyingWarnings); @@ -108,19 +107,20 @@ int main(int argc, char **argv) { cb_cmd_append(&cmd, ReleaseFlags); } + if (sound) { cb_cmd_append(&cmd, Codebase_Module_Sound); } if (gui) { cb_cmd_append(&cmd, Codebase_Module_Gui); - cb_cmd_append(&cmd, OPENGL); #if OS_LINUX || OS_BSD cb_cmd_append(&cmd, !strcmp(cb_getenv("XDG_SESSION_TYPE"), "x11") ? X11 : Wayland); #endif } - if (sound) { - cb_cmd_append(&cmd, Codebase_Module_Sound); - } + // NOTE(lb): Windows requires dlls to be all specified + // after the `/link` flag from what i understood + cb_cmd_append(&cmd, SystemSharedLibs); + if (gui) {cb_cmd_append(&cmd, OPENGL); } - cb_proc_wait(codebase_updater); + cb_process_wait(&codebase_updater); cb_run(&cmd); } -- 2.52.0