Merge pull request #11860 from github/redsun82/swift-clang-14

Swift: make compilation with newer STL possible
This commit is contained in:
Paolo Tranquilli
2023-01-10 17:17:56 +01:00
committed by GitHub
3 changed files with 27 additions and 5 deletions

View File

@@ -3,7 +3,26 @@ load("//swift:rules.bzl", "swift_cc_library")
swift_cc_library(
name = "file",
srcs = glob(["*.cpp"]),
hdrs = glob(["*.h"]),
hdrs = glob(["*.h"]) + [":path_hash_workaround"],
visibility = ["//swift:__subpackages__"],
deps = ["@picosha2"],
)
genrule(
name = "path_hash_workaround",
srcs = [
"PathHash.h.workaround",
"PathHash.h.fixed",
],
outs = ["PathHash.h"],
# see if https://cplusplus.github.io/LWG/issue3657 is fixed with the current compiler or not
# if fixed, PathHash.h.workaround will not compile
cmd = "\n".join([
"if clang -c -x c++ -std=c++17 -Wno-pragma-once-outside-header \\",
" $(rootpath PathHash.h.workaround) -o /dev/null &> /dev/null; then",
" cp $(rootpath PathHash.h.workaround) $@",
"else",
" cp $(rootpath PathHash.h.fixed) $@",
"fi",
]),
)

View File

@@ -0,0 +1,4 @@
#pragma once
#include <filesystem>
#include <functional>

View File

@@ -8,11 +8,10 @@
// but it works, and this is recognized as a defect of the standard.
// Using a non-standard Hasher type would be a huge pain, as the automatic hash implementation of
// std::variant would not kick in (we use std::filesystem::path in a variant used as a map key).
// We can reconsider when the fix to the above issue hits clang, which might require a version check
// here
namespace std {
template <>
struct std::hash<std::filesystem::path> {
std::size_t operator()(const std::filesystem::path& path) const { return hash_value(path); }
struct hash<filesystem::path> {
size_t operator()(const filesystem::path& path) const { return hash_value(path); }
};
} // namespace std