Skip to content

Commit b1f99b8

Browse files
[CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS. This allows swift compilation caching using CAS.
1 parent 2db4a03 commit b1f99b8

34 files changed

+2670
-297
lines changed

include/swift-c/DependencyScan/DependencyScan.h

+57-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
2626
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
2727
#define SWIFTSCAN_VERSION_MAJOR 0
28-
#define SWIFTSCAN_VERSION_MINOR 3
28+
#define SWIFTSCAN_VERSION_MINOR 4
2929

3030
SWIFTSCAN_BEGIN_DECLS
3131

@@ -139,6 +139,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
139139
swiftscan_swift_textual_detail_get_command_line(
140140
swiftscan_module_details_t details);
141141

142+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
143+
swiftscan_swift_textual_detail_get_bridging_pch_command_line(
144+
swiftscan_module_details_t details);
145+
142146
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
143147
swiftscan_swift_textual_detail_get_extra_pcm_args(
144148
swiftscan_module_details_t details);
@@ -154,6 +158,14 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
154158
swiftscan_swift_textual_detail_get_swift_overlay_dependencies(
155159
swiftscan_module_details_t details);
156160

161+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
162+
swiftscan_swift_textual_detail_get_cas_fs_root_id(
163+
swiftscan_module_details_t details);
164+
165+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
166+
swiftscan_swift_textual_detail_get_module_cache_key(
167+
swiftscan_module_details_t details);
168+
157169
//=== Swift Binary Module Details query APIs ------------------------------===//
158170

159171
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
@@ -172,6 +184,10 @@ SWIFTSCAN_PUBLIC bool
172184
swiftscan_swift_binary_detail_get_is_framework(
173185
swiftscan_module_details_t details);
174186

187+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
188+
swiftscan_swift_binary_detail_get_module_cache_key(
189+
swiftscan_module_details_t details);
190+
175191
//=== Swift Placeholder Module Details query APIs -------------------------===//
176192

177193
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
@@ -200,6 +216,12 @@ swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
200216
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
201217
swiftscan_clang_detail_get_captured_pcm_args(swiftscan_module_details_t details);
202218

219+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
220+
swiftscan_clang_detail_get_cas_fs_root_id(swiftscan_module_details_t details);
221+
222+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
223+
swiftscan_clang_detail_get_module_cache_key(swiftscan_module_details_t details);
224+
203225
//=== Batch Scan Input Functions ------------------------------------------===//
204226

205227
/// Create an \c swiftscan_batch_scan_input_t instance.
@@ -402,6 +424,40 @@ swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
402424
/// An entry point to invoke the compiler via a library call.
403425
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
404426

427+
//=== Scanner CAS Operations ----------------------------------------------===//
428+
429+
/// Opaque container for a CAS instance that includes both ObjectStore and
430+
/// ActionCache.
431+
typedef struct swiftscan_cas_s *swiftscan_cas_t;
432+
433+
/// Enum types for output types for cache key computation.
434+
/// TODO: complete the list.
435+
typedef enum {
436+
SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0,
437+
SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1,
438+
SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2,
439+
SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIAVEINTERFACE = 3,
440+
SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4,
441+
SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5
442+
} swiftscan_output_kind_t;
443+
444+
/// Create a \c cas instance that points to path.
445+
SWIFTSCAN_PUBLIC swiftscan_cas_t swiftscan_cas_create(const char *path);
446+
447+
/// Dispose the \c cas instance.
448+
SWIFTSCAN_PUBLIC void swiftscan_cas_dispose(swiftscan_cas_t cas);
449+
450+
/// Store content into CAS. Return \c CASID as string.
451+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t swiftscan_cas_store(swiftscan_cas_t cas,
452+
uint8_t *data,
453+
unsigned size);
454+
455+
/// Compute \c CacheKey for output of \c kind from the compiler invocation \c
456+
/// argc and \c argv with \c input. Return \c CacheKey as string.
457+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
458+
swiftscan_compute_cache_key(swiftscan_cas_t cas, int argc, const char **argv,
459+
const char *input, swiftscan_output_kind_t kind);
460+
405461
//===----------------------------------------------------------------------===//
406462

407463
SWIFTSCAN_END_DECLS

0 commit comments

Comments
 (0)