Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Hot Reload for macOS #81

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/hotreload.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdbool.h>

#include "plug.h"
#include "targets.h"
#include "config.h"

#ifdef MUSIALIZER_HOTRELOAD
Expand Down
7 changes: 6 additions & 1 deletion src/hotreload_linux.c → src/hotreload_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/nob_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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=./",
Expand Down
53 changes: 43 additions & 10 deletions src/nob_macos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions src/plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include <complex.h>

#include "targets.h"
#include "config.h"
#include "plug.h"
#include "ffmpeg.h"
Expand Down
9 changes: 9 additions & 0 deletions src/targets.h
Original file line number Diff line number Diff line change
@@ -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_
Loading