2
0

nob_win64_msvc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #define MUSIALIZER_TARGET_NAME "win64-msvc"
  2. bool build_musializer(void)
  3. {
  4. bool result = true;
  5. Nob_Cmd cmd = {0};
  6. Nob_Procs procs = {0};
  7. cmd.count = 0;
  8. nob_cmd_append(&cmd, "rc");
  9. nob_cmd_append(&cmd, "/fo", "./build/musializer.res");
  10. nob_cmd_append(&cmd, "./src/musializer.rc");
  11. // NOTE: Do not change the order of commandline arguments to rc. Their argparser is weird.
  12. if (!nob_cmd_run_sync(cmd)) nob_return_defer(false);
  13. #ifdef MUSIALIZER_HOTRELOAD
  14. procs.count = 0;
  15. cmd.count = 0;
  16. nob_cmd_append(&cmd, "cl.exe");
  17. nob_cmd_append(&cmd, "/LD");
  18. nob_cmd_append(&cmd, "/Fobuild\\", "/Fe./build/libplug.dll");
  19. nob_cmd_append(&cmd, "/I", "./");
  20. nob_cmd_append(&cmd, "/I", RAYLIB_SRC_FOLDER);
  21. nob_cmd_append(&cmd,
  22. "src/plug.c",
  23. "src/ffmpeg_windows.c",
  24. "./thirdparty/tinyfiledialogs.c");
  25. nob_cmd_append(&cmd,
  26. "/link",
  27. nob_temp_sprintf("/LIBPATH:build/raylib/%s", MUSIALIZER_TARGET_NAME),
  28. "raylib.lib");
  29. nob_cmd_append(&cmd, "Winmm.lib", "gdi32.lib", "User32.lib", "Shell32.lib", "Ole32.lib", "comdlg32.lib");
  30. nob_da_append(&procs, nob_cmd_run_async(cmd));
  31. cmd.count = 0;
  32. nob_cmd_append(&cmd, "cl.exe");
  33. nob_cmd_append(&cmd, "/I", "./");
  34. nob_cmd_append(&cmd, "/I", RAYLIB_SRC_FOLDER);
  35. nob_cmd_append(&cmd, "/Fobuild\\", "/Febuild\\musializer.exe");
  36. nob_cmd_append(&cmd,
  37. "./src/musializer.c",
  38. "./src/hotreload_windows.c",
  39. );
  40. nob_cmd_append(&cmd,
  41. "/link",
  42. "/SUBSYSTEM:WINDOWS",
  43. "/entry:mainCRTStartup",
  44. nob_temp_sprintf("/LIBPATH:build/raylib/%s", MUSIALIZER_TARGET_NAME),
  45. "raylib.lib");
  46. nob_cmd_append(&cmd, "Winmm.lib", "gdi32.lib", "User32.lib", "Shell32.lib", "./build/musializer.res");
  47. nob_da_append(&procs, nob_cmd_run_async(cmd));
  48. if (!nob_procs_wait(procs)) nob_return_defer(false);
  49. #else
  50. cmd.count = 0;
  51. nob_cmd_append(&cmd, "cl.exe");
  52. nob_cmd_append(&cmd, "/I", "./");
  53. nob_cmd_append(&cmd, "/I", RAYLIB_SRC_FOLDER);
  54. nob_cmd_append(&cmd, "/Fobuild\\", "/Febuild\\musializer.exe");
  55. nob_cmd_append(&cmd,
  56. "./src/musializer.c",
  57. "./src/plug.c",
  58. "./src/ffmpeg_windows.c",
  59. "./thirdparty/tinyfiledialogs.c");
  60. nob_cmd_append(&cmd,
  61. "/link",
  62. "/SUBSYSTEM:WINDOWS",
  63. "/entry:mainCRTStartup",
  64. nob_temp_sprintf("/LIBPATH:build/raylib/%s", MUSIALIZER_TARGET_NAME),
  65. "raylib.lib");
  66. nob_cmd_append(&cmd, "Winmm.lib", "gdi32.lib", "User32.lib", "Shell32.lib", "Ole32.lib", "comdlg32.lib", "./build/musializer.res");
  67. // TODO: is some sort of `-static` flag needed for MSVC to get a statically linked executable
  68. //nob_cmd_append(&cmd, "-static");
  69. if (!nob_cmd_run_sync(cmd)) nob_return_defer(false);
  70. #endif // MUSIALIZER_HOTRELOAD
  71. defer:
  72. nob_cmd_free(cmd);
  73. nob_da_free(procs);
  74. return result;
  75. }
  76. bool build_raylib(void)
  77. {
  78. bool result = true;
  79. Nob_Cmd cmd = {0};
  80. Nob_File_Paths object_files = {0};
  81. if (!nob_mkdir_if_not_exists("./build/raylib")) {
  82. nob_return_defer(false);
  83. }
  84. Nob_Procs procs = {0};
  85. const char *build_path = nob_temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
  86. if (!nob_mkdir_if_not_exists(build_path)) {
  87. nob_return_defer(false);
  88. }
  89. for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
  90. const char *input_path = nob_temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
  91. const char *output_path = nob_temp_sprintf("%s/%s.obj", build_path, raylib_modules[i]);
  92. nob_da_append(&object_files, output_path);
  93. if (nob_needs_rebuild(output_path, &input_path, 1)) {
  94. cmd.count = 0;
  95. nob_cmd_append(&cmd, "cl.exe", "/DPLATFORM_DESKTOP", "/DSUPPORT_FILEFORMAT_FLAC=1");
  96. #ifdef MUSIALIZER_HOTRELOAD
  97. nob_cmd_append(&cmd, "/DBUILD_LIBTYPE_SHARED");
  98. #endif
  99. nob_cmd_append(&cmd, "/I", RAYLIB_SRC_FOLDER"external/glfw/include");
  100. nob_cmd_append(&cmd, "/c", input_path);
  101. nob_cmd_append(&cmd, nob_temp_sprintf("/Fo%s", output_path));
  102. Nob_Proc proc = nob_cmd_run_async(cmd);
  103. nob_da_append(&procs, proc);
  104. }
  105. }
  106. cmd.count = 0;
  107. if (!nob_procs_wait(procs)) nob_return_defer(false);
  108. #ifndef MUSIALIZER_HOTRELOAD
  109. const char *libraylib_path = nob_temp_sprintf("%s/raylib.lib", build_path);
  110. if (nob_needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
  111. nob_cmd_append(&cmd, "lib");
  112. for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
  113. const char *input_path = nob_temp_sprintf("%s/%s.obj", build_path, raylib_modules[i]);
  114. nob_cmd_append(&cmd, input_path);
  115. }
  116. nob_cmd_append(&cmd, nob_temp_sprintf("/OUT:%s", libraylib_path));
  117. if (!nob_cmd_run_sync(cmd)) nob_return_defer(false);
  118. }
  119. #else
  120. if (nob_needs_rebuild("./build/raylib.dll", object_files.items, object_files.count)) {
  121. nob_cmd_append(&cmd, "link.exe", "/DLL");
  122. for (size_t i = 0; i < NOB_ARRAY_LEN(raylib_modules); ++i) {
  123. const char *input_path = nob_temp_sprintf("%s/%s.obj", build_path, raylib_modules[i]);
  124. nob_cmd_append(&cmd, input_path);
  125. }
  126. nob_cmd_append(&cmd, "Winmm.lib", "gdi32.lib", "User32.lib", "Shell32.lib");
  127. nob_cmd_append(&cmd, nob_temp_sprintf("/IMPLIB:%s/raylib.lib", build_path));
  128. nob_cmd_append(&cmd, "/OUT:./build/raylib.dll");
  129. if (!nob_cmd_run_sync(cmd)) nob_return_defer(false);
  130. }
  131. #endif // MUSIALIZER_HOTRELOAD
  132. defer:
  133. nob_cmd_free(cmd);
  134. nob_da_free(object_files);
  135. return result;
  136. }
  137. bool build_dist(void)
  138. {
  139. #ifdef MUSIALIZER_HOTRELOAD
  140. nob_log(NOB_ERROR, "We do not ship with hotreload enabled");
  141. return false;
  142. #else
  143. nob_log(NOB_ERROR, "TODO: Creating distro for MSVC build is not implemented yet");
  144. return false;
  145. #endif // MUSIALIZER_HOTRELOAD
  146. }