-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1/5] support C++20 Modules, add module_interfaces attr #22425
base: master
Are you sure you want to change the base?
[1/5] support C++20 Modules, add module_interfaces attr #22425
Conversation
src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests in the same PR?
- verify the experimental flag works as expected
- verify cc_binary, cc_test and cc_library work with the new attribute (although do nothing yet)
- verify calling cc_common.compile works with the new parameter
hi @mathstuf, In current implementation, I'm using the With this feature, we can update our codebase bit by bit, turning on C++20 Modules for some code without having to scan every file. |
f512dae
to
4cc08d9
Compare
hi @comius, I have updated the code. please review again. I test the failed case the new branch only add ci config. There could be differing settings that prevent the replication of the CI error. |
OptionEffectTag.CHANGES_INPUTS | ||
}, | ||
metadataTags = {OptionMetadataTag.EXPERIMENTAL}, | ||
help = "If enabled, cc_binary and cc_library targets can use attribute `module_interfaces`.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put under the help string:
Enables experimental C++20 modules support. Use it with `module_interfaces` attribute on `cc_binary` and `cc_library`.
While the support is behind the experimental flag, there are no guarantees about incompatible changes to it or even keeping the support in the future. Consider those risks when using it.
@@ -117,6 +117,11 @@ def _check_can_use_implementation_deps(ctx): | |||
if (not experimental_cc_implementation_deps and ctx.attr.implementation_deps): | |||
fail("requires --experimental_cc_implementation_deps", attr = "implementation_deps") | |||
|
|||
def _check_can_module_interfaces(ctx): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this code into cc_helper.check_cpp20_modules
. There's no need to have it in 2 different locations.
(Also semantics.bzl is a bit special, because we have a different internal version of it. There's no need to make this difference here).
<li>MSVC use ixx </li> | ||
</ul> | ||
</p> | ||
<p>For now usage is guarded by the flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For now usage
-> The use
Technical documentation should avoid using for now
or other time constructs. Especially at Google :)
|
||
# "srcs" attribute is a LABEL_LIST in cc_rules, which might also contain files. | ||
# "srcs" attribute is a LABEL_LIST in cc_rules, which might also contain files. | ||
def _calculate_artifact_label_map(srcs, attr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename srcs
-> attr_list
, attr
-> attr_name
, src
-> attr
. (The code is not used only for srcs attribute anymore)
change the comment over the function into a doc string:
"""
Converts a label_list attribute into a list of (Artifact, Label) tuples.
Each tuple represents an input source file and the label of the rule that generates it (or the label of the source file itself if it is an input file.
"""
Remove other (duplicated) comments above _get_srcs and _get_cpp20module_interfaces.
@Override | ||
protected ConfiguredRuleClassProvider createRuleClassProvider() { | ||
ConfiguredRuleClassProvider.Builder builder = new ConfiguredRuleClassProvider.Builder(); | ||
TestRuleClassProvider.addStandardRules(builder); | ||
builder.addConfigurationFragment(DummyTestFragment.class); | ||
return builder.addRuleDefinition(new TestRuleClassProvider.MakeVariableTesterRule()).build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this block. Please remove it.
ImmutableList<String> targetList = ImmutableList.of("//foo:lib", "//foo:bin", "//foo:test"); | ||
scratch.file( | ||
"foo/BUILD", | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose to move this scratch.file
into a setup method, i.e.
@Before
public void setupBasicRulesWithModules() {
scratch.file(....);
}
DRY is usually an antipattern for the tests, but in this case I'd recommend it.
supernit: fix weird indentation, make cc_library line up with opening """.
module_interfaces = ["foo.cppm"], | ||
) | ||
"""); | ||
for(String targetName: targetList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unroll the loop, i.e copy-paste each of the assert without using a for
. Same for the other two tests.
This is where you don't want to follow DRY in the test. Without a loop when an assert fails, the line number will tell you where it failed. (With a for loop you can't tell which targetName
failed)
"""); | ||
for(String targetName: targetList) { | ||
AssertionError e = assertThrows(AssertionError.class, () -> getConfiguredTarget(targetName)); | ||
assertThat(e).hasMessageThat().contains("requires --experimental_cpp20_modules"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this assertion always passes - due to a weird unit test setup we have. Have you tried changing the message, does it fail?
The pattern to use is https://cs.opensource.google/bazel/bazel/+/master:src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java;l=111-113;drc=03ac7ae4e2c7743ab797c8179d428235c1a9d052
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//a:a");
assertContainsEvent("..."); // or assertNoEvents();
That's probably fine given what I know of Bazel (that per-source behaviors are discouraged). |
I split the XXL PR #19940 into several small patches.
This is the first patch of Support C++20 Modules, I add
module_interfaces
attr onlyexample
build failed with the following message
To build with C++20 Modules, the flag
--experimental_cpp20_modules
must be added.To build with C++20 Modules, the feature
cpp20_modules
must be enabled.the flag
--experimental_cpp20_modules
works on global andthe feature
cpp20_modules
work on each targetbut in this patch, do nothing with C++20 Module Interfaces.