From c2a19167bbf004621c17b670f380eac1a4377d7d Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Fri, 7 Jun 2024 22:05:07 +0200 Subject: [PATCH] Build remove web --- .gitignore | 6 +-- .vscode/launch.json | 27 +++++++++++++ .vscode/settings.json | 87 --------------------------------------- .vscode/tasks.json | 11 +++++ Readme.md | 2 - build.cpp | 94 ++++++++++--------------------------------- 6 files changed, 60 insertions(+), 167 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index f6badad..22c7d9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,5 @@ obj/ -obj_web/ raylib/ -emsdk/ build treender -treender.html -treender.js -treender.wasm \ No newline at end of file +.vscode/settings.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 383421d..5812987 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,6 +28,33 @@ } ], "preLaunchTask": "build-deb" + }, + { + "name": "Debug builder", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build", + "args": [ + "build" + ], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "build-builder" } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 547185a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "files.associations": { - "iostream": "cpp", - "cmath": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "random": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "ctime": "cpp", - "list": "cpp", - "chrono": "cpp", - "codecvt": "cpp", - "cstring": "cpp", - "ratio": "cpp", - "iomanip": "cpp", - "sstream": "cpp", - "any": "cpp", - "strstream": "cpp", - "barrier": "cpp", - "bitset": "cpp", - "charconv": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_set": "cpp", - "optional": "cpp", - "regex": "cpp", - "fstream": "cpp", - "future": "cpp", - "mutex": "cpp", - "semaphore": "cpp", - "shared_mutex": "cpp", - "stop_token": "cpp", - "thread": "cpp", - "cfenv": "cpp", - "valarray": "cpp", - "__bit_reference": "cpp", - "__config": "cpp", - "__split_buffer": "cpp", - "__verbose_abort": "cpp", - "locale": "cpp", - "coroutine": "cpp", - "forward_list": "cpp", - "span": "cpp", - "variant": "cpp" - } -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3ab8118..d2d30bf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -16,6 +16,17 @@ "args": [ "build" ] + }, + { + "label": "build-builder", + "type": "shell", + "command": "g++", + "args": [ + "build.cpp", + "-ggdb", + "-o", + "build" + ] } ] } \ No newline at end of file diff --git a/Readme.md b/Readme.md index 43e0106..23e193f 100644 --- a/Readme.md +++ b/Readme.md @@ -4,8 +4,6 @@ g++ build.cpp -o build ./build or ./build run -or -./build cla build web // first clear all then build for web ``` # Code style diff --git a/build.cpp b/build.cpp index 8c63e35..42ce563 100644 --- a/build.cpp +++ b/build.cpp @@ -4,10 +4,8 @@ std::filesystem::path OBJ_DIR = "obj"; std::filesystem::path INC_DIR = "inc"; std::filesystem::path SRC_DIR = "src"; std::filesystem::path RAYLIB_DIR = "raylib"; -std::filesystem::path EMSDK_DIR = "emsdk"; std::filesystem::path BUILD_FILE = "treender"; -bool web_build = false; bool build = false; bool clear = false; bool run = false; @@ -16,26 +14,24 @@ std::string cpp_compiler = "g++"; std::string c_compiler = "gcc"; std::string opt_flags = "-ggdb"; std::vector command; -std::vector RAYINCLUDE = {"-Iraylib/src"}; +std::vector RAYINCLUDE = {"-Iraylib/src", "-Iraylib/src/external/glfw/include", "-Iraylib/src/external/glfw/deps/mingw"}; -void clear_build_dir(bool raylib, bool src) +void clear_build_dir(bool src, bool raylib) { - if (raylib) + if (src) { std::filesystem::remove_all(OBJ_DIR / SRC_DIR); } - if (src) + if (raylib) { std::filesystem::remove_all(OBJ_DIR / RAYLIB_DIR); } if (src && raylib) - std::filesystem::remove(OBJ_DIR); - + { + if (std::filesystem::exists(OBJ_DIR)) + std::filesystem::remove_all(OBJ_DIR); + } std::filesystem::remove(BUILD_FILE); - std::filesystem::remove(BUILD_FILE.replace_extension(".html")); - std::filesystem::remove(BUILD_FILE.replace_extension(".js")); - std::filesystem::remove(BUILD_FILE.replace_extension(".wasm")); - BUILD_FILE.replace_extension(""); } void compile_raylib_dir() @@ -43,22 +39,16 @@ void compile_raylib_dir() std::filesystem::path out_dir = OBJ_DIR / RAYLIB_DIR; std::filesystem::path ray_src_dir = RAYLIB_DIR / "src"; std::filesystem::create_directory(out_dir); - std::vector ray_srcs = {"rcore.c", "rshapes.c", "rtextures.c", "rtext.c", "utils.c", "rmodels.c", "raudio.c"}; - std::vector ray_flags = {"-DPLATFORM_WEB", "-DGRAPHICS_API_OPENGL_ES2"}; - - if (!web_build) - { - ray_srcs.push_back("rglfw.c"); - ray_flags = {"-D_GNU_SOURCE", "-DPLATFORM_DESKTOP", "-DGRAPHICS_API_OPENGL_33"}; - RAYINCLUDE.push_back("-Iraylib/src/external/glfw/include"); - RAYINCLUDE.push_back("-Iraylib/src/external/glfw/deps/mingw"); - } + std::vector ray_srcs = {"rcore.c", "rshapes.c", "rtextures.c", "rtext.c", "utils.c", "rmodels.c", "raudio.c", "rglfw.c"}; + std::vector ray_flags = {"-D_GNU_SOURCE", "-DPLATFORM_DESKTOP", "-DGRAPHICS_API_OPENGL_33"}; command.clear(); command.push_back(c_compiler); command.push_back("-c"); + int src_loc = command.size(); command.push_back(""); command.push_back("-o"); + int obj_loc = command.size(); command.push_back(""); command.insert(command.end(), ray_flags.begin(), ray_flags.end()); @@ -73,8 +63,8 @@ void compile_raylib_dir() out = out_dir / ray_srcs[i].replace_extension(".o"); if (check_if_rebuild(src, out)) { - command[2] = src.c_str(); - command[4] = out.c_str(); + command[src_loc] = src; + command[obj_loc] = out; nob_cmd_run_sync(command); } } @@ -114,8 +104,10 @@ int compile_src_dir() command.clear(); command.push_back(cpp_compiler); command.push_back("-c"); + int src_loc = command.size(); command.push_back(""); command.push_back("-o"); + int obj_loc = command.size(); command.push_back(""); command.push_back(opt_flags); command.insert(command.end(), RAYINCLUDE.begin(), RAYINCLUDE.end()); @@ -130,8 +122,8 @@ int compile_src_dir() { if (check_if_rebuild(src_dir.files[i], obj_dir.files[i])) { - command[2] = src_dir.files[i]; - command[4] = obj_dir.files[i]; + command[src_loc] = src_dir.files[i]; + command[obj_loc] = obj_dir.files[i]; if (!nob_cmd_run_sync(command)) return -1; @@ -156,14 +148,6 @@ void compile_obj_dir() command.push_back("-o"); command.push_back(BUILD_FILE); - if (web_build) - { - command.push_back("-s"); - command.push_back("USE_GLFW=3"); - command.push_back("--shell-file"); - command.push_back("raylib/src/minshell.html"); - } - nob_cmd_run_sync(command); } @@ -174,9 +158,6 @@ int main(int argc, char const *argv[]) for (int i = 1; i < argc; ++i) { - if (!std::strcmp(argv[i], "web")) - web_build = true; - if (!std::strcmp(argv[i], "opt")) opt_flags = "-O3"; @@ -186,23 +167,11 @@ int main(int argc, char const *argv[]) if (!std::strcmp(argv[i], "run")) run = true; - if (!std::strcmp(argv[i], "cla")) + if (!std::strcmp(argv[i], "clear")) { clear_build_dir(true, true); clear = true; } - - if (!std::strcmp(argv[i], "clr")) - { - clear_build_dir(false, true); - clear = true; - } - - if (!std::strcmp(argv[i], "cls")) - { - clear_build_dir(true, false); - clear = true; - } } if (clear && !build) @@ -212,7 +181,7 @@ int main(int argc, char const *argv[]) if (!std::filesystem::is_directory(RAYLIB_DIR)) { - command = {"git", "clone", "--depth", "1", "--branch", "5.0", "git@github.com:raysan5/raylib.git"}; + command = {"git", "clone", "--depth", "1", "--branch", "5.0", "https://github.com/raysan5/raylib.git"}; nob_cmd_run_sync(command); std::filesystem::remove_all("raylib/.git"); } @@ -220,27 +189,6 @@ int main(int argc, char const *argv[]) if (!std::filesystem::is_directory(RAYLIB_DIR)) return 0; - if (!std::filesystem::is_directory(EMSDK_DIR) && web_build) - { - command = {"git", "clone", "https://github.com/emscripten-core/emsdk.git"}; - nob_cmd_run_sync(command); - std::filesystem::remove_all("emsdk/.git"); - command = {"./emsdk/emsdk", "install", "latest"}; - nob_cmd_run_sync(command); - command = {"./emsdk/emsdk", "activate", "latest"}; - nob_cmd_run_sync(command); - } - - if (web_build) - { - cpp_compiler = "./emsdk/upstream/emscripten/em++"; - c_compiler = "./emsdk/upstream/emscripten/emcc"; - opt_flags = "-Os"; - RAYINCLUDE.push_back("-DPLATFORM_WEB"); - BUILD_FILE = BUILD_FILE.replace_extension(".html"); - OBJ_DIR = "obj_web"; - } - std::filesystem::create_directory(OBJ_DIR); compile_raylib_dir(); @@ -258,7 +206,7 @@ int main(int argc, char const *argv[]) if (!std::filesystem::exists(BUILD_FILE)) compile_obj_dir(); - if (!web_build && run) + if (run) { command = {"./" + BUILD_FILE.string()}; nob_cmd_run_sync(command);