From ab94ddbd0e11403ecc7f60dc737fd7cb4037acfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20Miks=CC=8Ca?= Date: Sun, 31 Aug 2025 10:53:41 +0200 Subject: [PATCH] avoid `-lpthread` link option when building with emscripten without threads - having this flag causes emscripten to generate binary with pthread support, which is not compatible with browsers that do not support pthreads or with web pages that do not enable pthread support --- BUILD.bazel | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BUILD.bazel b/BUILD.bazel index 3ca5735db0..1de1cea867 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -56,6 +56,16 @@ config_setting( constraint_values = ["@platforms//os:openbsd"], ) +config_setting( + name = "emscripten_without_threads", + constraint_values = [ + "@platforms//os:emscripten", + ], + values = { + "features": "-use_pthreads", + }, +) + # NOTE: Fuchsia is not an officially supported platform. config_setting( name = "fuchsia", @@ -111,10 +121,12 @@ cc_library( copts = select({ ":qnx": [], ":windows": [], + ":emscripten_without_threads": [], "//conditions:default": ["-pthread"], }), defines = select({ ":has_absl": ["GTEST_HAS_ABSL=1"], + ":emscripten_without_threads": ["GTEST_HAS_PTHREAD=0"], "//conditions:default": [], }), features = select({ @@ -138,6 +150,7 @@ cc_library( "-lm", "-pthread", ], + ":emscripten_without_threads": [], "//conditions:default": ["-pthread"], }), deps = select({