Skip to content

Commit 0ad585c

Browse files
authored
Merge pull request github#11860 from github/redsun82/swift-clang-14
Swift: make compilation with newer STL possible
2 parents 54c780b + 2fb5621 commit 0ad585c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

swift/extractor/infra/file/BUILD.bazel

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ load("//swift:rules.bzl", "swift_cc_library")
33
swift_cc_library(
44
name = "file",
55
srcs = glob(["*.cpp"]),
6-
hdrs = glob(["*.h"]),
6+
hdrs = glob(["*.h"]) + [":path_hash_workaround"],
77
visibility = ["//swift:__subpackages__"],
88
deps = ["@picosha2"],
99
)
10+
11+
genrule(
12+
name = "path_hash_workaround",
13+
srcs = [
14+
"PathHash.h.workaround",
15+
"PathHash.h.fixed",
16+
],
17+
outs = ["PathHash.h"],
18+
# see if https://cplusplus.github.io/LWG/issue3657 is fixed with the current compiler or not
19+
# if fixed, PathHash.h.workaround will not compile
20+
cmd = "\n".join([
21+
"if clang -c -x c++ -std=c++17 -Wno-pragma-once-outside-header \\",
22+
" $(rootpath PathHash.h.workaround) -o /dev/null &> /dev/null; then",
23+
" cp $(rootpath PathHash.h.workaround) $@",
24+
"else",
25+
" cp $(rootpath PathHash.h.fixed) $@",
26+
"fi",
27+
]),
28+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
#include <functional>

swift/extractor/infra/file/PathHash.h renamed to swift/extractor/infra/file/PathHash.h.workaround

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
// but it works, and this is recognized as a defect of the standard.
99
// Using a non-standard Hasher type would be a huge pain, as the automatic hash implementation of
1010
// std::variant would not kick in (we use std::filesystem::path in a variant used as a map key).
11-
// We can reconsider when the fix to the above issue hits clang, which might require a version check
12-
// here
1311
namespace std {
1412
template <>
15-
struct std::hash<std::filesystem::path> {
16-
std::size_t operator()(const std::filesystem::path& path) const { return hash_value(path); }
13+
struct hash<filesystem::path> {
14+
size_t operator()(const filesystem::path& path) const { return hash_value(path); }
1715
};
16+
1817
} // namespace std

0 commit comments

Comments
 (0)