Skip to content
Open
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
69 changes: 69 additions & 0 deletions test/layering_check/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test", "objc_library")
load("//test/rules:action_command_line_test.bzl", "action_command_line_test")

package(features = ["layering_check"])

Expand Down Expand Up @@ -37,6 +38,74 @@ cc_test(
],
)

# From Clang 14 on, -std=c++20 switches the driver to C++20 modules
# semantics: including a header a module map covers *non-textually* becomes
# "module 'cxx20_modular' is needed but has not been provided" -- unless the
# toolchain passes -fno-cxx-modules (//toolchain:no_cxx_modules_flags, gated
# on use_module_maps). wrapped_clang's generated map and the per-target maps
# Bazel writes are all-textual and immune, but the system module map of a
# hermetic toolchain driving this configuration is not.
cc_library(
name = "cxx20_non_textual_module_map",
srcs = ["modular.cpp"],
hdrs = ["modular.h"],
additional_compiler_inputs = ["cxx20.modulemap"],
copts = [
"-std=c++20",
"-fmodule-map-file=$(execpath cxx20.modulemap)",
],
# use_module_maps alone, without layering_check: strict-decluse would
# (correctly) reject the include, since nothing declares a dependency on
# the map's module. The fix is gated on use_module_maps, not on
# layering_check itself.
features = [
"-layering_check",
"use_module_maps",
],
)

build_test(
name = "cxx20_non_textual_module_map_test",
targets = [":cxx20_non_textual_module_map"],
)

# The flag is emitted exactly when use_module_maps is enabled: by itself, by
# way of layering_check, and never without. Note the build test above cannot
# fail under Xcode's clang, which does not switch to C++20 modules semantics
# the way upstream Clang 14+ does -- these assert the flag so the fix is
# visible under the tools this repo tests with.
action_command_line_test(
name = "no_cxx_modules_flags_from_module_maps_test",
expected_argv = [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c",
],
mnemonic = "CppCompile",
tags = ["requires_rules_based_toolchain"],
target_under_test = ":cxx20_non_textual_module_map",
)

action_command_line_test(
name = "no_cxx_modules_flags_from_layering_check_test",
expected_argv = [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c",
],
mnemonic = "CppCompile",
tags = ["requires_rules_based_toolchain"],
target_under_test = ":good_layering_check",
)

action_command_line_test(
name = "no_cxx_modules_flags_off_without_module_maps_test",
mnemonic = "CppCompile",
not_expected_argv = ["-fno-cxx-modules"],
tags = ["requires_rules_based_toolchain"],
target_under_test = ":disabled_bad_layering_check",
)

objc_library(
name = "bad_layering_check_objc",
srcs = ["c.m"],
Expand Down
7 changes: 7 additions & 0 deletions test/layering_check/cxx20.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// A module map whose header is *not* textual, like the umbrella-directory
// system module maps a hermetic toolchain generates for its own headers --
// unlike the all-textual maps wrapped_clang injects and Bazel writes per
// target, which C++20 modules semantics leave alone.
module "cxx20_modular" [system] {
header "modular.h"
}
3 changes: 3 additions & 0 deletions test/layering_check/modular.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "modular.h"

int uses_modular() { return from_modular_header(); }
6 changes: 6 additions & 0 deletions test/layering_check/modular.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef TEST_LAYERING_CHECK_MODULAR_H_
#define TEST_LAYERING_CHECK_MODULAR_H_

inline int from_modular_header() { return 20; }

#endif // TEST_LAYERING_CHECK_MODULAR_H_
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/darwin_arm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/darwin_arm64e.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/darwin_x86_64.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/ios_arm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/ios_arm64e.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
39 changes: 39 additions & 0 deletions test/test_data/toolchain_configs/ios_sim_arm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,45 @@
"type_name": "flag_set",
"with_features": []
},
{
"actions": [
"c++-compile",
"c++-header-parsing",
"c++-module-codegen",
"c++-module-compile",
"clif-match",
"linkstamp-compile",
"lto-backend",
"objc++-compile"
],
"flag_groups": [
{
"expand_if_available": null,
"expand_if_equal": null,
"expand_if_false": null,
"expand_if_not_available": null,
"expand_if_true": null,
"flag_groups": [],
"flags": [
"-Xclang",
"-fno-cxx-modules",
"-Wno-module-import-in-extern-c"
],
"iterate_over": null,
"type_name": "flag_group"
}
],
"type_name": "flag_set",
"with_features": [
{
"features": [
"use_module_maps"
],
"not_features": [],
"type_name": "with_feature_set"
}
]
},
{
"actions": [
"assemble",
Expand Down
Loading