Skip to content

Instantly share code, notes, and snippets.

@oquenchil
Created August 12, 2022 10:14
Show Gist options
  • Save oquenchil/e6e39237b4c7b95b7b96396764b9a97c to your computer and use it in GitHub Desktop.
Save oquenchil/e6e39237b4c7b95b7b96396764b9a97c to your computer and use it in GitHub Desktop.
Features Clang Modules
def get_header_module_features(target_cpu):
"""Returns features that control header modules."""
# Configure header modules:
#
# We have different features for module consumers and producers:
# 'header_modules' is enabled for targets that support being compiled as a
# header module.
# 'use_header_modules' is enabled for targets that want to use the provided
# header modules from their transitive closure. We enable this globally and
# disable it for targets that do not support builds with header modules.
# Allow switching off header modules completely by specifying
# features=["-use_header_modules"] in a rule.
return [
feature(
name = "header_modules",
implies = ["header_module_compile"],
requires = [feature_set(features = ["use_header_modules"])],
),
feature(
name = "header_module_codegen",
requires = [feature_set(features = ["header_modules"])],
),
feature(
name = "header_modules_codegen_functions",
implies = ["header_module_codegen"],
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_module_compile],
flag_groups = [flag_group(flags = ["-Xclang=-fmodules-codegen"])],
),
],
),
feature(
name = "header_modules_codegen_debuginfo",
implies = ["header_module_codegen"],
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_module_compile],
flag_groups = [
flag_group(flags = ["-Xclang=-fmodules-debuginfo"]),
],
),
],
),
feature(
name = "header_module_compile",
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_module_compile],
flag_groups = [
flag_group(flags = [
"-xc++",
"-Xclang=-emit-module",
"-Xclang=-fmodules-embed-all-files",
"-Xclang=-fmodules-local-submodule-visibility",
"-Xcrosstool-module-compilation",
]),
],
),
],
),
feature(
name = "use_header_modules",
implies = ["use_module_maps"],
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
],
flag_groups = [
flag_group(flags = [
"-fmodules",
"-fmodule-file-deps",
"-fno-implicit-modules",
"-fno-implicit-module-maps",
"-Wno-modules-ambiguous-internal-linkage",
"-Wno-module-import-in-extern-c",
"-Wno-modules-import-nested-redundant",
]),
flag_group(
flags = [
"-Xclang=-fmodule-file=%{module_files}",
],
iterate_over = "module_files",
),
],
),
],
),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment