Build remove web

This commit is contained in:
Nikola Petrov 2024-06-07 22:05:07 +02:00
parent 7e0d16b4b7
commit c2a19167bb
6 changed files with 60 additions and 167 deletions

6
.gitignore vendored
View File

@ -1,9 +1,5 @@
obj/ obj/
obj_web/
raylib/ raylib/
emsdk/
build build
treender treender
treender.html .vscode/settings.json
treender.js
treender.wasm

27
.vscode/launch.json vendored
View File

@ -28,6 +28,33 @@
} }
], ],
"preLaunchTask": "build-deb" "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"
} }
] ]
} }

87
.vscode/settings.json vendored
View File

@ -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"
}
}

11
.vscode/tasks.json vendored
View File

@ -16,6 +16,17 @@
"args": [ "args": [
"build" "build"
] ]
},
{
"label": "build-builder",
"type": "shell",
"command": "g++",
"args": [
"build.cpp",
"-ggdb",
"-o",
"build"
]
} }
] ]
} }

View File

@ -4,8 +4,6 @@ g++ build.cpp -o build
./build ./build
or or
./build run ./build run
or
./build cla build web // first clear all then build for web
``` ```
# Code style # Code style

View File

@ -4,10 +4,8 @@ std::filesystem::path OBJ_DIR = "obj";
std::filesystem::path INC_DIR = "inc"; std::filesystem::path INC_DIR = "inc";
std::filesystem::path SRC_DIR = "src"; std::filesystem::path SRC_DIR = "src";
std::filesystem::path RAYLIB_DIR = "raylib"; std::filesystem::path RAYLIB_DIR = "raylib";
std::filesystem::path EMSDK_DIR = "emsdk";
std::filesystem::path BUILD_FILE = "treender"; std::filesystem::path BUILD_FILE = "treender";
bool web_build = false;
bool build = false; bool build = false;
bool clear = false; bool clear = false;
bool run = false; bool run = false;
@ -16,26 +14,24 @@ std::string cpp_compiler = "g++";
std::string c_compiler = "gcc"; std::string c_compiler = "gcc";
std::string opt_flags = "-ggdb"; std::string opt_flags = "-ggdb";
std::vector<std::string> command; std::vector<std::string> command;
std::vector<std::string> RAYINCLUDE = {"-Iraylib/src"}; std::vector<std::string> 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); std::filesystem::remove_all(OBJ_DIR / SRC_DIR);
} }
if (src) if (raylib)
{ {
std::filesystem::remove_all(OBJ_DIR / RAYLIB_DIR); std::filesystem::remove_all(OBJ_DIR / RAYLIB_DIR);
} }
if (src && raylib) 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);
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() void compile_raylib_dir()
@ -43,22 +39,16 @@ void compile_raylib_dir()
std::filesystem::path out_dir = OBJ_DIR / RAYLIB_DIR; std::filesystem::path out_dir = OBJ_DIR / RAYLIB_DIR;
std::filesystem::path ray_src_dir = RAYLIB_DIR / "src"; std::filesystem::path ray_src_dir = RAYLIB_DIR / "src";
std::filesystem::create_directory(out_dir); std::filesystem::create_directory(out_dir);
std::vector<std::filesystem::path> ray_srcs = {"rcore.c", "rshapes.c", "rtextures.c", "rtext.c", "utils.c", "rmodels.c", "raudio.c"}; std::vector<std::filesystem::path> ray_srcs = {"rcore.c", "rshapes.c", "rtextures.c", "rtext.c", "utils.c", "rmodels.c", "raudio.c", "rglfw.c"};
std::vector<std::string> ray_flags = {"-DPLATFORM_WEB", "-DGRAPHICS_API_OPENGL_ES2"}; std::vector<std::string> ray_flags = {"-D_GNU_SOURCE", "-DPLATFORM_DESKTOP", "-DGRAPHICS_API_OPENGL_33"};
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");
}
command.clear(); command.clear();
command.push_back(c_compiler); command.push_back(c_compiler);
command.push_back("-c"); command.push_back("-c");
int src_loc = command.size();
command.push_back(""); command.push_back("");
command.push_back("-o"); command.push_back("-o");
int obj_loc = command.size();
command.push_back(""); command.push_back("");
command.insert(command.end(), ray_flags.begin(), ray_flags.end()); 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"); out = out_dir / ray_srcs[i].replace_extension(".o");
if (check_if_rebuild(src, out)) if (check_if_rebuild(src, out))
{ {
command[2] = src.c_str(); command[src_loc] = src;
command[4] = out.c_str(); command[obj_loc] = out;
nob_cmd_run_sync(command); nob_cmd_run_sync(command);
} }
} }
@ -114,8 +104,10 @@ int compile_src_dir()
command.clear(); command.clear();
command.push_back(cpp_compiler); command.push_back(cpp_compiler);
command.push_back("-c"); command.push_back("-c");
int src_loc = command.size();
command.push_back(""); command.push_back("");
command.push_back("-o"); command.push_back("-o");
int obj_loc = command.size();
command.push_back(""); command.push_back("");
command.push_back(opt_flags); command.push_back(opt_flags);
command.insert(command.end(), RAYINCLUDE.begin(), RAYINCLUDE.end()); 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])) if (check_if_rebuild(src_dir.files[i], obj_dir.files[i]))
{ {
command[2] = src_dir.files[i]; command[src_loc] = src_dir.files[i];
command[4] = obj_dir.files[i]; command[obj_loc] = obj_dir.files[i];
if (!nob_cmd_run_sync(command)) if (!nob_cmd_run_sync(command))
return -1; return -1;
@ -156,14 +148,6 @@ void compile_obj_dir()
command.push_back("-o"); command.push_back("-o");
command.push_back(BUILD_FILE); 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); nob_cmd_run_sync(command);
} }
@ -174,9 +158,6 @@ int main(int argc, char const *argv[])
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
{ {
if (!std::strcmp(argv[i], "web"))
web_build = true;
if (!std::strcmp(argv[i], "opt")) if (!std::strcmp(argv[i], "opt"))
opt_flags = "-O3"; opt_flags = "-O3";
@ -186,23 +167,11 @@ int main(int argc, char const *argv[])
if (!std::strcmp(argv[i], "run")) if (!std::strcmp(argv[i], "run"))
run = true; run = true;
if (!std::strcmp(argv[i], "cla")) if (!std::strcmp(argv[i], "clear"))
{ {
clear_build_dir(true, true); clear_build_dir(true, true);
clear = 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) if (clear && !build)
@ -212,7 +181,7 @@ int main(int argc, char const *argv[])
if (!std::filesystem::is_directory(RAYLIB_DIR)) 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); nob_cmd_run_sync(command);
std::filesystem::remove_all("raylib/.git"); std::filesystem::remove_all("raylib/.git");
} }
@ -220,27 +189,6 @@ int main(int argc, char const *argv[])
if (!std::filesystem::is_directory(RAYLIB_DIR)) if (!std::filesystem::is_directory(RAYLIB_DIR))
return 0; 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); std::filesystem::create_directory(OBJ_DIR);
compile_raylib_dir(); compile_raylib_dir();
@ -258,7 +206,7 @@ int main(int argc, char const *argv[])
if (!std::filesystem::exists(BUILD_FILE)) if (!std::filesystem::exists(BUILD_FILE))
compile_obj_dir(); compile_obj_dir();
if (!web_build && run) if (run)
{ {
command = {"./" + BUILD_FILE.string()}; command = {"./" + BUILD_FILE.string()};
nob_cmd_run_sync(command); nob_cmd_run_sync(command);