Skip to content

Commit

Permalink
fix: allow implementation files in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatashev committed Jan 4, 2024
1 parent bdb5d4e commit e59d730
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cpp/private/target_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Contains rules implementations for building C++ targets
"""

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("//cpp:providers.bzl", "CppModuleInfo")
load("//cpp/private:common.bzl", "collect_external_headers", "collect_external_includes", "collect_module_objects", "collect_modules", "get_compile_command_args", "resolve_linker_arguments")
load("//cpp/private:extra_actions.bzl", "EXTRA_ACTIONS")
load("//cpp/private/actions:compile.bzl", "cpp_compile")
load("//cpp/private/actions:strip.bzl", "cpp_strip_binary", "cpp_strip_objects")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

def _has_agressive_strip(features, _toolchain):
# FIXME(alexbatashev): does not work with default toolchain
Expand Down Expand Up @@ -165,7 +165,13 @@ def module_impl(ctx):
progress_message = "Precompiling %{output}",
)

obj_files = cpp_compile(ctx.files.srcs + [pcm], headers, includes, modules, features, toolchain, module_srcs = ctx.files.interface)
cur_module = {
"name": ctx.attr.module_name,
"file": pcm,
"source": ctx.files.interface[0],
}

obj_files = cpp_compile(ctx.files.srcs + [pcm], headers, includes, modules + [cur_module], features, toolchain, module_srcs = ctx.files.interface)
obj_files = depset(cpp_strip_objects(obj_files, features, toolchain), transitive = collect_module_objects(ctx.attr.deps + ctx.attr.partitions))

return CppModuleInfo(
Expand Down
1 change: 1 addition & 0 deletions integration_tests/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(

cpp_module(
name = "test",
srcs = ["module/impl.cpp"],
interface = "module/interface.cppm",
module_name = "test",
)
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/rules/module/impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module;

#include <iostream>

module test;

void hello_impl() { std::cout << "hello impl\n"; }
6 changes: 3 additions & 3 deletions integration_tests/rules/module/interface.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module;

export module test;

export void hello() {
std::cout << "Hello from module\n";
}
export void hello() { std::cout << "Hello from module\n"; }

export void hello_impl();
1 change: 1 addition & 0 deletions integration_tests/rules/module/module_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import test;

int main() {
hello();
hello_impl();
return 0;
}

0 comments on commit e59d730

Please sign in to comment.