From 6835c9eada82bca0b5524b1f48da7668e25b701c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:06:17 -0700 Subject: [PATCH 01/13] Update build.cpp --- buildcc/lib/target/src/target/build.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index e7412162..b4269764 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -63,11 +63,12 @@ void Target::Build() { } else { BuildRecompile(); } + + LinkTargetTask(dirty_); } void Target::BuildCompile() { CompileSources(); - LinkTargetTask(true); dirty_ = true; first_build_ = true; } @@ -108,7 +109,6 @@ void Target::BuildRecompile() { current_external_lib_deps_); // TODO, Verify the `physical` presence of the target if dirty_ == false - LinkTargetTask(dirty_); rebuild_ = dirty_; } From 1cde9e9aea410febb0303a32998de265d1f3fc59 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:27:14 -0700 Subject: [PATCH 02/13] Added common_compile_flag to target.fbs --- buildcc/lib/target/fbs/target.fbs | 1 + 1 file changed, 1 insertion(+) diff --git a/buildcc/lib/target/fbs/target.fbs b/buildcc/lib/target/fbs/target.fbs index d4826cea..717e9e48 100644 --- a/buildcc/lib/target/fbs/target.fbs +++ b/buildcc/lib/target/fbs/target.fbs @@ -44,6 +44,7 @@ table Target { // Flags preprocessor_flags:[string]; + common_compile_flags:[string]; c_compile_flags:[string]; cpp_compile_flags:[string]; link_flags:[string]; From 12963a8a9beaf6b63dc1784db8c25eff3e22c10d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:27:34 -0700 Subject: [PATCH 03/13] Update fbs_storer.cpp - WIth common_compile_flag --- buildcc/lib/target/src/fbs/fbs_storer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/buildcc/lib/target/src/fbs/fbs_storer.cpp b/buildcc/lib/target/src/fbs/fbs_storer.cpp index c0a6ac34..9fe80173 100644 --- a/buildcc/lib/target/src/fbs/fbs_storer.cpp +++ b/buildcc/lib/target/src/fbs/fbs_storer.cpp @@ -91,9 +91,11 @@ bool Target::Store() { auto fbs_preprocessor_flags = get_fbs_vector_string(builder, current_preprocessor_flags_); - auto fbs_c_compiler_flags = + auto fbs_common_compile_flags = + get_fbs_vector_string(builder, current_common_compile_flags_); + auto fbs_c_compile_flags = get_fbs_vector_string(builder, current_c_compile_flags_); - auto fbs_cpp_compiler_flags = + auto fbs_cpp_compile_flags = get_fbs_vector_string(builder, current_cpp_compile_flags_); auto fbs_link_flags = get_fbs_vector_string(builder, current_link_flags_); @@ -101,7 +103,8 @@ bool Target::Store() { builder, name_.c_str(), fbs_target_type, &fbs_source_files, &fbs_header_files, &fbs_lib_deps, &fbs_external_lib_deps, &fbs_include_dirs, &fbs_lib_dirs, &fbs_preprocessor_flags, - &fbs_c_compiler_flags, &fbs_cpp_compiler_flags, &fbs_link_flags); + &fbs_common_compile_flags, &fbs_c_compile_flags, &fbs_cpp_compile_flags, + &fbs_link_flags); fbs::FinishTargetBuffer(builder, fbs_target); auto file_path = GetBinaryPath(); From 0e38cfb61595dd7c131d41bd1040c148a2cf4dfc Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:28:03 -0700 Subject: [PATCH 04/13] Update fbs_loader with common_compile_flags --- buildcc/lib/target/include/target/fbs_loader.h | 4 ++++ buildcc/lib/target/src/fbs/fbs_loader.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/buildcc/lib/target/include/target/fbs_loader.h b/buildcc/lib/target/include/target/fbs_loader.h index 18cf9c3b..4559b7f3 100644 --- a/buildcc/lib/target/include/target/fbs_loader.h +++ b/buildcc/lib/target/include/target/fbs_loader.h @@ -59,6 +59,9 @@ class FbsLoader { const std::unordered_set &GetLoadedPreprocessorFlags() const { return loaded_preprocessor_flags_; } + const std::unordered_set &GetLoadedCommonCompileFlags() const { + return loaded_common_compile_flags_; + } const std::unordered_set &GetLoadedCCompileFlags() const { return loaded_c_compile_flags_; } @@ -87,6 +90,7 @@ class FbsLoader { fs_unordered_set loaded_lib_dirs_; std::unordered_set loaded_preprocessor_flags_; + std::unordered_set loaded_common_compile_flags_; std::unordered_set loaded_c_compile_flags_; std::unordered_set loaded_cpp_compile_flags_; std::unordered_set loaded_link_flags_; diff --git a/buildcc/lib/target/src/fbs/fbs_loader.cpp b/buildcc/lib/target/src/fbs/fbs_loader.cpp index aed68c48..2d9bd8e9 100644 --- a/buildcc/lib/target/src/fbs/fbs_loader.cpp +++ b/buildcc/lib/target/src/fbs/fbs_loader.cpp @@ -87,6 +87,7 @@ bool FbsLoader::Load() { Extract(target->lib_dirs(), loaded_lib_dirs_); Extract(target->preprocessor_flags(), loaded_preprocessor_flags_); + Extract(target->common_compile_flags(), loaded_common_compile_flags_); Extract(target->c_compile_flags(), loaded_c_compile_flags_); Extract(target->cpp_compile_flags(), loaded_cpp_compile_flags_); Extract(target->link_flags(), loaded_link_flags_); From cbd6087488a76b8af2ec3ac6ae116ff17d82063a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:28:27 -0700 Subject: [PATCH 05/13] Updated target.h with common_compile_flags --- buildcc/lib/target/include/target/target.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 2affbe93..d174ee3d 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -113,6 +113,7 @@ class Target { // * Flags void AddPreprocessorFlag(const std::string &flag); + void AddCommonFlag(const std::string &flag); void AddCCompileFlag(const std::string &flag); void AddCppCompileFlag(const std::string &flag); void AddLinkFlag(const std::string &flag); @@ -286,6 +287,7 @@ class Target { // TODO, Common flags for asm, c and cpp files std::unordered_set current_preprocessor_flags_; + std::unordered_set current_common_compile_flags_; std::unordered_set current_c_compile_flags_; std::unordered_set current_cpp_compile_flags_; std::unordered_set current_link_flags_; From 0d3713c80e17bf5e7c187a9e60e7b872419d0948 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:29:14 -0700 Subject: [PATCH 06/13] Renamed to CommonCompileFlag --- buildcc/lib/target/include/target/target.h | 2 +- buildcc/lib/target/src/target/flags.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index d174ee3d..fcfce5e1 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -113,7 +113,7 @@ class Target { // * Flags void AddPreprocessorFlag(const std::string &flag); - void AddCommonFlag(const std::string &flag); + void AddCommonCompileFlag(const std::string &flag); void AddCCompileFlag(const std::string &flag); void AddCppCompileFlag(const std::string &flag); void AddLinkFlag(const std::string &flag); diff --git a/buildcc/lib/target/src/target/flags.cpp b/buildcc/lib/target/src/target/flags.cpp index 6d2bf126..5fac51be 100644 --- a/buildcc/lib/target/src/target/flags.cpp +++ b/buildcc/lib/target/src/target/flags.cpp @@ -21,6 +21,9 @@ namespace buildcc::base { void Target::AddPreprocessorFlag(const std::string &flag) { current_preprocessor_flags_.insert(flag); } +void Target::AddCommonCompileFlag(const std::string &flag) { + current_common_compile_flags_.insert(flag); +} void Target::AddCCompileFlag(const std::string &flag) { current_c_compile_flags_.insert(flag); } From 68512fefcfb3cf5e9c764f7d778f834abfd3a846 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:29:31 -0700 Subject: [PATCH 07/13] Update build.cpp for Recheck --- buildcc/lib/target/src/target/build.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index b4269764..ccc49255 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -88,6 +88,8 @@ void Target::BuildRecompile() { // TODO, Toolchain, ASM, C, C++ compiler related to a particular name RecheckFlags(loader_.GetLoadedPreprocessorFlags(), current_preprocessor_flags_); + RecheckFlags(loader_.GetLoadedCommonCompileFlags(), + current_common_compile_flags_); RecheckFlags(loader_.GetLoadedCCompileFlags(), current_c_compile_flags_); RecheckFlags(loader_.GetLoadedCppCompileFlags(), current_cpp_compile_flags_); RecheckDirs(loader_.GetLoadedIncludeDirs(), current_include_dirs_); From 95f75f8d10ec21694e5a3cff7a945da95dcda057 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:36:16 -0700 Subject: [PATCH 08/13] Added common_compile_flags to compile_commands_ --- buildcc/lib/target/include/target/target.h | 4 ++-- buildcc/lib/target/src/target/build.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index fcfce5e1..d6ac6f96 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -191,8 +191,8 @@ class Target { std::unordered_set valid_header_ext_{".h", ".hpp"}; std::string_view compile_command_{ - "{compiler} {preprocessor_flags} {include_dirs} {compile_flags} -o " - "{output} -c {input}"}; + "{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} " + "{compile_flags} -o {output} -c {input}"}; std::string_view link_command_{ "{cpp_compiler} {link_flags} {compiled_sources} -o {output} " "{lib_dirs} {lib_deps}"}; diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index ccc49255..c5ea6868 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -45,6 +45,8 @@ void Target::Build() { internal::aggregate_with_prefix(prefix_lib_dir_, current_lib_dirs_)}, {"preprocessor_flags", internal::aggregate(current_preprocessor_flags_)}, + {"common_compile_flags", + internal::aggregate(current_common_compile_flags_)}, {"link_flags", internal::aggregate(current_link_flags_)}, // Toolchain executables here From e4398015d3bbcc082432304f48326f660f12748a Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:41:22 -0700 Subject: [PATCH 09/13] Minor log_trace --- buildcc/lib/target/src/target/tasks.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildcc/lib/target/src/target/tasks.cpp b/buildcc/lib/target/src/target/tasks.cpp index dfe7cfca..0e530891 100644 --- a/buildcc/lib/target/src/target/tasks.cpp +++ b/buildcc/lib/target/src/target/tasks.cpp @@ -29,6 +29,8 @@ namespace buildcc::base { void Target::CompileTargetTask(std::vector &&compile_sources, std::vector &&dummy_compile_sources) { + env::log_trace(name_, __FUNCTION__); + compile_task_ = tf_.emplace([this, compile_sources, dummy_compile_sources](tf::Subflow &subflow) { From 451cfaa198cece589031f9bb039b9aa084276ea4 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:47:18 -0700 Subject: [PATCH 10/13] Added common_compile_flags to target_gcc and target_msvc --- buildcc/targets/include/targets/target_gcc.h | 8 ++++---- buildcc/targets/include/targets/target_msvc.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buildcc/targets/include/targets/target_gcc.h b/buildcc/targets/include/targets/target_gcc.h index 7cd2ca1e..9cd4d72a 100644 --- a/buildcc/targets/include/targets/target_gcc.h +++ b/buildcc/targets/include/targets/target_gcc.h @@ -30,16 +30,16 @@ constexpr std::string_view kGccDynamicLibExt = ".so"; constexpr std::string_view kGccPrefixIncludeDir = "-I"; constexpr std::string_view kGccPrefixLibDir = "-L"; constexpr std::string_view kGccGenericCompileCommand = - "{compiler} {preprocessor_flags} {include_dirs} {compile_flags} -o " - "{output} -c {input}"; + "{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} " + "{compile_flags} -o {output} -c {input}"; constexpr std::string_view kGccExecutableLinkCommand = "{cpp_compiler} {link_flags} {compiled_sources} -o {output} " "{lib_dirs} {lib_deps}"; constexpr std::string_view kGccStaticLibLinkCommand = "{archiver} rcs {output} {compiled_sources}"; constexpr std::string_view kGccDynamicLibCompileCommand = - "{compiler} {preprocessor_flags} {include_dirs} {compile_flags} " - "-fpic -o {output} -c {input}"; + "{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} " + "{compile_flags} -fpic -o {output} -c {input}"; constexpr std::string_view kGccDynamicLibLinkCommand = "{cpp_compiler} -shared {link_flags} {compiled_sources} -o {output}"; diff --git a/buildcc/targets/include/targets/target_msvc.h b/buildcc/targets/include/targets/target_msvc.h index 6312a6ba..d0e1d53f 100644 --- a/buildcc/targets/include/targets/target_msvc.h +++ b/buildcc/targets/include/targets/target_msvc.h @@ -36,8 +36,8 @@ constexpr std::string_view kMsvcPrefixIncludeDir = "/I"; constexpr std::string_view kMsvcPrefixLibDir = "/LIBPATH:"; // TODO, Split this into individual CompileCommands if any differences occur constexpr std::string_view kMsvcCompileCommand = - "{compiler} {preprocessor_flags} {include_dirs} {compile_flags} " - "/Fo{output} /c {input}"; + "{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} " + "{compile_flags} /Fo{output} /c {input}"; constexpr std::string_view kMsvcExecutableLinkCommand = "{linker} {link_flags} {lib_dirs} /OUT:{output} {lib_deps} " "{compiled_sources}"; From e05f390ba0bea30e95ab816bc347154dd04449a3 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:52:55 -0700 Subject: [PATCH 11/13] Update target_gcc.h - Removed kGccDynamicLinkCompileCommand special case - Added -fpic for DynamicGccLibrary using the AddCommonCompileFlag API --- buildcc/targets/include/targets/target_gcc.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/buildcc/targets/include/targets/target_gcc.h b/buildcc/targets/include/targets/target_gcc.h index 9cd4d72a..b397ea66 100644 --- a/buildcc/targets/include/targets/target_gcc.h +++ b/buildcc/targets/include/targets/target_gcc.h @@ -37,9 +37,6 @@ constexpr std::string_view kGccExecutableLinkCommand = "{lib_dirs} {lib_deps}"; constexpr std::string_view kGccStaticLibLinkCommand = "{archiver} rcs {output} {compiled_sources}"; -constexpr std::string_view kGccDynamicLibCompileCommand = - "{compiler} {preprocessor_flags} {include_dirs} {common_compile_flags} " - "{compile_flags} -fpic -o {output} -c {input}"; constexpr std::string_view kGccDynamicLibLinkCommand = "{cpp_compiler} -shared {link_flags} {compiled_sources} -o {output}"; @@ -70,8 +67,8 @@ class DynamicTarget_gcc : public base::Target { : Target(name, base::TargetType::DynamicLibrary, toolchain, target_path_relative_to_root) { target_ext_ = kGccDynamicLibExt; - compile_command_ = kGccDynamicLibCompileCommand; link_command_ = kGccDynamicLibLinkCommand; + AddCommonCompileFlag("-fpic"); } }; From ee8d107c0123f703e5e9f12e36cca001e34b376b Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 13:57:05 -0700 Subject: [PATCH 12/13] Updated target_generic with common_compile_flag --- buildcc/lib/target/include/target/target.h | 3 +++ buildcc/targets/include/targets/target_generic.h | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index d6ac6f96..09501f1f 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -164,6 +164,9 @@ class Target { const std::unordered_set &GetCurrentPreprocessorFlags() const { return current_preprocessor_flags_; } + const std::unordered_set &GetCurrentCommonCompileFlags() const { + return current_common_compile_flags_; + } const std::unordered_set &GetCurrentCCompileFlags() const { return current_c_compile_flags_; } diff --git a/buildcc/targets/include/targets/target_generic.h b/buildcc/targets/include/targets/target_generic.h index 1cf709b6..b8e956a6 100644 --- a/buildcc/targets/include/targets/target_generic.h +++ b/buildcc/targets/include/targets/target_generic.h @@ -26,6 +26,7 @@ namespace buildcc { struct SyncTargetOptions { bool preprocessor_flags_{false}; + bool common_compile_flags_{false}; bool c_compile_flags_{false}; bool cpp_compile_flags_{false}; bool link_flags_{false}; @@ -46,6 +47,12 @@ inline void SyncTargets(base::Target &dest, const base::Target &source, } } + if (options.common_compile_flags_) { + for (const auto &flag : source.GetCurrentCommonCompileFlags()) { + dest.AddCommonCompileFlag(flag); + } + } + if (options.c_compile_flags_) { for (const auto &flag : source.GetCurrentCCompileFlags()) { dest.AddCCompileFlag(flag); @@ -90,6 +97,7 @@ class ExecutableTarget_generic : public base::Target { } SyncTargets(*this, *target, { + .common_compile_flags_ = true, .c_compile_flags_ = true, .cpp_compile_flags_ = true, .link_flags_ = true, @@ -123,6 +131,7 @@ class StaticTarget_generic : public base::Target { } SyncTargets(*this, *target, { + .common_compile_flags_ = true, .c_compile_flags_ = true, .cpp_compile_flags_ = true, .link_flags_ = true, @@ -155,6 +164,7 @@ class DynamicTarget_generic : public base::Target { } SyncTargets(*this, *target, { + .common_compile_flags_ = true, .c_compile_flags_ = true, .cpp_compile_flags_ = true, .link_flags_ = true, @@ -188,6 +198,7 @@ class Target_generic : public base::Target { } SyncTargets(*this, *target, { + .common_compile_flags_ = true, .c_compile_flags_ = true, .cpp_compile_flags_ = true, .link_flags_ = true, From 30a4a248611153d7d1a0d1e4b8402269c9bfebb8 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Sun, 8 Aug 2021 16:01:47 -0700 Subject: [PATCH 13/13] Added GetCompiledFlags with std::optional --- buildcc/lib/target/include/target/target.h | 2 ++ buildcc/lib/target/src/target/source.cpp | 4 +--- buildcc/lib/target/src/target/target.cpp | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 09501f1f..ad264c81 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -210,6 +211,7 @@ class Target { const internal::Path &GetCompiledSourcePath(const fs::path &source) const; internal::path_unordered_set GetCompiledSources() const; + std::optional GetCompiledFlags(FileExtType type) const; private: void Initialize(); diff --git a/buildcc/lib/target/src/target/source.cpp b/buildcc/lib/target/src/target/source.cpp index 5186e330..e9bd16a4 100644 --- a/buildcc/lib/target/src/target/source.cpp +++ b/buildcc/lib/target/src/target/source.cpp @@ -186,9 +186,7 @@ std::string Target::CompileCommand(const fs::path ¤t_source) const { // TODO, This doesn't look clean const auto type = GetFileExtType(current_source); const std::string &aggregated_compile_flags = - type == FileExtType::C ? aggregated_c_compile_flags_ - : type == FileExtType::Cpp ? aggregated_cpp_compile_flags_ - : ""; + GetCompiledFlags(type).value_or(""); return command_.Construct(compile_command_, { diff --git a/buildcc/lib/target/src/target/target.cpp b/buildcc/lib/target/src/target/target.cpp index 205b2fe1..33d89500 100644 --- a/buildcc/lib/target/src/target/target.cpp +++ b/buildcc/lib/target/src/target/target.cpp @@ -71,6 +71,20 @@ FileExtType Target::GetFileExtType(const fs::path &filepath) const { return type; } +std::optional Target::GetCompiledFlags(FileExtType type) const { + switch (type) { + case FileExtType::C: + return aggregated_c_compile_flags_; + break; + case FileExtType::Cpp: + return aggregated_cpp_compile_flags_; + break; + default: + break; + } + return {}; +} + bool Target::IsValidSource(const fs::path &sourcepath) const { bool valid = false; switch (GetFileExtType(sourcepath)) {