Skip to content

Commit

Permalink
implement hotreload for mac os
Browse files Browse the repository at this point in the history
  • Loading branch information
Markos-Th09 committed Jan 26, 2024
1 parent 7ba2fc2 commit 7070967
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/hotreload_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <dlfcn.h>

#include <raylib.h>

#define MUSIALIZER_API
#include "hotreload.h"

static const char *libplug_file_name = "libplug.so";
Expand Down
60 changes: 51 additions & 9 deletions src/nob_macos.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,49 @@ 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;
nob_cmd_append(&cmd, "clang");
nob_cmd_append(&cmd, "-Wall", "-Wextra", "-ggdb");
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.so");
nob_cmd_append(&cmd,
"./src/plug.c",
"./src/ffmpeg_linux.c");
nob_cmd_append(&cmd,
nob_temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
"-lraylib");
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", "-ggdb");
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_linux.c");
nob_cmd_append(&cmd,
"-Wl,-rpath,./build/",
"-Wl,-rpath,./",
nob_temp_sprintf("-Wl,-rpath,./build/raylib/%s", MUSIALIZER_TARGET_NAME),
// NOTE: just in case somebody wants to run musializer from within the ./build/ folder
nob_temp_sprintf("-Wl,-rpath,./raylib/%s", MUSIALIZER_TARGET_NAME));
nob_cmd_append(&cmd,
nob_temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
"-lraylib");
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, "-lm", "-ldl", "-lpthread");
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");
Expand Down Expand Up @@ -97,20 +138,21 @@ 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, "clang");
nob_cmd_append(&cmd, "-dynamiclib");
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]);
nob_cmd_append(&cmd, input_path);
}
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");
if (!nob_cmd_run_sync(cmd)) nob_return_defer(false);
}
#endif // MUSIALIZER_HOTRELOAD
Expand Down
14 changes: 10 additions & 4 deletions src/plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
# define subcc(a, b) ((a)-(b))
#endif

#ifdef WIN32
#define MUSIALIZER_PLUG __declspec(dllexport)
#else
#define MUSIALIZER_PLUG
#endif

typedef struct {
char *file_path;
Music music;
Expand Down Expand Up @@ -1286,7 +1292,7 @@ static void rendering_screen(void)
}
}

void plug_init(void)
MUSIALIZER_PLUG void plug_init(void)
{
p = malloc(sizeof(*p));
assert(p != NULL && "Buy more RAM lol");
Expand All @@ -1311,7 +1317,7 @@ void plug_init(void)
SetMasterVolume(0.5);
}

Plug *plug_pre_reload(void)
MUSIALIZER_PLUG Plug *plug_pre_reload(void)
{
for (size_t i = 0; i < p->tracks.count; ++i) {
Track *it = &p->tracks.items[i];
Expand All @@ -1321,7 +1327,7 @@ Plug *plug_pre_reload(void)
return p;
}

void plug_post_reload(Plug *pp)
MUSIALIZER_PLUG void plug_post_reload(Plug *pp)
{
p = pp;
for (size_t i = 0; i < p->tracks.count; ++i) {
Expand All @@ -1334,7 +1340,7 @@ void plug_post_reload(Plug *pp)
p->circle_power_location = GetShaderLocation(p->circle, "power");
}

void plug_update(void)
MUSIALIZER_PLUG void plug_update(void)
{
BeginDrawing();
ClearBackground(COLOR_BACKGROUND);
Expand Down

0 comments on commit 7070967

Please sign in to comment.