clean up build stuffs

This commit is contained in:
2026-03-05 03:08:22 -05:00
parent 6c43a29f9f
commit 708192ec02
5 changed files with 47 additions and 28 deletions

4
.gitignore vendored
View File

@@ -34,6 +34,10 @@ nob.ilk
*.dylib *.dylib
*.a *.a
# Generated source
*.gen.h
*.gen.cpp
# Misc # Misc
*.exe *.exe
!nob.c !nob.c

65
build.c
View File

@@ -109,7 +109,7 @@ static const char *frameworks[] = {
static bool build_lunasvg_lib(const char *build_dir, bool debug) { static bool build_lunasvg_lib(const char *build_dir, bool debug) {
const char *obj_dir = nob_temp_sprintf("%s/lunasvg_obj", build_dir); const char *obj_dir = nob_temp_sprintf("%s/lunasvg_obj", build_dir);
const char *lib_path = nob_temp_sprintf("%s/liblunasvg.a", build_dir); const char *lib_path = "vendor/lunasvg/liblunasvg.a";
// Collect all source paths to check if rebuild is needed // Collect all source paths to check if rebuild is needed
{ {
@@ -231,7 +231,7 @@ static bool build_lunasvg_lib(const char *build_dir, bool debug) {
static bool build_freetype_lib(const char *build_dir, bool debug) { static bool build_freetype_lib(const char *build_dir, bool debug) {
const char *obj_dir = nob_temp_sprintf("%s/freetype_obj", build_dir); const char *obj_dir = nob_temp_sprintf("%s/freetype_obj", build_dir);
const char *lib_path = nob_temp_sprintf("%s/libfreetype.a", build_dir); const char *lib_path = "vendor/freetype/libfreetype.a";
if (!nob_needs_rebuild(lib_path, freetype_sources, NOB_ARRAY_LEN(freetype_sources))) { if (!nob_needs_rebuild(lib_path, freetype_sources, NOB_ARRAY_LEN(freetype_sources))) {
nob_log(NOB_INFO, "freetype is up to date"); nob_log(NOB_INFO, "freetype is up to date");
@@ -305,15 +305,24 @@ int main(int argc, char **argv) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0) debug = true; if (strcmp(argv[i], "debug") == 0) debug = true;
else if (strcmp(argv[i], "clean") == 0) clean = true; else if (strcmp(argv[i], "clean") == 0) clean = true;
else {
nob_log(NOB_ERROR, "unknown argument: %s", argv[i]);
nob_log(NOB_ERROR, "usage: %s [debug] [clean]", argv[0]);
return 1;
}
} }
const char *build_dir = debug ? "build_debug" : "build_release"; const char *build_dir = debug ? "build_debug" : "build_release";
if (clean) { if (clean) {
nob_log(NOB_INFO, "Cleaning %s/", build_dir); nob_log(NOB_INFO, "Cleaning build artifacts");
Nob_Cmd cmd = {0}; { Nob_Cmd cmd = {0}; nob_cmd_append(&cmd, "rm", "-rf", "build_debug");
nob_cmd_append(&cmd, "rm", "-rf", build_dir); Nob_Cmd_Opt opt = {0}; nob_cmd_run_opt(&cmd, opt); }
{ Nob_Cmd_Opt opt = {0}; if (!nob_cmd_run_opt(&cmd, opt)) return 1; } { Nob_Cmd cmd = {0}; nob_cmd_append(&cmd, "rm", "-rf", "build_release");
Nob_Cmd_Opt opt = {0}; nob_cmd_run_opt(&cmd, opt); }
remove("vendor/lunasvg/liblunasvg.a");
remove("vendor/freetype/libfreetype.a");
remove("src/renderer/font_inter.gen.h");
return 0; return 0;
} }
@@ -335,10 +344,8 @@ int main(int argc, char **argv) {
if (!build_freetype_lib(build_dir, debug)) return 1; if (!build_freetype_lib(build_dir, debug)) return 1;
// Generate embedded font header // Generate embedded font header
const char *gen_dir = nob_temp_sprintf("%s/generated", build_dir);
if (!nob_mkdir_if_not_exists(gen_dir)) return 1;
if (!embed_font_file("assets/fonts/Inter-Regular.ttf", if (!embed_font_file("assets/fonts/Inter-Regular.ttf",
nob_temp_sprintf("%s/font_inter.h", gen_dir))) return 1; "src/renderer/font_inter.gen.h")) return 1;
// Unity build: single clang++ invocation compiles main.cpp (which #includes everything) // Unity build: single clang++ invocation compiles main.cpp (which #includes everything)
{ {
@@ -351,7 +358,6 @@ int main(int argc, char **argv) {
nob_cmd_append(&cmd, "-Isrc", "-Ivendor/clay"); nob_cmd_append(&cmd, "-Isrc", "-Ivendor/clay");
nob_cmd_append(&cmd, "-Ivendor/lunasvg/include"); nob_cmd_append(&cmd, "-Ivendor/lunasvg/include");
nob_cmd_append(&cmd, "-Ivendor/freetype/include"); nob_cmd_append(&cmd, "-Ivendor/freetype/include");
nob_cmd_append(&cmd, nob_temp_sprintf("-I%s", build_dir));
nob_cmd_append(&cmd, "-DLUNASVG_BUILD_STATIC"); nob_cmd_append(&cmd, "-DLUNASVG_BUILD_STATIC");
if (debug) { if (debug) {
@@ -365,8 +371,8 @@ int main(int argc, char **argv) {
// Reset language mode so .a is treated as a library, not source // Reset language mode so .a is treated as a library, not source
nob_cmd_append(&cmd, "-x", "none"); nob_cmd_append(&cmd, "-x", "none");
nob_cmd_append(&cmd, nob_temp_sprintf("%s/liblunasvg.a", build_dir)); nob_cmd_append(&cmd, "vendor/lunasvg/liblunasvg.a");
nob_cmd_append(&cmd, nob_temp_sprintf("%s/libfreetype.a", build_dir)); nob_cmd_append(&cmd, "vendor/freetype/libfreetype.a");
{ {
size_t i; size_t i;
@@ -454,7 +460,7 @@ static const char *link_libs[] = {
static bool build_lunasvg_lib(const char *build_dir, bool debug) { static bool build_lunasvg_lib(const char *build_dir, bool debug) {
const char *obj_dir = nob_temp_sprintf("%s\\lunasvg_obj", build_dir); const char *obj_dir = nob_temp_sprintf("%s\\lunasvg_obj", build_dir);
const char *lib_path = nob_temp_sprintf("%s\\lunasvg.lib", build_dir); const char *lib_path = debug ? "vendor\\lunasvg\\lunasvg_d.lib" : "vendor\\lunasvg\\lunasvg.lib";
// Check if rebuild is needed // Check if rebuild is needed
{ {
@@ -540,7 +546,7 @@ static bool build_lunasvg_lib(const char *build_dir, bool debug) {
static bool build_freetype_lib(const char *build_dir, bool debug) { static bool build_freetype_lib(const char *build_dir, bool debug) {
const char *obj_dir = nob_temp_sprintf("%s\\freetype_obj", build_dir); const char *obj_dir = nob_temp_sprintf("%s\\freetype_obj", build_dir);
const char *lib_path = nob_temp_sprintf("%s\\freetype.lib", build_dir); const char *lib_path = debug ? "vendor\\freetype\\freetype_d.lib" : "vendor\\freetype\\freetype.lib";
if (!nob_needs_rebuild(lib_path, freetype_sources, NOB_ARRAY_LEN(freetype_sources))) { if (!nob_needs_rebuild(lib_path, freetype_sources, NOB_ARRAY_LEN(freetype_sources))) {
nob_log(NOB_INFO, "freetype is up to date"); nob_log(NOB_INFO, "freetype is up to date");
@@ -598,16 +604,28 @@ int main(int argc, char **argv) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0) debug = true; if (strcmp(argv[i], "debug") == 0) debug = true;
else if (strcmp(argv[i], "clean") == 0) clean = true; else if (strcmp(argv[i], "clean") == 0) clean = true;
else {
nob_log(NOB_ERROR, "unknown argument: %s", argv[i]);
nob_log(NOB_ERROR, "usage: %s [debug] [clean]", argv[0]);
return 1;
}
} }
const char *build_dir = debug ? "build_debug" : "build_release"; const char *build_dir = debug ? "build_debug" : "build_release";
if (clean) { if (clean) {
nob_log(NOB_INFO, "Cleaning %s/", build_dir); nob_log(NOB_INFO, "Cleaning build artifacts");
Nob_Cmd cmd = {0}; { Nob_Cmd cmd = {0}; nob_cmd_append(&cmd, "cmd.exe", "/c",
nob_cmd_append(&cmd, "cmd.exe", "/c", "if exist build_debug rmdir /s /q build_debug");
nob_temp_sprintf("if exist %s rmdir /s /q %s", build_dir, build_dir)); Nob_Cmd_Opt opt = {0}; nob_cmd_run_opt(&cmd, opt); }
{ Nob_Cmd_Opt opt = {0}; if (!nob_cmd_run_opt(&cmd, opt)) return 1; } { Nob_Cmd cmd = {0}; nob_cmd_append(&cmd, "cmd.exe", "/c",
"if exist build_release rmdir /s /q build_release");
Nob_Cmd_Opt opt = {0}; nob_cmd_run_opt(&cmd, opt); }
remove("vendor\\lunasvg\\lunasvg.lib");
remove("vendor\\lunasvg\\lunasvg_d.lib");
remove("vendor\\freetype\\freetype.lib");
remove("vendor\\freetype\\freetype_d.lib");
remove("src\\renderer\\font_inter.gen.h");
return 0; return 0;
} }
@@ -618,10 +636,8 @@ int main(int argc, char **argv) {
if (!build_freetype_lib(build_dir, debug)) return 1; if (!build_freetype_lib(build_dir, debug)) return 1;
// Generate embedded font header // Generate embedded font header
const char *gen_dir = nob_temp_sprintf("%s\\generated", build_dir);
if (!nob_mkdir_if_not_exists(gen_dir)) return 1;
if (!embed_font_file("assets/fonts/Inter-Regular.ttf", if (!embed_font_file("assets/fonts/Inter-Regular.ttf",
nob_temp_sprintf("%s\\font_inter.h", gen_dir))) return 1; "src\\renderer\\font_inter.gen.h")) return 1;
// Unity build: single cl.exe invocation compiles main.cpp (which #includes everything) // Unity build: single cl.exe invocation compiles main.cpp (which #includes everything)
{ {
@@ -631,7 +647,6 @@ int main(int argc, char **argv) {
nob_cmd_append(&cmd, "/Isrc", "/Ivendor/clay"); nob_cmd_append(&cmd, "/Isrc", "/Ivendor/clay");
nob_cmd_append(&cmd, "/Ivendor/lunasvg/include"); nob_cmd_append(&cmd, "/Ivendor/lunasvg/include");
nob_cmd_append(&cmd, "/Ivendor/freetype/include"); nob_cmd_append(&cmd, "/Ivendor/freetype/include");
nob_cmd_append(&cmd, nob_temp_sprintf("/I%s", build_dir));
nob_cmd_append(&cmd, "/DLUNASVG_BUILD_STATIC"); nob_cmd_append(&cmd, "/DLUNASVG_BUILD_STATIC");
if (debug) { if (debug) {
@@ -651,8 +666,8 @@ int main(int argc, char **argv) {
nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE"); nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE");
nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", build_dir)); nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", build_dir));
nob_cmd_append(&cmd, "/DEBUG"); nob_cmd_append(&cmd, "/DEBUG");
nob_cmd_append(&cmd, nob_temp_sprintf("%s/lunasvg.lib", build_dir)); nob_cmd_append(&cmd, debug ? "vendor/lunasvg/lunasvg_d.lib" : "vendor/lunasvg/lunasvg.lib");
nob_cmd_append(&cmd, nob_temp_sprintf("%s/freetype.lib", build_dir)); nob_cmd_append(&cmd, debug ? "vendor/freetype/freetype_d.lib" : "vendor/freetype/freetype.lib");
{ {
size_t i; size_t i;
for (i = 0; i < NOB_ARRAY_LEN(link_libs); i++) for (i = 0; i < NOB_ARRAY_LEN(link_libs); i++)

View File

@@ -14,7 +14,7 @@ struct RendererDesc {
Renderer *renderer_create(RendererDesc *desc); Renderer *renderer_create(RendererDesc *desc);
void renderer_destroy(Renderer *renderer); void renderer_destroy(Renderer *renderer);
B32 renderer_begin_frame(Renderer *renderer); B32 renderer_begin_frame(Renderer *renderer);
void renderer_end_frame(Renderer *renderer, Clay_RenderCommandArray render_commands); void renderer_end_frame(Renderer *renderer, Clay_RenderCommandArray render_commands);
void renderer_resize(Renderer *renderer, S32 width, S32 height); void renderer_resize(Renderer *renderer, S32 width, S32 height);
void renderer_set_font_scale(Renderer *renderer, F32 scale); void renderer_set_font_scale(Renderer *renderer, F32 scale);

View File

@@ -19,7 +19,7 @@
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_BITMAP_H #include FT_BITMAP_H
#define internal static #define internal static
#include "generated/font_inter.h" #include "renderer/font_inter.gen.h"
#ifdef _DEBUG #ifdef _DEBUG
#define DX12_ENABLE_DEBUG_LAYER #define DX12_ENABLE_DEBUG_LAYER

View File

@@ -14,7 +14,7 @@
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_BITMAP_H #include FT_BITMAP_H
#define internal static #define internal static
#include "generated/font_inter.h" #include "renderer/font_inter.gen.h"
#define NUM_BACK_BUFFERS 2 #define NUM_BACK_BUFFERS 2
#define MAX_VERTICES (64 * 1024) #define MAX_VERTICES (64 * 1024)