From 96a7c2900b4d94708ee730851ab64d442d9188ec Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Wed, 15 May 2024 01:34:02 -0700 Subject: [PATCH] Remove PCH support --- drivers/lang/c/src/gcc/driver.c | 104 +------------------------------ drivers/lang/c/src/main.c | 33 ---------- drivers/lang/c/src/msvc/driver.c | 10 --- 3 files changed, 1 insertion(+), 146 deletions(-) diff --git a/drivers/lang/c/src/gcc/driver.c b/drivers/lang/c/src/gcc/driver.c index 0b152e6..29925a9 100644 --- a/drivers/lang/c/src/gcc/driver.c +++ b/drivers/lang/c/src/gcc/driver.c @@ -376,8 +376,7 @@ void gcc_compile_src( } /* Test if the source file is from the project itself. If the project - * imports (amalgamated) source files from other projects, we should not - * add the precompiled header options for the current project header. */ + * imports (amalgamated) source files from other projects. */ bool own_source = true; char *relative_src = &source[strlen(project->path)]; if (!strncmp(relative_src, "deps"UT_OS_PS, 5)) { @@ -398,24 +397,6 @@ void gcc_compile_src( /* Add CFLAGS */ gcc_add_flags(driver, config, project, lang, &cmd); - /* Add precompiled header. - * Only add the precompiled header if the source file is of the same - * language as the project configuration. Header compiled with different - * compiler settings cannot be included */ - if (!file_has_different_language && own_source && driver->get_attr("precompile-header")) { - if (driver->get_attr_bool("precompile-header") && !config->assembly) { - if (is_clang(lang)) { - char *pch_dir = driver->get_attr_string("pch-dir"); - ut_strbuf_append(&cmd, " -include %s/%s/%s.h", - project->path, pch_dir, project->id_base); - } else { - /* Disable PCH for gcc for now, as it seems to slow down builds */ - //char *tmp_dir = driver->get_attr_string("tmp-dir"); - //ut_strbuf_append(&cmd, " -I%s", tmp_dir); - } - } - } - /* Add include directories */ gcc_add_includes(driver, config, project, &cmd); @@ -432,71 +413,6 @@ void gcc_compile_src( free(cmdstr); } -static -void gcc_generate_precompiled_header( - bake_driver_api *driver, - bake_config *config, - bake_project *project) -{ - bool cpp = is_cpp(project); - bake_src_lang lang = cpp ? BAKE_SRC_LANG_CPP : BAKE_SRC_LANG_C; - - if (config->assembly) { - return; - } - - if (!is_clang(lang)) { - return; - } - - ut_strbuf cmd = UT_STRBUF_INIT; - - char *pch_dir = ut_asprintf("%s/%s", - project->path, - driver->get_attr_string("pch-dir")); - - char *source = ut_asprintf("%s/include/%s.h", - project->path, - project->id_base); - - char *target = ut_asprintf("%s/%s.h.%s", - pch_dir, - project->id_base, - driver->get_attr_string("ext-pch")); - - /* Add source file and object file */ - ut_strbuf_append(&cmd, - "%s -x %s-header %s -o %s", cc(cpp), cpp ? "c++" : "c", source, target); - - free(target); - free(source); - - /* Add misc options */ - gcc_add_misc(driver, config, project, lang, &cmd); - - /* Add optimization flags */ - gcc_add_optimization(driver, config, project, lang, &cmd, true); - - /* Add -std option */ - gcc_add_std(driver, config, project, lang, &cmd, true, true); - - /* Add CFLAGS */ - gcc_add_flags(driver, config, project, lang, &cmd); - - /* Add include directories */ - gcc_add_includes(driver, config, project, &cmd); - - /* Make sure PCH directory exists */ - ut_mkdir(pch_dir); - - free(pch_dir); - - /* Execute command */ - char *cmdstr = ut_strbuf_get(&cmd); - driver->exec(cmdstr); - free(cmdstr); -} - /* A better mechanism is needed to abstract away from the difference between * Linux-ish systems. */ static @@ -802,22 +718,6 @@ void gcc_link_binary( } } -/* Specify files to clean */ -static -void gcc_clean( - bake_driver_api *driver, - bake_config *config, - bake_project *project) -{ - char *header = ut_asprintf("include/%s.h.pch", project->id_base); - driver->remove(header); - free(header); - - header = ut_asprintf("include/%s.h.gch", project->id_base); - driver->remove(header); - free(header); -} - /* -- Misc functions -- */ /* Return name of project artefact */ @@ -1201,10 +1101,8 @@ bake_compiler_interface gcc_get() { bake_compiler_interface result = { .compile = gcc_compile_src, .link = gcc_link_binary, - .generate_precompiled_header = gcc_generate_precompiled_header, .clean_coverage = gcc_clean_coverage, .coverage = gcc_coverage, - .clean = gcc_clean, .artefact_name = gcc_artefact_name, .link_to_lib = gcc_link_to_lib }; diff --git a/drivers/lang/c/src/main.c b/drivers/lang/c/src/main.c index 8b4f034..2160820 100644 --- a/drivers/lang/c/src/main.c +++ b/drivers/lang/c/src/main.c @@ -32,7 +32,6 @@ typedef enum bake_src_lang { typedef struct bake_compiler_interface { bake_rule_action_cb compile; bake_rule_action_cb link; - bake_driver_cb generate_precompiled_header; bake_driver_cb clean_coverage; bake_driver_cb coverage; bake_driver_cb clean; @@ -269,22 +268,6 @@ void init( driver->set_attr_string("c-standard", "c99"); } } - if (!driver->get_attr("precompile-header")) { -#ifndef _WIN32 - char *main_header = ut_asprintf("%s/include/%s.h", - project->path, project->id_base); - - if (ut_file_test(main_header) == 1) { - driver->set_attr_bool("precompile-header", true); - } else { - driver->set_attr_bool("precompile-header", false); - } - free(main_header); -#else - /* TODO: support precompiled headers on Windows */ - driver->set_attr_bool("precompile-header", false); -#endif - } if (!driver->get_attr("static")) { driver->set_attr_bool("static", false); @@ -300,13 +283,6 @@ void init( driver->set_attr_bool("export-symbols", false); } - bool cpp = is_cpp(project); - if (is_clang(cpp)) { - driver->set_attr_string("ext-pch", "pch"); - } else { - driver->set_attr_string("ext-pch", "gch"); - } - char *tmp_dir = ut_asprintf( CACHE_DIR UT_OS_PS "%s-%s", config->build_target, config->configuration); @@ -316,10 +292,6 @@ void init( driver->set_attr_string("obj-dir", obj_dir); free(obj_dir); - char *pch_dir = ut_asprintf("%s"UT_OS_PS"include", tmp_dir); - driver->set_attr_string("pch-dir", pch_dir); - free(pch_dir); - if (!strcmp(driver->get_attr("c-standard")->is.string, "c89")) { driver->set_attr_array("cflags", "-D__BAKE_LEGACY__"); } @@ -455,11 +427,6 @@ void build( bake_config *config, bake_project *project) { - if (driver->get_attr("precompile-header") && - driver->get_attr_bool("precompile-header")) - { - cif.generate_precompiled_header(driver, config, project); - } } static diff --git a/drivers/lang/c/src/msvc/driver.c b/drivers/lang/c/src/msvc/driver.c index bf4e1b2..cb63830 100755 --- a/drivers/lang/c/src/msvc/driver.c +++ b/drivers/lang/c/src/msvc/driver.c @@ -505,15 +505,6 @@ char *msvc_link_to_lib( return result; } -static -void msvc_generate_precompiled_header( - bake_driver_api *driver, - bake_config *config, - bake_project *project) -{ - /* TODO: implement PCHs for msvc */ -} - static void msvc_coverage( bake_driver_api *driver, @@ -537,7 +528,6 @@ bake_compiler_interface msvc_get() { bake_compiler_interface result = { .compile = msvc_compile_src, .link = msvc_link_binary, - .generate_precompiled_header = msvc_generate_precompiled_header, .clean_coverage = msvc_clean_coverage, .coverage = msvc_coverage, .clean = msvc_clean,