Files
swift-mirror/include/swift/Frontend/CachingUtils.h
T
Ben Langmuir 11312f84de [cas] Introduce a frontend option to write CAS hash to an xattr
With the new option, when doing caching we write the hash that we already
computed for the main output file to an extended attribute (xattr) on the file.
This is equivalent to clang's -fwrite-output-hash-xattr option.

The format of the xattr is
name: com.apple.clang.cas_output_hash
data:
* Null-terminated hash schema name, e.g. llvm.builtin.v2[BLAKE3].
* Hash length (4 bytes, little-endian).
* Hash bytes

rdar://171185394
2026-03-16 15:06:33 -07:00

110 lines
4.4 KiB
C++

//===--- CachingUtils.h -----------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_FRONTEND_CACHINGUTILS_H
#define SWIFT_FRONTEND_CACHINGUTILS_H
#include "swift/Frontend/CASOutputBackends.h"
#include "swift/Frontend/CachedDiagnostics.h"
#include "swift/Frontend/FrontendInputsAndOutputs.h"
#include "swift/Frontend/FrontendOptions.h"
#include "clang/CAS/CASOptions.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/CAS/ActionCache.h"
#include "llvm/CAS/CASReference.h"
#include "llvm/CAS/ObjectStore.h"
#include "llvm/Support/PrefixMapper.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/VirtualOutputBackend.h"
#include <memory>
namespace swift {
class DiagnosticHelper;
/// Create a swift caching output backend that stores the output from
/// compiler into a CAS.
llvm::IntrusiveRefCntPtr<cas::SwiftCASOutputBackend>
createSwiftCachingOutputBackend(
llvm::cas::ObjectStore &CAS, llvm::cas::ActionCache &Cache,
llvm::cas::ObjectRef BaseKey,
const FrontendInputsAndOutputs &InputsAndOutputs,
const FrontendOptions &Opts, FrontendOptions::ActionType Action,
bool WriteOutputHashXAttr);
/// Replay the output of the compilation from cache.
/// Return true if outputs are replayed, false otherwise.
bool replayCachedCompilerOutputs(llvm::cas::ObjectStore &CAS,
llvm::cas::ActionCache &Cache,
llvm::cas::ObjectRef BaseKey,
DiagnosticEngine &Diag,
const FrontendOptions &Opts,
CachingDiagnosticsProcessor &CDP,
bool CacheRemarks, bool UseCASBackend,
bool WriteOutputHashXAttr);
/// Replay the output of the compilation from cache for one input file.
/// Return true if outputs are replayed, false otherwise.
bool replayCachedCompilerOutputsForInput(llvm::cas::ObjectStore &CAS,
llvm::cas::ObjectRef OutputRef,
const InputFile &Input,
unsigned InputIndex,
DiagnosticEngine &Diag,
DiagnosticHelper &DiagHelper,
llvm::vfs::OutputBackend &OutBackend,
const FrontendOptions &Opts,
CachingDiagnosticsProcessor &CDP,
bool CacheRemarks, bool UseCASBackend,
bool WriteOutputHashXAttr);
/// Load the cached compile result from cache.
std::unique_ptr<llvm::MemoryBuffer> loadCachedCompileResultFromCacheKey(
llvm::cas::ObjectStore &CAS, llvm::cas::ActionCache &Cache,
DiagnosticEngine &Diag, llvm::StringRef CacheKey, file_types::ID Type,
llvm::StringRef Filename = "");
llvm::Expected<std::optional<llvm::cas::ObjectProxy>>
loadCachedCompileResultProxy(llvm::cas::ObjectStore &CAS,
llvm::cas::ActionCache &Cache,
llvm::StringRef CacheKey, file_types::ID Type);
llvm::Expected<llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>>
createCASFileSystem(llvm::cas::ObjectStore &CAS,
const std::string &IncludeTreeRoot,
const std::string &IncludeTreeFileList);
std::vector<std::string> remapPathsFromCommandLine(
ArrayRef<std::string> Args,
llvm::function_ref<std::string(StringRef)> RemapCallback);
namespace cas {
class CachedResultLoader {
public:
CachedResultLoader(llvm::cas::ObjectStore &CAS,
llvm::cas::ObjectRef OutputRef)
: CAS(CAS), OutputRef(OutputRef) {}
using CallbackTy =
llvm::function_ref<llvm::Error(file_types::ID, llvm::cas::ObjectRef)>;
/// Replay the cached result.
llvm::Error replay(CallbackTy Callback);
private:
llvm::cas::ObjectStore &CAS;
llvm::cas::ObjectRef OutputRef;
};
} // end namespace cas
} // end namespace swift
#endif