Remove unused crap

This commit is contained in:
David Gonzalez Martin 2025-01-11 07:37:40 -06:00 committed by David
parent 5df281f4b6
commit 6ac8a954b6
2 changed files with 0 additions and 568 deletions

View File

@ -1,255 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(bloat-buster)
include(CMakePrintHelpers)
cmake_print_variables("OS: ${CMAKE_SYSTEM_NAME}")
cmake_print_variables("Build type: ${CMAKE_BUILD_TYPE}")
cmake_print_variables("C flags Debug: ${CMAKE_C_FLAGS_DEBUG}")
cmake_print_variables("CXX flags Debug: ${CMAKE_CXX_FLAGS_DEBUG}")
cmake_print_variables("C flags MinSizeRel: ${CMAKE_C_FLAGS_MINSIZEREL}")
cmake_print_variables("CXX flags MinSizeRel: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
cmake_print_variables("C flags RelWithDebInfo: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
cmake_print_variables("CXX flags RelWithDebInfo: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
cmake_print_variables("C flags Release: ${CMAKE_C_FLAGS_RELEASE}")
cmake_print_variables("CXX flags Release: ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 23)
set(SHADER_COMPILATION_USE_SOURCE OFF CACHE BOOL "Variable to control if to invoke command line for shader compilation or not")
set(LIBRARY_NAME "std")
set(RUNNER_NAME "runner")
if (NOT COMPILER_NAME)
set(COMPILER_NAME "bb" CACHE STRING)
endif()
set(BB_IS_CI OFF CACHE BOOL "Variable that determines if the cmake script is run on the CI or not")
if (BB_IS_CI)
set(BB_IS_CI_C_FLAG "-DBB_CI=1")
message(STATUS "CMake is run on CI")
else()
set(BB_IS_CI_C_FLAG "-DBB_CI=0")
message(STATUS "CMake is not run on CI")
endif()
set (USE_LLVM ${BB_IS_CI} CACHE BOOL "Variable that determines if LLVM should be linked to the target")
if (SHADER_COMPILATION_USE_SOURCE)
set(SHADER_COMPILATION_USE_SOURCE_C_FLAG "-DSHADER_COMPILATION_USE_SOURCE=1")
else()
set(SHADER_COMPILATION_USE_SOURCE_C_FLAG "-DSHADER_COMPILATION_USE_SOURCE=0")
endif()
add_compile_options(
-pedantic
-Wall -Wextra -Wpedantic
-Wno-nested-anon-types -Wno-keyword-macro -Wno-gnu-auto-type -Wno-auto-decl-extensions -Wno-gnu-empty-initializer -Wno-fixed-enum-extension -Wno-gnu-binary-literal
-fno-exceptions -fno-stack-protector
-fdiagnostics-color=always
-fansi-escape-codes
-ferror-limit=1
# -march=native
${BB_IS_CI_C_FLAG} -DCOMPILER_NAME=\"${COMPILER_NAME}\" -DBUILD_DIR=\"${CMAKE_BINARY_DIR}\" -DBB_DIR=\"${BB_DIR}\" ${SHADER_COMPILATION_USE_SOURCE_C_FLAG}
)
include_directories("bootstrap/include")
add_library("${LIBRARY_NAME}"
"bootstrap/std/base.c"
"bootstrap/std/string.c"
"bootstrap/std/format.c"
"bootstrap/std/os.c"
"bootstrap/std/entry_point.c"
"bootstrap/std/virtual_buffer.c"
"bootstrap/std/md5.c"
"bootstrap/std/sha1.c"
)
add_executable("${RUNNER_NAME}" "bootstrap/runner/runner.c")
target_link_libraries(${RUNNER_NAME} PRIVATE ${LIBRARY_NAME})
add_executable("${COMPILER_NAME}"
"bootstrap/bloat-buster/main.c"
"bootstrap/bloat-buster/pdb_image.c"
"bootstrap/bloat-buster/bb_core.c"
)
target_link_libraries(${COMPILER_NAME} PRIVATE ${LIBRARY_NAME})
if (USE_LLVM)
find_package(LLVM REQUIRED CONFIG)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-19 llvm-config-19.0 llvm-config190 llvm-config19 llvm-config NAMES_PER_DIR
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-19.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE)
message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE})
else()
message(FATAL_ERROR "unable to find llvm-config")
endif()
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libs
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --shared-mode
OUTPUT_VARIABLE LLVM_LINK_MODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
cmake_print_variables("LLVM libs: ${LLVM_LIBRARIES}")
cmake_print_variables("LLVM libdirs: ${LLVM_LIBDIRS}")
cmake_print_variables("LLVM system libs: ${LLVM_SYSTEM_LIBS}")
cmake_print_variables("LLVM link mode: ${LLVM_LINK_MODE}")
if (${LLVM_LINK_MODE} STREQUAL "shared")
# We always ask for the system libs corresponding to static linking,
# since on some distros LLD is only available as a static library
# and we need these libraries to link it successfully
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
OUTPUT_VARIABLE LLVM_STATIC_SYSTEM_LIBS_SPACES
ERROR_QUIET # Some installations have no static libs, we just ignore the failure
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_STATIC_SYSTEM_LIBS "${LLVM_STATIC_SYSTEM_LIBS_SPACES}")
find_library(LLD_COFF NAMES liblldCOFF.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_COMMON NAMES liblldCommon.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_ELF NAMES liblldELF.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MACHO NAMES liblldMachO.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MINGW NAMES liblldMinGW.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_WASM NAMES liblldWasm.so PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
else()
find_library(LLD_COFF NAMES lldCOFF.lib lldCOFF.a liblldCOFF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_COMMON NAMES lldCommon.lib lldCommon.a liblldCommon.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_ELF NAMES lldELF.lib lldELF.a liblldELF.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MACHO NAMES lldMachO.lib lldMachO.a liblldMachO.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_MINGW NAMES lldMinGW.lib lldMinGW.a liblldMinGW.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(LLD_WASM NAMES lldWasm.lib lldWasm.a liblldWasm.a PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
endif()
set(lld_libs
${LLD_COFF}
${LLD_ELF}
${LLD_COMMON}
${LLD_MINGW}
${LLD_MACHO}
${LLD_WASM}
)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --includedir
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIRS_SPACES}")
if (APPLE)
if (MSVC)
list(REMOVE_ITEM LLVM_LIBRARIES "zstd.lib")
else()
list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd")
endif()
find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR)
list(APPEND LLVM_LIBRARIES "${ZSTD}")
endif()
link_directories("${LLVM_LIBDIRS}")
target_compile_definitions(${COMPILER_NAME} PRIVATE ${LLVM_DEFINITIONS})
cmake_print_variables("LLVM definitions: ${LLVM_DEFINITIONS}")
target_include_directories(${COMPILER_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
target_link_directories(${COMPILER_NAME} PRIVATE ${LLVM_LIBRARY_DIRS})
target_link_libraries(${COMPILER_NAME} PRIVATE ${LLVM_LIBRARIES} ${lld_libs})
target_sources(${COMPILER_NAME} PRIVATE
"bootstrap/bloat-buster/llvm.cpp"
"bootstrap/bloat-buster/lld_driver.c"
"bootstrap/bloat-buster/lld_api.cpp"
)
endif()
if (NOT BB_IS_CI)
if (SHADER_COMPILATION_USE_SOURCE)
add_subdirectory(dependencies/SPIRV-Headers-vulkan-sdk-1.3.296.0)
add_subdirectory(dependencies/SPIRV-Tools-vulkan-sdk-1.3.296.0)
add_subdirectory(dependencies/glslang-15.0.0)
target_link_libraries(${COMPILER_NAME} PRIVATE glslang::glslang glslang::SPIRV glslang::glslang-default-resource-limits)
endif()
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(dependencies/glfw-3.4)
target_link_libraries(${COMPILER_NAME} PRIVATE glfw)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
target_compile_definitions(${COMPILER_NAME} PRIVATE GLFW_EXPOSE_NATIVE_WIN32)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_XCB_KHR)
target_compile_definitions(${COMPILER_NAME} PRIVATE GLFW_EXPOSE_NATIVE_X11)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_METAL_EXT)
target_compile_definitions(${COMPILER_NAME} PRIVATE GLFW_EXPOSE_NATIVE_COCOA)
endif()
if (APPLE)
find_library(METAL_LIBRARY Metal)
target_link_libraries(${COMPILER_NAME} PRIVATE ${METAL_LIBRARY})
else()
if (APPLE)
execute_process(
COMMAND brew --prefix vulkan-headers
OUTPUT_VARIABLE VULKAN_HEADERS_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
include_directories("${VULKAN_HEADERS_PREFIX}/include")
endif()
add_subdirectory(dependencies/volk-1.3.301 volk)
target_link_libraries(${COMPILER_NAME} PRIVATE volk)
endif()
target_sources(${COMPILER_NAME} PRIVATE
"bootstrap/std/image_loader.c"
"bootstrap/std/font_cache.c"
"bootstrap/std/font_provider.c"
"bootstrap/std/window.c"
"bootstrap/std/ui_core.c"
"bootstrap/std/ui_builder.c"
)
if (APPLE)
target_include_directories(${COMPILER_NAME} PRIVATE dependencies/metal-cpp_macOS15.2_iOS18.2)
target_sources(${COMPILER_NAME} PRIVATE "bootstrap/std/renderer_metal.cpp")
else()
target_sources(${COMPILER_NAME} PRIVATE "bootstrap/std/renderer_vulkan.c")
endif()
target_include_directories(${COMPILER_NAME} PRIVATE dependencies/stb)
endif()

View File

@ -1,313 +0,0 @@
#include <std/base.h>
#include <std/os.h>
#include <std/entry_point.h>
#include <std/virtual_buffer.h>
#include <std/string.h>
#include <bloat-buster/base.h>
declare_slice(CompilerBackend);
typedef enum CMakeBuildType
{
CMAKE_BUILD_TYPE_DEBUG,
CMAKE_BUILD_TYPE_MIN_SIZE_RELEASE,
CMAKE_BUILD_TYPE_RELEASE_WITH_DEBUG_INFO,
CMAKE_BUILD_TYPE_RELEASE,
CMAKE_BUILD_TYPE_COUNT,
} CMakeBuildType;
fn void run(Arena* arena, char** envp, String compiler_path, CompilerBackend compiler_backend, u8 debug, char* bb_source_path)
{
CStringSlice args = {};
auto compiler_backend_string = compiler_backend_to_one_char_string(compiler_backend);
#define common_compile_and_run_args \
string_to_c(compiler_path), \
bb_source_path, \
string_to_c(compiler_backend_string), \
0,
if (debug)
{
#if _WIN32
args = (CStringSlice) array_to_slice(((char*[]){
"C:\\Users\\David\\Downloads\\remedybg_0_4_0_8\\remedybg.exe",
"-g",
common_compile_and_run_args
}));
#elif defined(__linux__)
args = (CStringSlice) array_to_slice(((char*[]){
"/home/david/source/gf/gf2",
"-ex",
"set auto-solib-add off",
"-ex",
"r",
"--args",
common_compile_and_run_args
}));
#elif defined(__APPLE__)
args = (CStringSlice) array_to_slice(((char*[]){
"/usr/bin/lldb",
"-o",
"run",
"--",
common_compile_and_run_args
}));
#endif
}
else
{
args = (CStringSlice) array_to_slice(((char*[]){
common_compile_and_run_args
}));
}
run_command(arena, args, envp);
}
typedef enum Command : u8
{
COMMAND_DEBUG,
COMMAND_RUN_TESTS,
COMMAND_COUNT,
} Command;
STRUCT(TestOptions)
{
Slice(String) test_paths;
Slice(CompilerBackend) compiler_backends;
};
fn void run_tests(Arena* arena, String compiler_path, TestOptions const * const test_options, char** envp)
{
Target target = native_target_get();
for (u32 test_i = 0; test_i < test_options->test_paths.length; test_i += 1)
{
String test_path = test_options->test_paths.pointer[test_i];
char* test_path_c = string_to_c(test_path);
auto test_dir = path_no_extension(test_path);
auto test_name = path_base(test_dir);
for (u32 engine_i = 0; engine_i < test_options->compiler_backends.length; engine_i += 1)
{
CompilerBackend compiler_backend = test_options->compiler_backends.pointer[engine_i];
auto compiler_backend_string = compiler_backend_to_one_char_string(compiler_backend);
char* arguments[] = {
string_to_c(compiler_path),
test_path_c,
string_to_c(compiler_backend_string),
0,
};
run_command(arena, (CStringSlice) array_to_slice(arguments), envp);
auto run_tests = BB_CI;
#ifndef __x86_64__
run_tests = run_tests && compiler_backend != COMPILER_BACKEND_BB;
#endif
if (run_tests)
{
auto executable = binary_path_from_options(arena, (BinaryPathOptions) {
.build_directory = strlit(BB_DIR),
.name = test_name,
.target = target,
.backend = compiler_backend,
.binary_file_type = BINARY_FILE_EXECUTABLE,
});
char* run_arguments[] = {
string_to_c(executable),
0,
};
run_command(arena, (CStringSlice) array_to_slice(run_arguments), envp);
}
}
}
}
void entry_point(int argc, char* argv[], char* envp[])
{
if (argc < 2)
{
print("Expected some arguments\n");
failed_execution();
}
Arena* arena = arena_init_default(KB(64));
CompilerBackend preferred_compiler_backend = COMPILER_BACKEND_COUNT;
Command command = COMMAND_COUNT;
u8 test_every_config = 0;
String source_file_path = {};
CMakeBuildType build_type = CMAKE_BUILD_TYPE_COUNT;
String release_strings[CMAKE_BUILD_TYPE_COUNT] = {
[CMAKE_BUILD_TYPE_DEBUG] = strlit("Debug"),
[CMAKE_BUILD_TYPE_MIN_SIZE_RELEASE] = strlit("MinSizeRel"),
[CMAKE_BUILD_TYPE_RELEASE_WITH_DEBUG_INFO] = strlit("RelWithDebInfo"),
[CMAKE_BUILD_TYPE_RELEASE] = strlit("Release"),
};
for (int i = 1; i < argc; i += 1)
{
char* c_argument = argv[i];
auto argument = cstr(c_argument);
if (one_char_string_to_compiler_backend(argument) != COMPILER_BACKEND_COUNT)
{
preferred_compiler_backend = one_char_string_to_compiler_backend(argument);
}
else if (string_starts_with(argument, strlit("build_type=")))
{
auto release_start = cast_to(u32, s32, string_first_ch(argument, '=') + 1);
auto release_string = s_get_slice(u8, argument, release_start, argument.length);
for (u64 i = 0; i < array_length(release_strings); i += 1)
{
if (s_equal(release_string, release_strings[i]))
{
build_type = (CMakeBuildType)i;
break;
}
}
assert(build_type != CMAKE_BUILD_TYPE_COUNT);
}
else if (s_equal(argument, strlit("test")))
{
command = COMMAND_RUN_TESTS;
}
else if (s_equal(argument, strlit("debug")))
{
command = COMMAND_DEBUG;
}
else if (s_equal(argument, strlit("all")))
{
test_every_config = 1;
}
}
auto index = 2 - (command == COMMAND_COUNT);
if (argc > index)
{
auto* c_argument = argv[index];
auto argument = cstr(c_argument);
String expected_starts[] = {
strlit("tests/"),
strlit("tests\\"),
strlit("./tests/"),
strlit(".\\tests\\"),
strlit("src/"),
strlit("src\\"),
strlit("./src/"),
strlit(".\\src\\"),
};
for (u32 i = 0; i < array_length(expected_starts); i += 1)
{
auto expected_start = expected_starts[i];
if (expected_start.length < argument.length)
{
// TODO: make our own function
if (strncmp(c_argument, string_to_c(expected_start), expected_start.length) == 0)
{
source_file_path = argument;
break;
}
}
}
}
if (command == COMMAND_COUNT && !source_file_path.pointer)
{
print("Expected a command\n");
failed_execution();
}
if (command == COMMAND_COUNT)
{
command = COMMAND_RUN_TESTS;
test_every_config = 1;
}
if ((command == COMMAND_DEBUG) | ((command == COMMAND_RUN_TESTS) & (test_every_config == 0)))
{
if (preferred_compiler_backend == COMPILER_BACKEND_COUNT)
{
preferred_compiler_backend = COMPILER_BACKEND_BB;
}
}
if (build_type == CMAKE_BUILD_TYPE_COUNT)
{
build_type = CMAKE_BUILD_TYPE_DEBUG;
}
String compiler_path = strlit(BUILD_DIR "/" COMPILER_NAME);
switch (command)
{
case COMMAND_DEBUG:
if (!source_file_path.pointer)
{
source_file_path = strlit("foo");
// failed_execution();
}
run(arena, envp, compiler_path, preferred_compiler_backend, 1, string_to_c(source_file_path));
break;
case COMMAND_RUN_TESTS:
{
String every_single_test[] = {
strlit("tests/first.nat"),
// strlit("tests/add_sub.nat"),
// strlit("tests/mul.nat"),
// strlit("tests/div.nat"),
// strlit("tests/and.nat"),
// strlit("tests/or.nat"),
// strlit("tests/xor.nat"),
// strlit("tests/return_var.nat"),
// strlit("tests/return_mod_scope.nat"),
// strlit("tests/shift_left.nat"),
// strlit("tests/shift_right.nat"),
// strlit("tests/thousand_simple_functions.nat"),
// strlit("tests/simple_arg.nat"),
// strlit("tests/comparison.nat"),
};
CompilerBackend all_compiler_backends[] = {
COMPILER_BACKEND_BB,
COMPILER_BACKEND_LLVM,
};
static_assert(array_length(all_compiler_backends) == COMPILER_BACKEND_COUNT);
Slice(CompilerBackend) compiler_backend_selection;
if (test_every_config)
{
compiler_backend_selection = (Slice(CompilerBackend)) array_to_slice(all_compiler_backends);
}
else
{
compiler_backend_selection = (Slice(CompilerBackend)) { .pointer = &preferred_compiler_backend, .length = 1 };
}
Slice(String) test_selection;
if (source_file_path.pointer)
{
test_selection = (Slice(String)) { .pointer = &source_file_path, .length = 1 };
}
else
{
test_selection = (Slice(String)) array_to_slice(every_single_test);
}
run_tests(arena, compiler_path, &(TestOptions) {
.test_paths = test_selection,
.compiler_backends = compiler_backend_selection,
}, envp);
} break;
case COMMAND_COUNT:
unreachable();
}
}