|
| 1 | +//===--- DependencyScan.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 | +// This C API is primarily intended to serve as the Swift Driver's |
| 14 | +// dependency scanning facility (https://github.com/apple/swift-driver). |
| 15 | +// |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +#ifndef SWIFT_C_DEPENDENCY_SCAN_H |
| 19 | +#define SWIFT_C_DEPENDENCY_SCAN_H |
| 20 | + |
| 21 | +#include "DependencyScanMacros.h" |
| 22 | +#include "DSString.h" |
| 23 | +#include <stdbool.h> |
| 24 | +#include <stddef.h> |
| 25 | +#include <stdint.h> |
| 26 | + |
| 27 | +/// The version constants for the SwiftDependencyScan C API. |
| 28 | +/// DEPSCAN_VERSION_MINOR should increase when there are API additions. |
| 29 | +/// DEPSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes. |
| 30 | +#define DEPSCAN_VERSION_MAJOR 0 |
| 31 | +#define DEPSCAN_VERSION_MINOR 1 |
| 32 | + |
| 33 | +DEPSCAN_BEGIN_DECLS |
| 34 | + |
| 35 | +//=== Scanner Data Types --------------------------------------------------===// |
| 36 | + |
| 37 | +typedef enum { |
| 38 | + DEPSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0, |
| 39 | + DEPSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1, |
| 40 | + DEPSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2, |
| 41 | + DEPSCAN_DEPENDENCY_INFO_CLANG = 3 |
| 42 | +} depscan_dependency_info_kind_t; |
| 43 | + |
| 44 | +/// Swift modules to be built from a module interface, may have a bridging |
| 45 | +/// header. |
| 46 | +typedef struct { |
| 47 | + /// The module interface from which this module was built, if any. |
| 48 | + ds_string_t module_interface_path; |
| 49 | + |
| 50 | + /// The paths of potentially ready-to-use compiled modules for the interface. |
| 51 | + ds_string_set_t* compiled_module_candidates; |
| 52 | + |
| 53 | + /// The bridging header, if any. |
| 54 | + ds_string_t bridging_header_path; |
| 55 | + |
| 56 | + /// The source files referenced by the bridging header. |
| 57 | + ds_string_set_t* bridging_source_files; |
| 58 | + |
| 59 | + /// (Clang) modules on which the bridging header depends. |
| 60 | + ds_string_set_t* bridging_module_dependencies; |
| 61 | + |
| 62 | + /// Options to the compile command required to build this module interface |
| 63 | + ds_string_set_t* command_line; |
| 64 | + |
| 65 | + /// To build a PCM to be used by this Swift module, we need to append these |
| 66 | + /// arguments to the generic PCM build arguments reported from the dependency |
| 67 | + /// graph. |
| 68 | + ds_string_set_t* extra_pcm_args; |
| 69 | + |
| 70 | + /// The hash value that will be used for the generated module |
| 71 | + ds_string_t context_hash; |
| 72 | + |
| 73 | + /// A flag to indicate whether or not this module is a framework. |
| 74 | + bool is_framework; |
| 75 | +} depscan_swift_textual_details_t; |
| 76 | + |
| 77 | +/// Swift modules with only a binary module file. |
| 78 | +typedef struct { |
| 79 | + /// The path to the pre-compiled binary module |
| 80 | + ds_string_t compiled_module_path; |
| 81 | + |
| 82 | + /// The path to the .swiftModuleDoc file. |
| 83 | + ds_string_t module_doc_path; |
| 84 | + |
| 85 | + /// The path to the .swiftSourceInfo file. |
| 86 | + ds_string_t module_source_info_path; |
| 87 | +} depscan_swift_binary_details_t; |
| 88 | + |
| 89 | +/// Swift placeholder modules carry additional details that specify their |
| 90 | +/// module doc path and source info paths. |
| 91 | +typedef struct { |
| 92 | + /// The path to the pre-compiled binary module |
| 93 | + ds_string_t compiled_module_path; |
| 94 | + |
| 95 | + /// The path to the .swiftModuleDoc file. |
| 96 | + ds_string_t module_doc_path; |
| 97 | + |
| 98 | + /// The path to the .swiftSourceInfo file. |
| 99 | + ds_string_t module_source_info_path; |
| 100 | +} depscan_swift_placeholder_details_t; |
| 101 | + |
| 102 | +/// Clang modules are built from a module map file. |
| 103 | +typedef struct { |
| 104 | + /// The path to the module map used to build this module. |
| 105 | + ds_string_t module_map_path; |
| 106 | + |
| 107 | + /// clang-generated context hash |
| 108 | + ds_string_t context_hash; |
| 109 | + |
| 110 | + /// Options to the compile command required to build this clang modulemap |
| 111 | + ds_string_set_t* command_line; |
| 112 | +} depscan_clang_details_t; |
| 113 | + |
| 114 | +typedef struct { |
| 115 | + depscan_dependency_info_kind_t kind; |
| 116 | + union { |
| 117 | + depscan_swift_textual_details_t swift_textual_details; |
| 118 | + depscan_swift_binary_details_t swift_binary_details; |
| 119 | + depscan_swift_placeholder_details_t swift_placeholder_details; |
| 120 | + depscan_clang_details_t clang_details; |
| 121 | + }; |
| 122 | +} depscan_module_details_t; |
| 123 | + |
| 124 | +typedef struct { |
| 125 | + /// The module's name |
| 126 | + /// The format is: |
| 127 | + /// `<module-kind>:<module-name>` |
| 128 | + /// where `module-kind` is one of: |
| 129 | + /// "swiftTextual" |
| 130 | + /// "swiftBinary" |
| 131 | + /// "swiftPlaceholder" |
| 132 | + /// "clang"" |
| 133 | + ds_string_t module_name; |
| 134 | + |
| 135 | + /// The path for the module. |
| 136 | + ds_string_t module_path; |
| 137 | + |
| 138 | + /// The source files used to build this module. |
| 139 | + ds_string_set_t* source_files; |
| 140 | + |
| 141 | + /** |
| 142 | + * The list of modules which this module direct depends on. |
| 143 | + * The format is: |
| 144 | + * `<module-kind>:<module-name>` |
| 145 | + */ |
| 146 | + ds_string_set_t* direct_dependencies; |
| 147 | + |
| 148 | + /// Specific details of a particular kind of module. |
| 149 | + depscan_module_details_t* details; |
| 150 | +} depscan_dependency_info_t; |
| 151 | + |
| 152 | +/// Full Dependency Graph (Result) |
| 153 | + |
| 154 | +typedef struct { |
| 155 | + int count; |
| 156 | + depscan_dependency_info_t *modules; |
| 157 | +} depscan_dependency_set_t; |
| 158 | + |
| 159 | +typedef struct { |
| 160 | + /// The name of the main module for this dependency graph (root node) |
| 161 | + ds_string_t main_module_name; |
| 162 | + |
| 163 | + /// The complete list of modules discovered |
| 164 | + depscan_dependency_set_t* module_set; |
| 165 | +} depscan_dependency_result_t; |
| 166 | + |
| 167 | +//=== Dependency Result Functions -----------------------------------------===// |
| 168 | + |
| 169 | +DEPSCAN_PUBLIC void |
| 170 | +depscan_dependency_info_details_dispose(depscan_module_details_t *details); |
| 171 | + |
| 172 | +DEPSCAN_PUBLIC void |
| 173 | +depscan_dependency_info_dispose(depscan_dependency_info_t *info); |
| 174 | + |
| 175 | +DEPSCAN_PUBLIC void |
| 176 | +depscan_dependency_set_dispose(depscan_dependency_set_t *set); |
| 177 | + |
| 178 | +DEPSCAN_PUBLIC void |
| 179 | +depscan_dependency_result_dispose(depscan_dependency_result_t *result); |
| 180 | + |
| 181 | +//=== Scanner Functions ---------------------------------------------------===// |
| 182 | + |
| 183 | +/// Container of the configuration state and shared cache for dependency scanning. |
| 184 | +typedef void *depscan_scanner_t; |
| 185 | + |
| 186 | +DEPSCAN_PUBLIC depscan_scanner_t |
| 187 | +depscan_scanner_create(void); |
| 188 | + |
| 189 | +DEPSCAN_PUBLIC void |
| 190 | +depscan_scanner_dispose(depscan_scanner_t); |
| 191 | + |
| 192 | +DEPSCAN_PUBLIC depscan_dependency_result_t* |
| 193 | +depscan_scan_dependencies(depscan_scanner_t* scanner, |
| 194 | + const char *working_directory, |
| 195 | + int argc, |
| 196 | + const char *const *argv); |
| 197 | + |
| 198 | +DEPSCAN_END_DECLS |
| 199 | + |
| 200 | +#endif // SWIFT_C_DEPENDENCY_SCAN_H |
0 commit comments