This introduces a basic outline of installapi as a clang driver option. It captures relevant information as cc1 args, which are common arguments already passed to the linker to encode into TBD file outputs. This is effectively an upstream for what already exists as `tapi installapi` in Xcode toolchains, but directly in Clang. This patch does not handle any AST traversing on input yet. InstallAPI is broadly an operation that takes a series of header files that represent a single dynamic library and generates a TBD file out of it which represents all the linkable symbols and necessary attributes for statically linking in clients. It is the linkable object in all Apple SDKs and when building dylibs in Xcode. `clang -installapi` also will support verification where it compares all the information recorded for the TBD files against the already built binary, to catch possible mismatches like when a declaration is missing a definition for an exported symbol.
28 lines
1002 B
C++
28 lines
1002 B
C++
//===--- InstallAPI/Context.cpp -------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/InstallAPI/Context.h"
|
|
#include "clang/AST/ASTContext.h"
|
|
#include "llvm/TextAPI/TextAPIWriter.h"
|
|
|
|
using namespace clang;
|
|
using namespace clang::installapi;
|
|
using namespace llvm::MachO;
|
|
|
|
void InstallAPIConsumer::HandleTranslationUnit(ASTContext &Context) {
|
|
if (Context.getDiagnostics().hasErrorOccurred())
|
|
return;
|
|
InterfaceFile IF;
|
|
// Set library attributes captured through cc1 args.
|
|
Target T(Ctx.TargetTriple);
|
|
IF.addTarget(T);
|
|
IF.setFromBinaryAttrs(Ctx.BA, T);
|
|
if (auto Err = TextAPIWriter::writeToStream(*Ctx.OS, IF, Ctx.FT))
|
|
Ctx.Diags->Report(diag::err_cannot_open_file) << Ctx.OutputLoc;
|
|
}
|