Skip to content

Commit cbee84a

Browse files
meteorcloudycopybara-github
authored andcommitted
Use a separate feature for cpp std option on Windows
Copybara Import from #443 BEGIN_PUBLIC Use a separate feature for cpp std option on Windows (#443) Address #440 (comment) We should probably do the same for unix cc toolchains, but that needs more clean up first. Closes #443 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=#443 from meteorcloudy:msvc_cpp_std 3c4f7b3 PiperOrigin-RevId: 784153348 Change-Id: Ibc1b580d7b5b6df34ec1db70f2005b9002585f65
1 parent d068b73 commit cbee84a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

cc/private/toolchain/windows_cc_toolchain_config.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,21 @@ def _impl(ctx):
728728
],
729729
)
730730

731+
default_cpp_std_feature = feature(
732+
name = "default_cpp_std",
733+
enabled = True,
734+
flag_sets = [
735+
flag_set(
736+
actions = all_cpp_compile_actions,
737+
flag_groups = [
738+
flag_group(
739+
flags = ["/std:c++17"],
740+
),
741+
],
742+
),
743+
],
744+
)
745+
731746
default_compile_flags_feature = feature(
732747
name = "default_compile_flags",
733748
enabled = True,
@@ -751,7 +766,6 @@ def _impl(ctx):
751766
flag_groups = [
752767
flag_group(
753768
flags = [
754-
"/std:c++17",
755769
"/DNOMINMAX",
756770
"/D_WIN32_WINNT=0x0601",
757771
"/D_CRT_SECURE_NO_DEPRECATE",
@@ -1274,6 +1288,7 @@ def _impl(ctx):
12741288
no_stripping_feature,
12751289
targets_windows_feature,
12761290
copy_dynamic_libraries_to_binary_feature,
1291+
default_cpp_std_feature,
12771292
default_compile_flags_feature,
12781293
msvc_env_feature,
12791294
msvc_compile_env_feature,

tests/simple_binary/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ cc_binary(
2626
srcs = ["foo.cc"],
2727
linkshared = 1,
2828
)
29+
30+
# Regression test for building C code
31+
# https://github.com/bazelbuild/rules_cc/pull/440#issuecomment-3075519628
32+
cc_binary(
33+
name = "bar",
34+
srcs = ["bar.c"],
35+
copts = select({
36+
"@platforms//os:windows": ["/std:c11"],
37+
"//conditions:default": [],
38+
}),
39+
)

tests/simple_binary/bar.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
int main(int argc, char *argv[]) { return 0; }

0 commit comments

Comments
 (0)