|
25 | 25 | /// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
|
26 | 26 | /// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
|
27 | 27 | #define SWIFTSCAN_VERSION_MAJOR 0
|
28 |
| -#define SWIFTSCAN_VERSION_MINOR 5 |
| 28 | +#define SWIFTSCAN_VERSION_MINOR 6 |
29 | 29 |
|
30 | 30 | SWIFTSCAN_BEGIN_DECLS
|
31 | 31 |
|
@@ -441,6 +441,52 @@ typedef struct swiftscan_cas_options_s *swiftscan_cas_options_t;
|
441 | 441 | /// ActionCache.
|
442 | 442 | typedef struct swiftscan_cas_s *swiftscan_cas_t;
|
443 | 443 |
|
| 444 | +/// Opaque container for a cached compilation. |
| 445 | +typedef struct swiftscan_cached_compilation_s *swiftscan_cached_compilation_t; |
| 446 | + |
| 447 | +/// Opaque type for a cache replay instance. |
| 448 | +typedef struct swiftscan_cache_replay_instance_s |
| 449 | + *swiftscan_cache_replay_instance_t; |
| 450 | + |
| 451 | +/// Opaque type for a cancellation token for async cache operations. |
| 452 | +typedef struct swiftscan_cache_cancellation_token_s |
| 453 | + *swiftscan_cache_cancellation_token_t; |
| 454 | + |
| 455 | +/// Enum types for output types for cache key computation. |
| 456 | +/// List should contain all the output file types, including supplemententary |
| 457 | +/// outputs, except diagnostics outputs, which are covered by cached diagnostic |
| 458 | +/// entry. |
| 459 | +typedef enum { |
| 460 | + SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0, |
| 461 | + SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1, |
| 462 | + SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2, |
| 463 | + SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIVATEINTERFACE = 3, |
| 464 | + SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4, |
| 465 | + SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5, |
| 466 | + SWIFTSCAN_OUTPUT_TYPE_CLANG_HEADER = 6, |
| 467 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_SOURCE_INFO = 7, |
| 468 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_MODULE_DOC = 8, |
| 469 | + SWIFTSCAN_OUTPUT_TYPE_DEPENDENCIES = 9, |
| 470 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_DEPS = 10, |
| 471 | + SWIFTSCAN_OUTPUT_TYPE_MODULE_TRACE = 11, |
| 472 | + SWIFTSCAN_OUTPUT_TYPE_TBD = 12, |
| 473 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_MODULE_SUMMARY = 13, |
| 474 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_ABI_DESCRIPTOR = 14, |
| 475 | + SWIFTSCAN_OUTPUT_TYPE_SWIFT_API_DESCRIPTOR = 15, |
| 476 | + SWIFTSCAN_OUTPUT_TYPE_CONST_VALUE = 16, |
| 477 | + SWIFTSCAN_OUTPUT_TYPE_MODULE_SEMANTIC_INFO = 17, |
| 478 | + SWIFTSCAN_OUTPUT_TYPE_YAML_OPT_RECORD = 18, |
| 479 | + SWIFTSCAN_OUTPUT_TYPE_BITSTREAM_OPT_RECORD = 19, |
| 480 | + SWIFTSCAN_OUTPUT_TYPE_CACHED_DIAGNOSTICS = 20 |
| 481 | +} swiftscan_output_kind_t; |
| 482 | + |
| 483 | +/// Enum types for cache result lookup or replay. |
| 484 | +typedef enum { |
| 485 | + SWIFTSCAN_CACHE_RESULT_SUCCESS = 0, |
| 486 | + SWIFTSCAN_CACHE_RESULT_NOT_FOUND = 1, |
| 487 | + SWIFTSCAN_CACHE_RESULT_ERROR = 2, |
| 488 | +} swiftscan_cache_result_t; |
| 489 | + |
444 | 490 | /// Create a \c CASOptions for creating CAS inside scanner specified.
|
445 | 491 | SWIFTSCAN_PUBLIC swiftscan_cas_options_t swiftscan_cas_options_create(void);
|
446 | 492 |
|
@@ -492,6 +538,129 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
|
492 | 538 | swiftscan_cache_compute_key(swiftscan_cas_t cas, int argc, const char **argv,
|
493 | 539 | const char *input, swiftscan_string_ref_t *error);
|
494 | 540 |
|
| 541 | +/// Query the result of the compilation using the output cache key. \c globally |
| 542 | +/// suggests if the lookup should check remote cache if such operation exists. |
| 543 | +/// Returns the CachedCompilation of the result if found, or nullptr if output |
| 544 | +/// is not found or an error occurs. When an error occurs, the error message is |
| 545 | +/// returned via \c error parameter and its caller needs to free the message |
| 546 | +/// using `swiftscan_string_dispose`. The returned CachedCompilation needs to be |
| 547 | +/// freed via `swiftscan_cached_compilation_dispose`. |
| 548 | +SWIFTSCAN_PUBLIC swiftscan_cached_compilation_t |
| 549 | +swiftscan_cache_query(swiftscan_cas_t cas, const char *key, bool globally, |
| 550 | + swiftscan_string_ref_t *error); |
| 551 | + |
| 552 | +/// Async version of `swiftscan_cache_query` where result is returned via |
| 553 | +/// callback. Both cache_result enum and CachedCompilation will be provided to |
| 554 | +/// callback. \c ctx is an opaque value that passed to the callback and \c |
| 555 | +/// swiftscan_cache_cancellation_token_t will return an token that can be used |
| 556 | +/// to cancel the async operation. The token needs to be freed by caller using |
| 557 | +/// `swiftscan_cache_cancellation_token_dispose`. |
| 558 | +SWIFTSCAN_PUBLIC void swiftscan_cache_query_async( |
| 559 | + swiftscan_cas_t cas, const char *key, bool globally, void *ctx, |
| 560 | + void (*callback)(void *ctx, swiftscan_cache_result_t, |
| 561 | + swiftscan_cached_compilation_t, |
| 562 | + swiftscan_string_ref_t error), |
| 563 | + swiftscan_cache_cancellation_token_t *); |
| 564 | + |
| 565 | +/// Dispose a CachedCompilation. |
| 566 | +SWIFTSCAN_PUBLIC void |
| 567 | + swiftscan_cached_compilation_dispose(swiftscan_cached_compilation_t); |
| 568 | + |
| 569 | +/// Download and materialized the CASObject referenced by the CASID in the local |
| 570 | +/// CAS if needed from a remote CAS. |
| 571 | +/// If the return value is SWIFTSCAN_CACHE_RESULT_ERROR, the error message is |
| 572 | +/// returned via \c error parameter and its caller needs to free the message |
| 573 | +/// using `swiftscan_string_dispose`. |
| 574 | +SWIFTSCAN_PUBLIC swiftscan_cache_result_t |
| 575 | +swiftscan_cache_load_object(swiftscan_cas_t cas, swiftscan_cached_compilation_t, |
| 576 | + swiftscan_string_ref_t *error); |
| 577 | + |
| 578 | +/// Async version of `swiftscan_cache_load_object` where result is returned via |
| 579 | +/// callback. \c ctx is an opaque value that passed to the callback and |
| 580 | +/// \c swiftscan_cache_cancellation_token_t will return an token that can be |
| 581 | +/// used to cancel the async operation. The token needs to be freed by caller |
| 582 | +/// using `swiftscan_cache_cancellation_token_dispose`. |
| 583 | +SWIFTSCAN_PUBLIC void swiftscan_cache_load_object_async( |
| 584 | + swiftscan_cas_t cas, swiftscan_cached_compilation_t, void *ctx, |
| 585 | + void (*callback)(void *ctx, swiftscan_cache_result_t, |
| 586 | + swiftscan_string_ref_t error), |
| 587 | + swiftscan_cache_cancellation_token_t *); |
| 588 | + |
| 589 | +/// Check if CachedCompilation is materialized locally and can be accessed |
| 590 | +/// without downloading. |
| 591 | +SWIFTSCAN_PUBLIC bool |
| 592 | + swiftscan_cache_compilation_is_loaded(swiftscan_cached_compilation_t); |
| 593 | + |
| 594 | +/// Query the number of outputs from a cached compilation. The cached |
| 595 | +/// compilation needs to be loaded, otherwise will return error. The error |
| 596 | +/// message is returned via \c error parameter and its caller needs to free the |
| 597 | +/// message using `swiftscan_string_dispose`. |
| 598 | +SWIFTSCAN_PUBLIC unsigned |
| 599 | +swiftscan_cache_get_num_cached_outputs(swiftscan_cached_compilation_t, |
| 600 | + swiftscan_string_ref_t *error); |
| 601 | + |
| 602 | +/// Query if the kind of otuput exists in a cached compilation. The cached |
| 603 | +/// compilation needs to be loaded, otherwise will return error. The error |
| 604 | +/// message is returned via \c error parameter and its caller needs to free the |
| 605 | +/// message using `swiftscan_string_dispose`. |
| 606 | +SWIFTSCAN_PUBLIC bool |
| 607 | +swiftscan_cache_compilation_has_output_kind(swiftscan_cached_compilation_t, |
| 608 | + swiftscan_output_kind_t, |
| 609 | + swiftscan_string_ref_t *error); |
| 610 | + |
| 611 | +/// Make the cache compilation available globally. \c callback will be called |
| 612 | +/// on completion. |
| 613 | +/// \c swiftscan_cache_cancellation_token_t will return an token that can be |
| 614 | +/// used to cancel the async operation. The token needs to be freed by caller |
| 615 | +/// using `swiftscan_cache_cancellation_token_dispose`. |
| 616 | +SWIFTSCAN_PUBLIC void swiftscan_cache_make_global_async( |
| 617 | + swiftscan_cas_t cas, const char *key, void *ctx, |
| 618 | + void (*callback)(void *ctx, swiftscan_string_ref_t error), |
| 619 | + swiftscan_cache_cancellation_token_t *); |
| 620 | + |
| 621 | +/// Cancel the async cache action that is associated with token. |
| 622 | +SWIFTSCAN_PUBLIC void |
| 623 | + swiftscan_cache_action_cancel(swiftscan_cache_cancellation_token_t); |
| 624 | + |
| 625 | +/// Dispose the cancellation token. |
| 626 | +SWIFTSCAN_PUBLIC void swiftscan_cache_cancellation_token_dispose( |
| 627 | + swiftscan_cache_cancellation_token_t); |
| 628 | + |
| 629 | +/// Create a swift cached compilation replay instance with its command-line |
| 630 | +/// invocation. Return nullptr when errors occurs and the error message is |
| 631 | +/// returned via \c error parameter and its caller needs to free the message |
| 632 | +/// using `swiftscan_string_dispose`. |
| 633 | +SWIFTSCAN_PUBLIC swiftscan_cache_replay_instance_t |
| 634 | +swiftscan_cache_create_replay_instance(int argc, const char **argv, |
| 635 | + swiftscan_string_ref_t *error); |
| 636 | + |
| 637 | +/// Dispose swift cached compilation replay instance. |
| 638 | +SWIFTSCAN_PUBLIC void |
| 639 | + swiftscan_cache_replay_instance_dispose(swiftscan_cache_replay_instance_t); |
| 640 | + |
| 641 | +/// Replay the cached compilation using cached compliation replay instance. |
| 642 | +/// If the return value is SWIFTSCAN_CACHE_RESULT_ERROR, the error message is |
| 643 | +/// returned via \c error parameter and its caller needs to free the message |
| 644 | +/// using `swiftscan_string_dispose`. |
| 645 | +SWIFTSCAN_PUBLIC swiftscan_cache_result_t swiftscan_cache_replay_compilation( |
| 646 | + swiftscan_cas_t cas, swiftscan_cache_replay_instance_t, |
| 647 | + swiftscan_cached_compilation_t, swiftscan_string_ref_t *error); |
| 648 | + |
| 649 | +/// Async replay the cached compilation. Callback function will be provided |
| 650 | +/// by the cache replay result, and its stdout, stderr, and any error message. |
| 651 | +/// \c ctx is an opaque value that passed to the callback and |
| 652 | +/// \c swiftscan_cache_cancellation_token_t will return an token that can be |
| 653 | +/// used to cancel the async operation. The token needs to be freed by caller |
| 654 | +/// using `swiftscan_cache_cancellation_token_dispose`. |
| 655 | +SWIFTSCAN_PUBLIC void swiftscan_cache_replay_compilation_async( |
| 656 | + swiftscan_cas_t cas, swiftscan_cache_replay_instance_t, |
| 657 | + swiftscan_cached_compilation_t, void *ctx, |
| 658 | + void (*callback)(void *ctx, swiftscan_cache_result_t, |
| 659 | + swiftscan_string_ref_t std_out, |
| 660 | + swiftscan_string_ref_t std_err, |
| 661 | + swiftscan_string_ref_t error), |
| 662 | + swiftscan_cache_cancellation_token_t *); |
| 663 | + |
495 | 664 | //===----------------------------------------------------------------------===//
|
496 | 665 |
|
497 | 666 | SWIFTSCAN_END_DECLS
|
|
0 commit comments