Skip to content

Commit

Permalink
fix: correctly resolve target dependencies (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatashev authored Jan 1, 2024
1 parent 4634323 commit a8d079d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cpp/private/actions/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions cpp/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cpp/private/target_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
)

Expand Down
1 change: 1 addition & 0 deletions cpp/private/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cpp/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

0 comments on commit a8d079d

Please sign in to comment.