Skip to content

Commit 0d5324e

Browse files
Fix catch2 posix signals handling (#3328)
1 parent bd4dce3 commit 0d5324e

File tree

3 files changed

+147
-12
lines changed

3 files changed

+147
-12
lines changed

MODULE.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module(name = "onedal")
1919
bazel_dep(name = "platforms", version = "1.0.0")
2020
bazel_dep(name = "bazel_skylib", version = "1.8.1")
2121
bazel_dep(name = "rules_cc", version = "0.2.0")
22-
bazel_dep(name = "catch2", version = "3.8.1")
2322
bazel_dep(name = "fmt", version = "11.2.0")
2423

2524
declare_onedal_config = use_repo_rule("@onedal//dev/bazel/config:config.bzl", "declare_onedal_config")
@@ -35,6 +34,15 @@ use_repo(extra_toolchain_ext, "onedal_extra_toolchain")
3534
register_toolchains("@{}//:all".format("onedal_extra_toolchain"))
3635

3736

37+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
38+
http_archive(
39+
name = "catch2",
40+
url = "https://github.com/catchorg/Catch2/archive/v3.9.1.tar.gz",
41+
sha256 = "a215c2a723bd7483efd236dc86066842a389cb4e344c61119c978acdf24d39be",
42+
strip_prefix = "Catch2-3.9.1",
43+
build_file = "//dev/bazel/deps:catch2.BUILD",
44+
)
45+
3846
opencl_repo = use_repo_rule("@onedal//dev/bazel/deps:opencl.bzl", "opencl_repo")
3947
opencl_repo(name = "opencl")
4048

cpp/oneapi/dal/test/engine/catch.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,4 @@
2020
// https://github.com/catchorg/Catch2/blob/devel/docs/benchmarks.md
2121
#define CATCH_CONFIG_ENABLE_BENCHMARKING
2222

23-
// CATCH_CONFIG_POSIX_SIGNAL enables handling of POSIX signals.
24-
// For unknown reason user-defined handlers for signals
25-
// (see https://en.wikipedia.org/wiki/C_signal_handling)
26-
// catches SIGSEGV signal when USM pointer is accessed on host.
27-
// To make USM work, we disable signal handling in Catch2.
28-
#define CATCH_CONFIG_NO_POSIX_SIGNALS
29-
30-
// Disables unexpected exceptions handing in Catch2.
31-
// It is easier to debug exception via GDB if there is handler.
32-
#define CATCH_CONFIG_DISABLE_EXCEPTIONS
33-
3423
#include <catch2/catch_all.hpp>

dev/bazel/deps/catch2.BUILD

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#===============================================================================
2+
# Copyright contributors to the oneDAL project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#===============================================================================
16+
17+
# This BUILD.bazel file is based on the original from the Catch2 project.
18+
# Catch2 is licensed under the Boost Software License 1.0 (BSL-1.0).
19+
#
20+
# Original source: https://github.com/catchorg/Catch2
21+
# License text: see LICENSE.MIT in this repository
22+
#
23+
# Modifications for oneDAL:
24+
# - Adjusted substitutions specific for oneDAL (e.g. enabled CATCH_CONFIG_NO_POSIX_SIGNALS)
25+
# - Added comments related to enabling/disabling macros
26+
# - Removed `license()` rule and `package()` directive to avoid dependency on `rules_license`
27+
#
28+
# SPDX-License-Identifier: BSL-1.0
29+
30+
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
31+
32+
# oneDAL verison of catch2 bazel build file
33+
expand_template(
34+
name = "catch_user_config",
35+
out = "catch2/catch_user_config.hpp",
36+
substitutions = {
37+
"@CATCH_CONFIG_CONSOLE_WIDTH@": "80",
38+
"@CATCH_CONFIG_DEFAULT_REPORTER@": "console",
39+
"#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE": "",
40+
"#cmakedefine CATCH_CONFIG_BAZEL_SUPPORT": "#define CATCH_CONFIG_BAZEL_SUPPORT",
41+
"#cmakedefine CATCH_CONFIG_COLOUR_WIN32": "",
42+
"#cmakedefine CATCH_CONFIG_COUNTER": "",
43+
"#cmakedefine CATCH_CONFIG_CPP11_TO_STRING": "",
44+
"#cmakedefine CATCH_CONFIG_CPP17_BYTE": "",
45+
"#cmakedefine CATCH_CONFIG_CPP17_OPTIONAL": "",
46+
"#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW": "",
47+
"#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS": "",
48+
"#cmakedefine CATCH_CONFIG_CPP17_VARIANT": "",
49+
"#cmakedefine CATCH_CONFIG_DEPRECATION_ANNOTATIONS": "",
50+
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER": "",
51+
# Disables unexpected exceptions handing in Catch2.
52+
# It is easier to debug exception via GDB if there is handler.
53+
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS": "#define CATCH_CONFIG_DISABLE_EXCEPTIONS",
54+
"#cmakedefine CATCH_CONFIG_DISABLE_STRINGIFICATION": "",
55+
"#cmakedefine CATCH_CONFIG_DISABLE": "",
56+
"#cmakedefine CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS": "",
57+
"#cmakedefine CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER": "",
58+
"#cmakedefine CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER": "",
59+
"#cmakedefine CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER": "",
60+
"#cmakedefine CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER": "",
61+
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_REDIRECT": "",
62+
"#cmakedefine CATCH_CONFIG_FALLBACK_STRINGIFIER @CATCH_CONFIG_FALLBACK_STRINGIFIER@": "",
63+
"#cmakedefine CATCH_CONFIG_FAST_COMPILE": "",
64+
"#cmakedefine CATCH_CONFIG_GETENV": "",
65+
"#cmakedefine CATCH_CONFIG_GLOBAL_NEXTAFTER": "",
66+
"#cmakedefine CATCH_CONFIG_NO_ANDROID_LOGWRITE": "",
67+
"#cmakedefine CATCH_CONFIG_NO_COLOUR_WIN32": "",
68+
"#cmakedefine CATCH_CONFIG_NO_COUNTER": "",
69+
"#cmakedefine CATCH_CONFIG_NO_CPP11_TO_STRING": "",
70+
"#cmakedefine CATCH_CONFIG_NO_CPP17_BYTE": "",
71+
"#cmakedefine CATCH_CONFIG_NO_CPP17_OPTIONAL": "",
72+
"#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW": "",
73+
"#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS": "",
74+
"#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT": "",
75+
"#cmakedefine CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS": "",
76+
"#cmakedefine CATCH_CONFIG_NO_GETENV": "",
77+
"#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER": "",
78+
# CATCH_CONFIG_POSIX_SIGNAL enables handling of POSIX signals.
79+
# For unknown reason user-defined handlers for signals
80+
# (see https://en.wikipedia.org/wiki/C_signal_handling)
81+
# catches SIGSEGV signal when USM pointer is accessed on host.
82+
# To make USM work, we disable signal handling in Catch2.
83+
"#cmakedefine CATCH_CONFIG_NO_POSIX_SIGNALS": "#define CATCH_CONFIG_NO_POSIX_SIGNALS",
84+
"#cmakedefine CATCH_CONFIG_NO_USE_ASYNC": "",
85+
"#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT": "",
86+
"#cmakedefine CATCH_CONFIG_NO_WCHAR": "",
87+
"#cmakedefine CATCH_CONFIG_NO_WINDOWS_SEH": "",
88+
"#cmakedefine CATCH_CONFIG_NOSTDOUT": "",
89+
"#cmakedefine CATCH_CONFIG_POSIX_SIGNALS": "",
90+
"#cmakedefine CATCH_CONFIG_PREFIX_ALL": "",
91+
"#cmakedefine CATCH_CONFIG_PREFIX_MESSAGES": "",
92+
"#cmakedefine CATCH_CONFIG_SHARED_LIBRARY": "",
93+
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT": "",
94+
"#cmakedefine CATCH_CONFIG_USE_ASYNC": "",
95+
"#cmakedefine CATCH_CONFIG_WCHAR": "",
96+
"#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG": "",
97+
"#cmakedefine CATCH_CONFIG_WINDOWS_SEH": "",
98+
"#cmakedefine CATCH_CONFIG_USE_BUILTIN_CONSTANT_P": "",
99+
"#cmakedefine CATCH_CONFIG_NO_USE_BUILTIN_CONSTANT_P": "",
100+
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "",
101+
"#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "",
102+
},
103+
template = "src/catch2/catch_user_config.hpp.in",
104+
)
105+
106+
# Generated header library, modifies the include prefix to account for
107+
# generation path so that we can include <catch2/catch_user_config.hpp>
108+
# correctly.
109+
cc_library(
110+
name = "catch2_generated",
111+
hdrs = ["catch2/catch_user_config.hpp"],
112+
include_prefix = ".", # to manipulate -I of dependencies
113+
visibility = ["//visibility:public"],
114+
)
115+
116+
# Static library, without main.
117+
cc_library(
118+
name = "catch2",
119+
srcs = glob(
120+
["src/catch2/**/*.cpp"],
121+
exclude = ["src/catch2/internal/catch_main.cpp"],
122+
),
123+
hdrs = glob(["src/catch2/**/*.hpp"]),
124+
includes = ["src/"],
125+
linkstatic = True,
126+
visibility = ["//visibility:public"],
127+
deps = [":catch2_generated"],
128+
)
129+
130+
# Static library, with main.
131+
cc_library(
132+
name = "catch2_main",
133+
srcs = ["src/catch2/internal/catch_main.cpp"],
134+
includes = ["src/"],
135+
linkstatic = True,
136+
visibility = ["//visibility:public"],
137+
deps = [":catch2"],
138+
)

0 commit comments

Comments
 (0)