From 5d398efbd4c4663eefd825c90f4673cc07280fd8 Mon Sep 17 00:00:00 2001 From: auxves Date: Tue, 20 Feb 2024 15:42:56 -0800 Subject: [PATCH 1/3] generalize hot reload code for posix --- src/{hotreload_linux.c => hotreload_posix.c} | 7 ++++++- src/nob_linux.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) rename src/{hotreload_linux.c => hotreload_posix.c} (82%) diff --git a/src/hotreload_linux.c b/src/hotreload_posix.c similarity index 82% rename from src/hotreload_linux.c rename to src/hotreload_posix.c index a92807b..9e757a9 100644 --- a/src/hotreload_linux.c +++ b/src/hotreload_posix.c @@ -5,7 +5,12 @@ #include "hotreload.h" -static const char *libplug_file_name = "libplug.so"; +#if MUSIALIZER_TARGET == TARGET_MACOS + static const char *libplug_file_name = "libplug.dylib"; +#else + static const char *libplug_file_name = "libplug.so"; +#endif + static void *libplug = NULL; #define PLUG(name, ...) name##_t *name = NULL; diff --git a/src/nob_linux.c b/src/nob_linux.c index 24d4cb0..3bd9af2 100644 --- a/src/nob_linux.c +++ b/src/nob_linux.c @@ -34,7 +34,7 @@ bool build_musializer(void) nob_cmd_append(&cmd, "-o", "./build/musializer"); nob_cmd_append(&cmd, "./src/musializer.c", - "./src/hotreload_linux.c"); + "./src/hotreload_posix.c"); nob_cmd_append(&cmd, "-Wl,-rpath=./build/", "-Wl,-rpath=./", From b1cd29835b4625e75314d11b74b56d1f917b7adc Mon Sep 17 00:00:00 2001 From: auxves Date: Tue, 20 Feb 2024 15:46:49 -0800 Subject: [PATCH 2/3] implement hot reload for macos --- src/nob_macos.c | 53 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/nob_macos.c b/src/nob_macos.c index a8c8f5c..269588a 100644 --- a/src/nob_macos.c +++ b/src/nob_macos.c @@ -8,8 +8,40 @@ bool build_musializer(void) Nob_Procs procs = {0}; #ifdef MUSIALIZER_HOTRELOAD - nob_log(NOB_ERROR, "TODO: hotreloading is not supported on %s yet", NOB_ARRAY_GET(target_names, config.target)); - nob_return_defer(false); + procs.count = 0; + cmd.count = 0; + // TODO: add a way to replace `cc` with something else GCC compatible on POSIX + // Like `clang` for instance + nob_cmd_append(&cmd, "clang"); + nob_cmd_append(&cmd, "-Wall", "-Wextra", "-g"); + nob_cmd_append(&cmd, "-I./build/"); + nob_cmd_append(&cmd, "-I./raylib/raylib-"RAYLIB_VERSION"/src/"); + nob_cmd_append(&cmd, "-fPIC", "-shared"); + nob_cmd_append(&cmd, "-o", "./build/libplug.dylib"); + nob_cmd_append(&cmd, + "./src/plug.c", + "./src/ffmpeg_linux.c"); + nob_cmd_append(&cmd, "./build/raylib/macos/libraylib.dylib"); + nob_cmd_append(&cmd, "-lm", "-ldl", "-lpthread"); + nob_da_append(&procs, nob_cmd_run_async(cmd)); + + cmd.count = 0; + nob_cmd_append(&cmd, "clang"); + nob_cmd_append(&cmd, "-Wall", "-Wextra", "-g"); + nob_cmd_append(&cmd, "-I./build/"); + nob_cmd_append(&cmd, "-I./raylib/raylib-"RAYLIB_VERSION"/src/"); + nob_cmd_append(&cmd, "-o", "./build/musializer"); + nob_cmd_append(&cmd, + "./src/musializer.c", + "./src/hotreload_posix.c"); + nob_cmd_append(&cmd, "./build/raylib/macos/libraylib.dylib"); + nob_cmd_append(&cmd, "-lm", "-ldl", "-lpthread"); + nob_cmd_append(&cmd, "-rpath", "./build"); + nob_cmd_append(&cmd, "-rpath", "./build/raylib/macos"); + nob_cmd_append(&cmd, "-rpath", "./"); + nob_cmd_append(&cmd, "-rpath", "./raylib/macos"); + nob_da_append(&procs, nob_cmd_run_async(cmd)); + if (!nob_procs_wait(procs)) nob_return_defer(false); #else cmd.count = 0; nob_cmd_append(&cmd, "clang"); @@ -21,8 +53,7 @@ bool build_musializer(void) "./src/plug.c", "./src/ffmpeg_linux.c", "./src/musializer.c"); - nob_cmd_append(&cmd, - nob_temp_sprintf("./build/raylib/%s/libraylib.a", MUSIALIZER_TARGET_NAME)); + nob_cmd_append(&cmd, "./build/raylib/macos/libraylib.a"); nob_cmd_append(&cmd, "-framework", "CoreVideo"); nob_cmd_append(&cmd, "-framework", "IOKit"); @@ -97,15 +128,17 @@ bool build_raylib(void) if (!nob_cmd_run_sync(cmd)) nob_return_defer(false); } #else - const char *libraylib_path = nob_temp_sprintf("%s/libraylib.so", build_path); + const char *libraylib_path = nob_temp_sprintf("%s/libraylib.dylib", build_path); if (nob_needs_rebuild(libraylib_path, object_files.items, object_files.count)) { - if (config.target != TARGET_LINUX) { - nob_log(NOB_ERROR, "TODO: dynamic raylib for %s is not supported yet", NOB_ARRAY_GET(target_names, config.target)); - nob_return_defer(false); - } nob_cmd_append(&cmd, "cc"); - nob_cmd_append(&cmd, "-shared"); + nob_cmd_append(&cmd, "-shared", "-fPIC"); + nob_cmd_append(&cmd, "-framework", "CoreVideo"); + nob_cmd_append(&cmd, "-framework", "IOKit"); + nob_cmd_append(&cmd, "-framework", "Cocoa"); + nob_cmd_append(&cmd, "-framework", "GLUT"); + nob_cmd_append(&cmd, "-framework", "OpenGL"); + nob_cmd_append(&cmd, "-install_name", "@rpath/libraylib.dylib"); nob_cmd_append(&cmd, "-o", libraylib_path); for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) { const char *input_path = nob_temp_sprintf("%s/%s.o", build_path, raylib_modules[i]); From b9df8ca5bd370a3dd54a670bcc4b311ef0978271 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 21 Feb 2024 20:30:40 +0700 Subject: [PATCH 3/3] Factor out targets.h and always include it before config.h MUSIALIZER_TARGET is useless without the targets definitions. --- nob.c | 6 +----- src/hotreload.h | 1 + src/plug.c | 1 + src/targets.h | 9 +++++++++ 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 src/targets.h diff --git a/nob.c b/nob.c index 369ff97..33e3c6a 100644 --- a/nob.c +++ b/nob.c @@ -13,15 +13,11 @@ #ifdef CONFIGURED +#include "./src/targets.h" #include CONFIG_PATH #define RAYLIB_VERSION "5.0" -#define TARGET_LINUX 0 -#define TARGET_WIN64_MINGW 1 -#define TARGET_WIN64_MSVC 2 -#define TARGET_MACOS 3 - static const char *raylib_modules[] = { "rcore", "raudio", diff --git a/src/hotreload.h b/src/hotreload.h index 1ee184f..fd947ad 100644 --- a/src/hotreload.h +++ b/src/hotreload.h @@ -4,6 +4,7 @@ #include #include "plug.h" +#include "targets.h" #include "config.h" #ifdef MUSIALIZER_HOTRELOAD diff --git a/src/plug.c b/src/plug.c index dca0c51..4090ac7 100644 --- a/src/plug.c +++ b/src/plug.c @@ -6,6 +6,7 @@ #include #include +#include "targets.h" #include "config.h" #include "plug.h" #include "ffmpeg.h" diff --git a/src/targets.h b/src/targets.h new file mode 100644 index 0000000..7ee13a9 --- /dev/null +++ b/src/targets.h @@ -0,0 +1,9 @@ +#ifndef TARGETS_H_ +#define TARGETS_H_ + +#define TARGET_LINUX 0 +#define TARGET_WIN64_MINGW 1 +#define TARGET_WIN64_MSVC 2 +#define TARGET_MACOS 3 + +#endif // TARGETS_H_