Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cc/private/toolchain/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ licenses(["notice"]) # Apache 2.0

cc_library(name = "empty_lib")

%{std_module}

# Label flag for extra libraries to be linked into every binary.
# TODO(bazel-team): Support passing flag multiple times to build a list.
label_flag(
Expand Down
16 changes: 16 additions & 0 deletions cc/private/toolchain/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def _get_cxx_include_directories(repository_ctx, print_resource_dir_supported, c

return inc_directories

def _get_share_libcxx_v1_dir(repository_ctx, cc, additional_flags = []):
return repository_ctx.execute([cc, "-print-resource-dir"] + additional_flags).stdout.strip() + "/../../../share/libc++/v1"

def _is_compiler_option_supported(repository_ctx, cc, option):
"""Checks that `option` is supported by the C compiler. Doesn't %-escape the option."""
result = repository_ctx.execute([
Expand Down Expand Up @@ -608,6 +611,11 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overridden_tools):
extra_flags_per_feature["use_module_maps"] = ["-Xclang", "-fno-cxx-modules"]

write_builtin_include_directory_paths(repository_ctx, cc, builtin_include_directories)
if is_clang:
libcxx_v1_dir = _get_share_libcxx_v1_dir(repository_ctx, cc)
files = repository_ctx.execute(["ls", libcxx_v1_dir]).stdout.strip().split("\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use repository_ctx.path(...).readdir() instead to list files within Starlark.

for file in files:
repository_ctx.symlink(libcxx_v1_dir + "/" + file, file)
repository_ctx.template(
"BUILD",
paths["@rules_cc//cc/private/toolchain:BUILD.tpl"],
Expand Down Expand Up @@ -767,5 +775,13 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overridden_tools):
"-D__TIME__=\\\"redacted\\\"",
],
),
"%{std_module}": """
cc_library(
name = "std_modules",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the std module has to be passed into the cc_toolchain in some way so that users can get the module for their current toolchain, not the host toolchain. That's why exposing this target directly wouldn't work well.

If it's common for folks to import std, could we add this dependency automatically to all module_interfaces? Or should this be toggleable on the toolchain? Requiring an explicit dep on std could become tedious.

srcs = glob(["std/**"]),
module_interfaces = ["std.cppm"],
features = ["cpp_modules"],
)
""",
},
)