Skip to content

Commit d932f1b

Browse files
authored
Have Bazel disable GCC SFrame option if possible (#1055)
This adds the flag `-Wa,--gsframe=no` to the Bazel configuration for Linux systems, to deal with an error that happens with GCC 15.2. A similar addition was made to the Makefiles in a past PR.
1 parent a480778 commit d932f1b

7 files changed

Lines changed: 92 additions & 3 deletions

File tree

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ common --enable_platform_specific_config
2525

2626
build:linux --copt=-std=c++17
2727
build:linux --cxxopt=-std=c++17
28+
build:linux --per_file_copt="googletest/.*@-Xassembler,-W"
2829

2930
build:macos --copt=-std=c++17
3031
build:macos --cxxopt=-std=c++17

WORKSPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ http_archive(
2525

2626
http_archive(
2727
name = "com_google_googletest",
28+
patch_args = ["-p1"],
29+
patches = ["//third_party:googletest.patch"],
2830
sha256 = "40d4ec942217dcc84a9ebe2a68584ada7d4a33a8ee958755763278ea1c5e18ff",
2931
strip_prefix = "googletest-1.17.0",
3032
url = "https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip",
@@ -55,6 +57,10 @@ load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")
5557

5658
tf_workspace0()
5759

60+
load("//dev_tools:compiler_probe.bzl", "compiler_probe")
61+
62+
compiler_probe(name = "local_compiler_config")
63+
5864
# https://gitlab.com/libeigen/eigen/-/releases/3.4.1
5965
EIGEN_COMMIT = "b66188b5dfd147265bfa9ec47595ca0db72d21f5"
6066

apps/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414

1515
# TODO: remove reliance on getopt (unistd.h) to allow apps to run on Windows.
1616

17+
load("@local_compiler_config//:compiler_config.bzl", "SUPPORTS_GSFRAME")
1718
load("@rules_cc//cc:defs.bzl", "cc_binary")
1819

20+
gsframe_copts = select({
21+
"@platforms//os:linux": ["-Wa,--gsframe=no"] if SUPPORTS_GSFRAME else [],
22+
"//conditions:default": [],
23+
})
24+
1925
cc_binary(
2026
name = "qsim_base",
2127
srcs = ["qsim_base.cc"],
28+
copts = gsframe_copts,
2229
data = ["//circuits:circuit_q24"],
2330
deps = [
2431
"//lib:run_qsim_lib",
@@ -28,6 +35,7 @@ cc_binary(
2835
cc_binary(
2936
name = "qsim_von_neumann",
3037
srcs = ["qsim_von_neumann.cc"],
38+
copts = gsframe_copts,
3139
deps = [
3240
"//lib:run_qsim_lib",
3341
],
@@ -36,6 +44,7 @@ cc_binary(
3644
cc_binary(
3745
name = "qsim_amplitudes",
3846
srcs = ["qsim_amplitudes.cc"],
47+
copts = gsframe_copts,
3948
deps = [
4049
"//lib:bitstring",
4150
"//lib:run_qsim_lib",
@@ -45,6 +54,7 @@ cc_binary(
4554
cc_binary(
4655
name = "qsimh_base",
4756
srcs = ["qsimh_base.cc"],
57+
copts = gsframe_copts,
4858
deps = [
4959
"//lib:bitstring",
5060
"//lib:run_qsimh_lib",
@@ -54,6 +64,7 @@ cc_binary(
5464
cc_binary(
5565
name = "qsimh_amplitudes",
5666
srcs = ["qsimh_amplitudes.cc"],
67+
copts = gsframe_copts,
5768
deps = [
5869
"//lib:bitstring",
5970
"//lib:run_qsimh_lib",

dev_tools/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty BUILD file to make dev_tools a package.

dev_tools/compiler_probe.bzl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2026 Google LLC
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+
# https://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+
"""Repository rule to probe compiler support for SFrame flags."""
16+
17+
def _compiler_probe_impl(repository_ctx):
18+
# Try to determine the compiler. Prefer CC from environment.
19+
cc = repository_ctx.os.environ.get("CC", "c++")
20+
21+
# Run a test compilation to test if the flag is recognized.
22+
# This is hacky and I wish there was a better way.
23+
res = repository_ctx.execute([
24+
cc,
25+
"-Wa,--gsframe=no",
26+
"-c",
27+
"-x",
28+
"c++",
29+
"/dev/null",
30+
"-o",
31+
"/dev/null",
32+
])
33+
34+
supports_gsframe = (res.return_code == 0)
35+
36+
repository_ctx.file("BUILD.bazel", "package(default_visibility = ['//visibility:public'])\n")
37+
repository_ctx.file("compiler_config.bzl", "SUPPORTS_GSFRAME = %s\n" % supports_gsframe)
38+
39+
compiler_probe = repository_rule(
40+
implementation = _compiler_probe_impl,
41+
local = True,
42+
environ = ["CC", "PATH"],
43+
)

tests/BUILD

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@local_compiler_config//:compiler_config.bzl", "SUPPORTS_GSFRAME")
1516
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
1617

18+
gsframe_copts = ["-Wa,--gsframe=no"] if SUPPORTS_GSFRAME else []
19+
1720
# Options for testing different simulator types.
1821
avx_copts = [
1922
"-mavx2",
2023
"-mfma",
21-
]
24+
] + gsframe_copts
2225

23-
avx512_copts = ["-march=native"]
26+
avx512_copts = ["-march=native"] + gsframe_copts
2427

25-
sse_copts = ["-msse4"]
28+
sse_copts = ["-msse4"] + gsframe_copts
2629

2730
windows_copts = [
2831
"/arch:AVX",

third_party/googletest.patch

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--- a/BUILD.bazel
2+
+++ b/BUILD.bazel
3+
@@ -32,6 +32,12 @@
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
+load("@local_compiler_config//:compiler_config.bzl", "SUPPORTS_GSFRAME")
8+
+gsframe_copts = select({
9+
+ "@platforms//os:linux": ["-Wa,--gsframe=no"] if SUPPORTS_GSFRAME else [],
10+
+ "//conditions:default": [],
11+
+})
12+
+
13+
licenses(["notice"])
14+
15+
exports_files(["LICENSE"])
16+
@@ -108,7 +112,7 @@
17+
"googletest/include/gtest/*.h",
18+
"googlemock/include/gmock/*.h",
19+
]),
20+
- copts = select({
21+
+ copts = gsframe_copts + select({
22+
":qnx": [],
23+
":windows": [],
24+
"//conditions:default": ["-pthread"],

0 commit comments

Comments
 (0)