move from imgui to CLAY

This commit is contained in:
2026-02-25 15:20:47 -05:00
parent 6656b6d0b2
commit 12dae774e4
41 changed files with 6835 additions and 77320 deletions

134
nob.c
View File

@@ -5,22 +5,6 @@
#include "nob.h"
#define BUILD_DIR "build"
#define IMGUI_LIB_DEBUG BUILD_DIR "/imgui_d.lib"
#define IMGUI_LIB_RELEASE BUILD_DIR "/imgui.lib"
static const char *src_files[] = {
"src/main.cpp",
};
static const char *imgui_files[] = {
"vendor/imgui/imgui.cpp",
"vendor/imgui/imgui_draw.cpp",
"vendor/imgui/imgui_tables.cpp",
"vendor/imgui/imgui_widgets.cpp",
"vendor/imgui/imgui_demo.cpp",
"vendor/imgui/backends/imgui_impl_win32.cpp",
"vendor/imgui/backends/imgui_impl_dx12.cpp",
};
static const char *link_libs[] = {
"d3d12.lib",
@@ -34,61 +18,6 @@ static const char *link_libs[] = {
"winmm.lib",
};
static const char *obj_name(const char *src_path) {
const char *slash = strrchr(src_path, '/');
const char *name = slash ? slash + 1 : src_path;
size_t len = strlen(name);
return nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name);
}
static bool build_imgui_lib(bool debug) {
const char *lib_path = debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE;
int need = nob_needs_rebuild(lib_path, imgui_files, NOB_ARRAY_LEN(imgui_files));
if (need < 0) return false;
if (!need) {
nob_log(NOB_INFO, "%s is up to date", lib_path);
return true;
}
nob_log(NOB_INFO, "Building %s...", lib_path);
Nob_Cmd cmd = {0};
nob_cmd_append(&cmd, "cl.exe");
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3", "/c");
nob_cmd_append(&cmd, "/Ivendor/imgui", "/Ivendor/imgui/backends");
if (debug) {
nob_cmd_append(&cmd, "/MTd", "/Zi", "/Od", "/D_DEBUG");
} else {
nob_cmd_append(&cmd, "/MT", "/O2", "/DNDEBUG");
}
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/", BUILD_DIR));
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
nob_cmd_append(&cmd, imgui_files[i]);
if (!nob_cmd_run(&cmd)) return false;
// Archive .obj files into a .lib
cmd.count = 0;
nob_cmd_append(&cmd, "lib.exe", "/nologo", "/MACHINE:X64");
nob_cmd_append(&cmd, nob_temp_sprintf("/OUT:%s", lib_path));
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
nob_cmd_append(&cmd, obj_name(imgui_files[i]));
if (!nob_cmd_run(&cmd)) return false;
// Clean up imgui .obj files
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
nob_delete_file(obj_name(imgui_files[i]));
return true;
}
int main(int argc, char **argv) {
NOB_GO_REBUILD_URSELF(argc, argv);
@@ -103,49 +32,46 @@ int main(int argc, char **argv) {
nob_log(NOB_INFO, "Cleaning %s/", BUILD_DIR);
Nob_Cmd cmd = {0};
nob_cmd_append(&cmd, "cmd.exe", "/c", "if exist " BUILD_DIR " rmdir /s /q " BUILD_DIR);
if (!nob_cmd_run(&cmd)) return 1;
{ Nob_Cmd_Opt opt = {0}; if (!nob_cmd_run_opt(&cmd, opt)) return 1; }
return 0;
}
if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1;
// Build vendor libs (unless already built)
if (!build_imgui_lib(debug)) return 1;
// Unity build: single cl.exe invocation compiles main.cpp (which #includes everything)
{
Nob_Cmd cmd = {0};
nob_cmd_append(&cmd, "cl.exe");
nob_cmd_append(&cmd, "/nologo", "/std:c++20", "/EHsc", "/W3");
nob_cmd_append(&cmd, "/Isrc", "/Ivendor/clay");
// Compile and link
Nob_Cmd cmd = {0};
if (debug) {
nob_cmd_append(&cmd, "/MTd", "/Zi", "/Od", "/D_DEBUG");
} else {
nob_cmd_append(&cmd, "/MT", "/Zi", "/O2", "/DNDEBUG");
}
nob_cmd_append(&cmd, "cl.exe");
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3");
nob_cmd_append(&cmd, "/Isrc", "/Ivendor/imgui", "/Ivendor/imgui/backends");
nob_cmd_append(&cmd, nob_temp_sprintf("/Fe:%s/autosample.exe", BUILD_DIR));
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/autosample.pdb", BUILD_DIR));
if (debug) {
nob_cmd_append(&cmd, "/MTd", "/Zi", "/Od", "/D_DEBUG");
} else {
nob_cmd_append(&cmd, "/MT", "/Zi", "/O2", "/DNDEBUG");
nob_cmd_append(&cmd, "src/main.cpp");
nob_cmd_append(&cmd, "/link");
nob_cmd_append(&cmd, "/MACHINE:X64");
nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE");
nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", BUILD_DIR));
nob_cmd_append(&cmd, "/DEBUG");
{
size_t i;
for (i = 0; i < NOB_ARRAY_LEN(link_libs); i++)
nob_cmd_append(&cmd, link_libs[i]);
}
{ Nob_Cmd_Opt opt = {0}; if (!nob_cmd_run_opt(&cmd, opt)) return 1; }
}
nob_cmd_append(&cmd, nob_temp_sprintf("/Fe:%s/autosample.exe", BUILD_DIR));
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/autosample.pdb", BUILD_DIR));
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++)
nob_cmd_append(&cmd, src_files[i]);
nob_cmd_append(&cmd, "/link");
nob_cmd_append(&cmd, "/MACHINE:X64");
nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE");
nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", BUILD_DIR));
nob_cmd_append(&cmd, "/DEBUG");
nob_cmd_append(&cmd, debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE);
for (size_t i = 0; i < NOB_ARRAY_LEN(link_libs); i++)
nob_cmd_append(&cmd, link_libs[i]);
if (!nob_cmd_run(&cmd)) return 1;
// Clean up .obj files
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++)
nob_delete_file(obj_name(src_files[i]));
// Clean up obj files
nob_delete_file(nob_temp_sprintf("%s/main.obj", BUILD_DIR));
nob_log(NOB_INFO, "Build complete: %s/autosample.exe", BUILD_DIR);
return 0;