Build libSwiftStaticMirror as a standalone library with minimal required dependencies.

This separates it from `libSwiftScan` and allows us to build this library without building much of the rest of the compiler.

Also refactor `utils/build-parser-lib` into `utils/build-tooling-libs` which builds both SwiftSyntaxParser and SwiftStaticMirror.
This commit is contained in:
Artem Chikin
2022-02-03 14:54:48 -08:00
parent 59f29f09d4
commit d24e15812b
26 changed files with 429 additions and 307 deletions

View File

@@ -1,77 +0,0 @@
//===--- BinaryScan.h - C API for Swift Binary Scanning ---*- C -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
//
// This C API is primarily intended to serve as a "static mirror" library
// for querying Swift type information from binary object files.
//
//===----------------------------------------------------------------------===//
#include "DependencyScanMacros.h"
#include "CommonString.h"
#ifndef SWIFT_C_BINARY_SCAN_H
#define SWIFT_C_BINARY_SCAN_H
SWIFTSCAN_BEGIN_DECLS
//=== Public Binary Scanner Data Types ------------------------------------===//
/// Container of the configuration state for binary static mirror scanning
/// instance
typedef void *swiftscan_static_mirror_t;
/// Opaque container to a conformance type info of a given protocol conformance.
typedef struct swiftscan_conformance_info_s
*swiftscan_static_mirror_conformance_info_t;
typedef struct {
swiftscan_static_mirror_conformance_info_t *conformances;
size_t count;
} swiftscan_static_mirror_conformances_set_t;
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_static_mirror_conformance_info_get_type_name(
swiftscan_static_mirror_conformance_info_t);
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_static_mirror_conformance_info_get_protocol_name(
swiftscan_static_mirror_conformance_info_t);
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_static_mirror_conformance_info_get_mangled_type_name(
swiftscan_static_mirror_conformance_info_t);
SWIFTSCAN_PUBLIC void
swiftscan_static_mirror_conformance_info_dispose(
swiftscan_static_mirror_conformance_info_t);
/// Create an \c swiftscan_static_mirror_t instance.
/// The returned \c swiftscan_static_mirror_t is owned by the caller and must be
/// disposed of using \c swiftscan_static_mirror_dispose .
SWIFTSCAN_PUBLIC swiftscan_static_mirror_t
swiftscan_static_mirror_create(int, const char **, const char *);
SWIFTSCAN_PUBLIC void
swiftscan_static_mirror_dispose(swiftscan_static_mirror_t);
/// Identify and collect all types conforming to any of the protocol names
/// specified as arguments
SWIFTSCAN_PUBLIC swiftscan_static_mirror_conformances_set_t *
swiftscan_static_mirror_conformances_set_create(
swiftscan_static_mirror_t, int, const char **);
SWIFTSCAN_PUBLIC void swiftscan_static_mirror_conformances_set_dispose(
swiftscan_static_mirror_conformances_set_t *);
SWIFTSCAN_END_DECLS
#endif // SWIFT_C_BINARY_SCAN_H

View File

@@ -1,41 +0,0 @@
//===--- CommonString.h - C API for Swift Dependency Scanning ---*- C -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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_C_LIB_SWIFT_SCAN_STRING_H
#define SWIFT_C_LIB_SWIFT_SCAN_STRING_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
SWIFTSCAN_BEGIN_DECLS
//=== String Data Types used by LibSwift Scan ----------------------------===//
/**
* A character string used to pass around dependency scan result metadata.
* Lifetime of the string is strictly tied to the object whose field it
* represents. When the owning object is released, string memory is freed.
*/
typedef struct {
const void *data;
size_t length;
} swiftscan_string_ref_t;
typedef struct {
swiftscan_string_ref_t *strings;
size_t count;
} swiftscan_string_set_t;
SWIFTSCAN_END_DECLS
#endif // SWIFT_C_DEPENDENCY_SCAN_H

View File

@@ -15,15 +15,21 @@
//
//===----------------------------------------------------------------------===//
#include "DependencyScanMacros.h"
#include "CommonString.h"
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
#define SWIFT_C_DEPENDENCY_SCAN_H
#include "DependencyScanMacros.h"
#include "swift-c/CommonString/CommonString.h"
/// The version constants for the SwiftDependencyScan C API.
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
#define SWIFTSCAN_VERSION_MAJOR 0
#define SWIFTSCAN_VERSION_MINOR 2
SWIFTSCAN_BEGIN_DECLS
//=== Public Dependency Scanner Data Types -------------------------------===//
//=== Public Scanner Data Types -------------------------------------------===//
typedef enum {
// This dependency info encodes two ModuleDependencyKind types:
@@ -345,8 +351,6 @@ swiftscan_scanner_cache_load(swiftscan_scanner_t scanner,
SWIFTSCAN_PUBLIC void
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
//=== Experimental compiler invocation operations -------------------------===//
/// An entry point to invoke the compiler via a library call.
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);

View File

@@ -1,32 +0,0 @@
//===--- LibSwiftScan.h - C API for Swift Dependency Scanning ---*- C ---*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
//
// This C API is primarily intended to serve as:
// - Swift Driver's dependency scanning facility
// (https://github.com/apple/swift-driver).
// - An object-file scanning facility for extracting of Swift type information
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_C_SWIFT_SCAN_H
#define SWIFT_C_SWIFT_SCAN_H
/// The version constants for the SwiftDependencyScan C API.
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
#define SWIFTSCAN_VERSION_MAJOR 0
#define SWIFTSCAN_VERSION_MINOR 3
#include "DependencyScan.h"
#include "BinaryScan.h"
#endif // SWIFT_C_SWIFT_SCAN_H

View File

@@ -1,4 +1,4 @@
module _InternalSwiftScan {
header "LibSwiftScan.h"
header "DependencyScan.h"
link "_InternalSwiftScan"
}