Skip to content

Commit d24e158

Browse files
committed
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.
1 parent 59f29f0 commit d24e158

26 files changed

+429
-307
lines changed

cmake/modules/SwiftComponents.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@
6464
# Swift code.
6565
# * toolchain-tools -- a subset of tools that we will install to the OSS toolchain.
6666
# * testsuite-tools -- extra tools required to run the Swift testsuite.
67+
# * parser-lib -- Build the syntax parser library used by SwiftSyntax.
68+
# * static-mirror-lib -- Build the static mirror library used by SwiftStaticMirror.
6769
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
6870
# * llvm-toolchain-dev-tools -- install LLVM development tools useful in a shared toolchain
6971
# * dev -- headers and libraries required to use Swift compiler as a library.
7072
set(_SWIFT_DEFINED_COMPONENTS
71-
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
73+
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;static-mirror-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
7274

7375
# The default install components include all of the defined components, except
7476
# for the following exceptions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- CommonString.h - C API for Swift Dependency Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_C_LIB_SWIFT_COMMON_STRING_H
14+
#define SWIFT_C_LIB_SWIFT_COMMON_STRING_H
15+
16+
#include <stdbool.h>
17+
#include <stddef.h>
18+
#include <stdint.h>
19+
20+
/**
21+
* A character string used to pass around dependency scan result metadata.
22+
* Lifetime of the string is strictly tied to the object whose field it
23+
* represents. When the owning object is released, string memory is freed.
24+
*/
25+
typedef struct {
26+
const void *data;
27+
size_t length;
28+
} swiftscan_string_ref_t;
29+
30+
typedef struct {
31+
swiftscan_string_ref_t *strings;
32+
size_t count;
33+
} swiftscan_string_set_t;
34+
35+
#endif // SWIFT_C_LIB_SWIFT_COMMON_STRING_H

include/swift-c/DependencyScan/BinaryScan.h

-77
This file was deleted.

include/swift-c/DependencyScan/CommonString.h

-41
This file was deleted.

include/swift-c/DependencyScan/DependencyScan.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18-
#include "DependencyScanMacros.h"
19-
#include "CommonString.h"
20-
2118
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
2219
#define SWIFT_C_DEPENDENCY_SCAN_H
2320

21+
#include "DependencyScanMacros.h"
22+
#include "swift-c/CommonString/CommonString.h"
23+
24+
/// The version constants for the SwiftDependencyScan C API.
25+
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
26+
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
27+
#define SWIFTSCAN_VERSION_MAJOR 0
28+
#define SWIFTSCAN_VERSION_MINOR 2
29+
2430
SWIFTSCAN_BEGIN_DECLS
2531

26-
//=== Public Dependency Scanner Data Types -------------------------------===//
32+
//=== Public Scanner Data Types -------------------------------------------===//
2733

2834
typedef enum {
2935
// This dependency info encodes two ModuleDependencyKind types:
@@ -345,8 +351,6 @@ swiftscan_scanner_cache_load(swiftscan_scanner_t scanner,
345351
SWIFTSCAN_PUBLIC void
346352
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
347353

348-
//=== Experimental compiler invocation operations -------------------------===//
349-
350354
/// An entry point to invoke the compiler via a library call.
351355
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
352356

include/swift-c/DependencyScan/LibSwiftScan.h

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module _InternalSwiftScan {
2-
header "LibSwiftScan.h"
2+
header "DependencyScan.h"
33
link "_InternalSwiftScan"
44
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===--- BinaryScan.h - C API for Swift Binary Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This C API is primarily intended to serve as a "static mirror" library
14+
// for querying Swift type information from binary object files.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#include "StaticMirrorMacros.h"
19+
#include "swift-c/CommonString/CommonString.h"
20+
21+
#ifndef SWIFT_C_BINARY_SCAN_H
22+
#define SWIFT_C_BINARY_SCAN_H
23+
24+
/// The version constants for the SwiftStaticMirror C API.
25+
/// SWIFTSTATICMIRROR_VERSION_MINOR should increase when there are API additions.
26+
/// SWIFTSTATICMIRROR_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
27+
#define SWIFTSTATICMIRROR_VERSION_MAJOR 0
28+
#define SWIFTSTATICMIRROR_VERSION_MINOR 1
29+
30+
SWIFTSTATICMIRROR_BEGIN_DECLS
31+
32+
//=== Public Binary Scanner Data Types ------------------------------------===//
33+
34+
typedef swiftscan_string_ref_t swift_static_mirror_string_ref_t;
35+
typedef swiftscan_string_set_t swift_static_mirror_string_set_t;
36+
37+
/// Container of the configuration state for binary static mirror scanning
38+
/// instance
39+
typedef void *swift_static_mirror_t;
40+
41+
/// Opaque container to a conformance type info of a given protocol conformance.
42+
typedef struct swift_static_mirror_conformance_info_s
43+
*swift_static_mirror_conformance_info_t;
44+
45+
typedef struct {
46+
swift_static_mirror_conformance_info_t *conformances;
47+
size_t count;
48+
} swift_static_mirror_conformances_set_t;
49+
50+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
51+
swift_static_mirror_conformance_info_get_type_name(
52+
swift_static_mirror_conformance_info_t);
53+
54+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
55+
swift_static_mirror_conformance_info_get_protocol_name(
56+
swift_static_mirror_conformance_info_t);
57+
58+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
59+
swift_static_mirror_conformance_info_get_mangled_type_name(
60+
swift_static_mirror_conformance_info_t);
61+
62+
SWIFTSTATICMIRROR_PUBLIC void
63+
swift_static_mirror_conformance_info_dispose(
64+
swift_static_mirror_conformance_info_t);
65+
66+
/// Create an \c swift_static_mirror_t instance.
67+
/// The returned \c swift_static_mirror_t is owned by the caller and must be
68+
/// disposed of using \c swift_static_mirror_dispose .
69+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_t
70+
swift_static_mirror_create(int, const char **, const char *);
71+
72+
SWIFTSTATICMIRROR_PUBLIC void
73+
swift_static_mirror_dispose(swift_static_mirror_t);
74+
75+
/// Identify and collect all types conforming to any of the protocol names
76+
/// specified as arguments
77+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_conformances_set_t *
78+
swift_static_mirror_conformances_set_create(
79+
swift_static_mirror_t, int, const char **);
80+
81+
SWIFTSTATICMIRROR_PUBLIC void swift_static_mirror_conformances_set_dispose(
82+
swift_static_mirror_conformances_set_t *);
83+
84+
SWIFTSTATICMIRROR_END_DECLS
85+
86+
#endif // SWIFT_C_BINARY_SCAN_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- DependencyScanMacros.h - Swift Dependency Scanning Macros -*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifdef __cplusplus
14+
# define SWIFTSTATICMIRROR_BEGIN_DECLS extern "C" {
15+
# define SWIFTSTATICMIRROR_END_DECLS }
16+
#else
17+
# define SWIFTSTATICMIRROR_BEGIN_DECLS
18+
# define SWIFTSTATICMIRROR_END_DECLS
19+
#endif
20+
21+
#ifndef SWIFTSTATICMIRROR_PUBLIC
22+
# ifdef _WIN32
23+
# ifdef libStaticMirror_EXPORTS
24+
# define SWIFTSTATICMIRROR_PUBLIC __declspec(dllexport)
25+
# else
26+
# define SWIFTSTATICMIRROR_PUBLIC __declspec(dllimport)
27+
# endif
28+
# else
29+
# define SWIFTSTATICMIRROR_PUBLIC
30+
# endif
31+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module _InternalStaticMirror {
2+
header "BinaryScan.h"
3+
link "_InternalStaticMirror"
4+
}

include/swift/DependencyScan/StringUtils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift-c/DependencyScan/DependencyScan.h"
13+
#include "swift-c/CommonString/CommonString.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include "llvm/ADT/StringSet.h"
1616
#include <string>
1717
#include <vector>
1818

1919
//=== Private Utility Functions--------------------------------------------===//
2020
namespace swift {
21-
namespace dependencies {
21+
namespace c_string_utils {
2222

2323
/// Create null string
2424
swiftscan_string_ref_t create_null();

0 commit comments

Comments
 (0)