Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/nob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ jobs:
# https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#create-your-own-command-prompt-shortcut
run: |
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
cl.exe ${{ matrix.hotreload == true && '/DMUSIALIZER_HOTRELOAD' || '' }} /Fenob nob.c
cl.exe /Fenob nob.c
- name: Run nob
shell: cmd
run: |
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
nob.exe config ${{ matrix.hotreload == true && 'hotreload' || '' }}
nob.exe
- name: Upload build folder
uses: actions/upload-artifact@v4
Expand Down
27 changes: 27 additions & 0 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ int main(int argc, char **argv)

if (!nob_mkdir_if_not_exists("build")) return 1;

if (argc > 0) {
const char *command_name = shift(argv, argc);
if (strcmp(command_name, "config") == 0) {
// TODO: an ability to set target through the `config` command
while (argc > 0) {
const char *flag_name = shift(argv, argc);
bool found = false;
for (size_t i = 0; !found && i < ARRAY_LEN(feature_flags); ++i) {
// TODO: an ability to disable flags that enabled by default
if (strcmp(feature_flags[i].name, flag_name) == 0) {
feature_flags[i].enabled_by_default = true;
found = true;
}
}
if (!found) {
nob_log(ERROR, "Unknown command `%s`", flag_name);
return 1;
}
}
if (!generate_default_config(CONFIG_PATH)) return 1;
return 0;
} else {
nob_log(ERROR, "Unknown command `%s`", command_name);
return 1;
}
}

int config_exists = nob_file_exists(CONFIG_PATH);
if (config_exists < 0) return 1;
if (config_exists == 0) {
Expand Down
26 changes: 13 additions & 13 deletions src_build/configurer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,26 @@ static Target_Flag target_flags[] = {
};

typedef struct {
const char *display;
const char *name;
const char *macro;
const char *description;
bool enabled_by_default;
} Feature_Flag;

static Feature_Flag feature_flags[] = {
{
.display = "Hotreload",
.macro = "MUSIALIZER_HOTRELOAD",
.name = "hotreload",
.description = "Moves everything in src/plug.c to a separate \"DLL\" so it can be hotreloaded.",
},
{
.display = "Unbundle",
.macro = "MUSIALIZER_UNBUNDLE",
.name = "unbundle",
.description = "Don't bundle resources/ folder with the executable and load the resources directly from the folder.",
},
{
.display = "Microphone",
.macro = "MUSIALIZER_MICROPHONE",
.name = "microphone",
.description = "Unfinished feature that enables capturing sound from the mic."
},
};
Expand All @@ -94,6 +95,7 @@ bool generate_default_config(const char *file_path)
return false;
}

// TODO: generate_default_config() should also log what platform it picked
fprintf(f, "//// Build target. Pick only one!\n");
for (size_t i = 0; i < NOB_ARRAY_LEN(target_flags); ++i) {
if (target_flags[i].enabled_by_default) {
Expand All @@ -107,17 +109,15 @@ bool generate_default_config(const char *file_path)

for (size_t i = 0; i < NOB_ARRAY_LEN(feature_flags); ++i) {
fprintf(f, "//// %s\n", feature_flags[i].description);
if (strcmp(feature_flags[i].macro, "MUSIALIZER_HOTRELOAD") == 0) {
// TODO: FIX ASAP! This requires bootstrapping nob with additional flags which goes against its philosophy!
#ifdef MUSIALIZER_HOTRELOAD
fprintf(f, "#define %s\n", feature_flags[i].macro);
#else
fprintf(f, "// #define %s\n", feature_flags[i].macro);
#endif
if (feature_flags[i].enabled_by_default) {
nob_log(INFO, "%s: ENABLED", feature_flags[i].name);
fprintf(f, "#define %s\n", feature_flags[i].macro);
} else {
nob_log(INFO, "%s: DISABLED", feature_flags[i].name);
fprintf(f, "// #define %s\n", feature_flags[i].macro);
}
fprintf(f, "\n");

}

fclose(f);
Expand All @@ -138,9 +138,9 @@ bool generate_config_logger(const char *config_logger_path)
genf(f, " nob_log(level, \"Target: %%s\", MUSIALIZER_TARGET_NAME);");
for (size_t i = 0; i < NOB_ARRAY_LEN(feature_flags); ++i) {
genf(f, " #ifdef %s", feature_flags[i].macro);
genf(f, " nob_log(level, \"%s: ENABLED\");", feature_flags[i].display);
genf(f, " nob_log(level, \"%s: ENABLED\");", feature_flags[i].name);
genf(f, " #else");
genf(f, " nob_log(level, \"%s: DISABLED\");", feature_flags[i].display);
genf(f, " nob_log(level, \"%s: DISABLED\");", feature_flags[i].name);
genf(f, " #endif");
}
genf(f, "}");
Expand Down
1 change: 1 addition & 0 deletions src_build/nob_stage2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>

#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "../thirdparty/nob.h"
#include "../build/config.h"
#include "./configurer.c"
Expand Down