Skip to content

Commit

Permalink
Remove PCH support
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 15, 2024
1 parent 0479eb1 commit 96a7c29
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 146 deletions.
104 changes: 1 addition & 103 deletions drivers/lang/c/src/gcc/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
};
Expand Down
33 changes: 0 additions & 33 deletions drivers/lang/c/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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__");
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions drivers/lang/c/src/msvc/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 96a7c29

Please sign in to comment.