diff --git a/cpp/private/actions/compile.bzl b/cpp/private/actions/compile.bzl index 35e74c9..5a59c19 100644 --- a/cpp/private/actions/compile.bzl +++ b/cpp/private/actions/compile.bzl @@ -18,6 +18,7 @@ def _cpp_compile_impl(ctx, sources, headers, includes, modules, features, toolch for m in modules: module_files.append(m["file"]) + module_files.append(m["source"]) module_vars.append("{name}={file}".format(name = m["name"], file = m["file"].path)) extra_vars["cpp_precompiled_modules"] = module_vars @@ -31,7 +32,7 @@ def _cpp_compile_impl(ctx, sources, headers, includes, modules, features, toolch action_name = action_name, ) - outfile = ctx.actions.declare_file("_objs/" + src.basename + ".o") + outfile = ctx.actions.declare_file("_objs/" + ctx.label.name + "/" + src.basename + ".o") args = get_compile_command_args( toolchain, source = src.path, diff --git a/cpp/private/common.bzl b/cpp/private/common.bzl index 248550c..e901874 100644 --- a/cpp/private/common.bzl +++ b/cpp/private/common.bzl @@ -6,8 +6,7 @@ def collect_external_headers(deps): for dep in deps: if CcInfo in dep: - headers.extend(dep[CcInfo].compilation_context.direct_public_headers) - headers.extend(dep[CcInfo].compilation_context.direct_textual_headers) + headers.extend(dep[CcInfo].compilation_context.headers.to_list()) return headers @@ -16,6 +15,9 @@ def collect_external_includes(deps): for dep in deps: if CcInfo in dep: includes.extend(dep[CcInfo].compilation_context.includes.to_list()) + includes.extend(dep[CcInfo].compilation_context.external_includes.to_list()) + includes.extend(dep[CcInfo].compilation_context.system_includes.to_list()) + includes.extend(dep[CcInfo].compilation_context.quote_includes.to_list()) return depset(includes) def collect_modules(deps): @@ -26,11 +28,13 @@ def collect_modules(deps): modules.append({ "name": dep[CppModuleInfo].module_name, "file": dep[CppModuleInfo].pcm, + "source": dep[CppModuleInfo].interface_source, }) for part in dep[CppModuleInfo].partitions.to_list(): modules.append({ "name": part[CppModuleInfo].module_name, "file": part[CppModuleInfo].pcm, + "source": part[CppModuleInfo].interface_source, }) return modules diff --git a/cpp/private/target_rules.bzl b/cpp/private/target_rules.bzl index c71140e..a171275 100644 --- a/cpp/private/target_rules.bzl +++ b/cpp/private/target_rules.bzl @@ -138,7 +138,7 @@ def module_impl(ctx): extra_vars["cpp_precompiled_modules"] = module_vars - pcm = ctx.actions.declare_file("_pcm/" + ctx.attr.module_name + "-" + ctx.files.interface[0].basename[:-(len(ctx.files.interface[0].extension) + 1)] + ".pcm") + pcm = ctx.actions.declare_file("_pcm/" + ctx.attr.name + "/" + ctx.attr.module_name + "-" + ctx.files.interface[0].basename[:-(len(ctx.files.interface[0].extension) + 1)] + ".pcm") precompile_args = get_compile_command_args( toolchain, @@ -171,6 +171,7 @@ def module_impl(ctx): module_name = ctx.attr.module_name, pcm = pcm, objs = obj_files, + interface_source = ctx.files.interface[0], partitions = depset(ctx.attr.partitions), ) diff --git a/cpp/private/toolchain.bzl b/cpp/private/toolchain.bzl index 9c95fa4..c1dac80 100644 --- a/cpp/private/toolchain.bzl +++ b/cpp/private/toolchain.bzl @@ -179,6 +179,7 @@ def _get_clang_features(ctx): flag_set( actions = all_cpp_compile_actions + [EXTRA_ACTIONS.cpp_module_precompile_interface], flag_groups = [ + flag_group(flags = ["-fno-implicit-modules"]), flag_group( iterate_over = "cpp_precompiled_modules", expand_if_available = "cpp_precompiled_modules", diff --git a/cpp/providers.bzl b/cpp/providers.bzl index a50e08a..84236b8 100644 --- a/cpp/providers.bzl +++ b/cpp/providers.bzl @@ -3,6 +3,7 @@ CppModuleInfo = provider( "module_name": "name of the exported module", "pcm": "file containing precompiled module", "objs": "compiled object files", + "interface_source": "source file for the interface of the module", "partitions": "required dependencies", }, )