Skip to content

Commit f694259

Browse files
authored
[googletest] avoid -lpthread link option when building with emscripten without threads (#5992)
I also created an [upstream PR](google/googletest#4824) for this change.
1 parent 29524ed commit f694259

File tree

6 files changed

+166
-1
lines changed

6 files changed

+166
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2024 Google Inc.
2+
# All Rights Reserved.
3+
#
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are
7+
# met:
8+
#
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above
12+
# copyright notice, this list of conditions and the following disclaimer
13+
# in the documentation and/or other materials provided with the
14+
# distribution.
15+
# * Neither the name of Google Inc. nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
# https://bazel.build/external/overview#bzlmod
32+
33+
module(
34+
name = "googletest",
35+
version = "1.17.0.bcr.1",
36+
compatibility_level = 1,
37+
)
38+
39+
# Only direct dependencies need to be listed below.
40+
# Please keep the versions in sync with the versions in the WORKSPACE file.
41+
42+
bazel_dep(
43+
name = "abseil-cpp",
44+
version = "20250127.1",
45+
)
46+
bazel_dep(
47+
name = "platforms",
48+
version = "0.0.11",
49+
)
50+
bazel_dep(
51+
name = "re2",
52+
version = "2024-07-02.bcr.1",
53+
)
54+
55+
bazel_dep(
56+
name = "rules_python",
57+
version = "1.3.0",
58+
dev_dependency = True,
59+
)
60+
61+
# https://rules-python.readthedocs.io/en/stable/toolchains.html#library-modules-with-dev-only-python-usage
62+
python = use_extension(
63+
"@rules_python//python/extensions:python.bzl",
64+
"python",
65+
dev_dependency = True,
66+
)
67+
python.toolchain(
68+
ignore_root_user_error = True,
69+
is_default = True,
70+
python_version = "3.12",
71+
)
72+
73+
# See fake_fuchsia_sdk.bzl for instructions on how to override this with a real SDK, if needed.
74+
fuchsia_sdk = use_extension("//:fake_fuchsia_sdk.bzl", "fuchsia_sdk")
75+
fuchsia_sdk.create_fake()
76+
use_repo(fuchsia_sdk, "fuchsia_sdk")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--- BUILD.bazel
2+
+++ BUILD.bazel
3+
@@ -56,6 +56,16 @@ config_setting(
4+
constraint_values = ["@platforms//os:openbsd"],
5+
)
6+
7+
+config_setting(
8+
+ name = "emscripten_without_threads",
9+
+ constraint_values = [
10+
+ "@platforms//os:emscripten",
11+
+ ],
12+
+ values = {
13+
+ "features": "-use_pthreads",
14+
+ },
15+
+)
16+
+
17+
# NOTE: Fuchsia is not an officially supported platform.
18+
config_setting(
19+
name = "fuchsia",
20+
@@ -111,10 +121,12 @@ cc_library(
21+
copts = select({
22+
":qnx": [],
23+
":windows": [],
24+
+ ":emscripten_without_threads": [],
25+
"//conditions:default": ["-pthread"],
26+
}),
27+
defines = select({
28+
":has_absl": ["GTEST_HAS_ABSL=1"],
29+
+ ":emscripten_without_threads": ["GTEST_HAS_PTHREAD=0"],
30+
"//conditions:default": [],
31+
}),
32+
features = select({
33+
@@ -138,6 +150,7 @@ cc_library(
34+
"-lm",
35+
"-pthread",
36+
],
37+
+ ":emscripten_without_threads": [],
38+
"//conditions:default": ["-pthread"],
39+
}),
40+
deps = select({
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- MODULE.bazel
2+
+++ MODULE.bazel
3+
@@ -32,7 +32,7 @@
4+
5+
module(
6+
name = "googletest",
7+
- version = "1.17.0",
8+
+ version = "1.17.0.bcr.1",
9+
compatibility_level = 1,
10+
)
11+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
matrix:
2+
bazel:
3+
- 8.x
4+
unix_platform:
5+
- debian11
6+
- ubuntu2404
7+
- macos
8+
- macos_arm64
9+
windows_platform:
10+
- windows
11+
tasks:
12+
unix_presubmit:
13+
name: Unix Presubmit
14+
platform: ${{ unix_platform }}
15+
bazel: ${{ bazel }}
16+
build_flags:
17+
- '--cxxopt=-std=c++17'
18+
build_targets:
19+
- '@googletest//:all'
20+
windows_presubmit:
21+
name: Windows Presubmit
22+
platform: ${{ windows_platform }}
23+
bazel: ${{ bazel }}
24+
build_flags:
25+
- '--cxxopt=/std:c++17'
26+
build_targets:
27+
- '@googletest//:all'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"url": "https://github.com/google/googletest/releases/download/v1.17.0/googletest-1.17.0.tar.gz",
3+
"strip_prefix": "googletest-1.17.0",
4+
"integrity": "sha256-Zfq3AdmCnTjLd8FKzcQx0hCL/b+JeeQOuK5Wft8Qsnw=",
5+
"patch_strip": 0,
6+
"patches": {
7+
"build_bazel.patch": "sha256-tMYspfSBszCA4xVp42vVtO8g5849WEI/04pQCChQl7g=",
8+
"module_bazel.patch": "sha256-8tzhrZfwrEb/XD0lX+Etv/6Ap/YInEl9tCFebibiQcI="
9+
}
10+
}

modules/googletest/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"1.15.2",
2222
"1.16.0",
2323
"1.16.0.bcr.1",
24-
"1.17.0"
24+
"1.17.0",
25+
"1.17.0.bcr.1"
2526
],
2627
"yanked_versions": {}
2728
}

0 commit comments

Comments
 (0)