mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -64,11 +64,13 @@
|
||||
# Swift code.
|
||||
# * toolchain-tools -- a subset of tools that we will install to the OSS toolchain.
|
||||
# * testsuite-tools -- extra tools required to run the Swift testsuite.
|
||||
# * parser-lib -- Build the syntax parser library used by SwiftSyntax.
|
||||
# * static-mirror-lib -- Build the static mirror library used by SwiftStaticMirror.
|
||||
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
|
||||
# * llvm-toolchain-dev-tools -- install LLVM development tools useful in a shared toolchain
|
||||
# * dev -- headers and libraries required to use Swift compiler as a library.
|
||||
set(_SWIFT_DEFINED_COMPONENTS
|
||||
"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")
|
||||
"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")
|
||||
|
||||
# The default install components include all of the defined components, except
|
||||
# for the following exceptions.
|
||||
|
||||
35
include/swift-c/CommonString/CommonString.h
Normal file
35
include/swift-c/CommonString/CommonString.h
Normal file
@@ -0,0 +1,35 @@
|
||||
//===--- 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_COMMON_STRING_H
|
||||
#define SWIFT_C_LIB_SWIFT_COMMON_STRING_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
#endif // SWIFT_C_LIB_SWIFT_COMMON_STRING_H
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
module _InternalSwiftScan {
|
||||
header "LibSwiftScan.h"
|
||||
header "DependencyScan.h"
|
||||
link "_InternalSwiftScan"
|
||||
}
|
||||
|
||||
86
include/swift-c/StaticMirror/BinaryScan.h
Normal file
86
include/swift-c/StaticMirror/BinaryScan.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//===--- 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 "StaticMirrorMacros.h"
|
||||
#include "swift-c/CommonString/CommonString.h"
|
||||
|
||||
#ifndef SWIFT_C_BINARY_SCAN_H
|
||||
#define SWIFT_C_BINARY_SCAN_H
|
||||
|
||||
/// The version constants for the SwiftStaticMirror C API.
|
||||
/// SWIFTSTATICMIRROR_VERSION_MINOR should increase when there are API additions.
|
||||
/// SWIFTSTATICMIRROR_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
|
||||
#define SWIFTSTATICMIRROR_VERSION_MAJOR 0
|
||||
#define SWIFTSTATICMIRROR_VERSION_MINOR 1
|
||||
|
||||
SWIFTSTATICMIRROR_BEGIN_DECLS
|
||||
|
||||
//=== Public Binary Scanner Data Types ------------------------------------===//
|
||||
|
||||
typedef swiftscan_string_ref_t swift_static_mirror_string_ref_t;
|
||||
typedef swiftscan_string_set_t swift_static_mirror_string_set_t;
|
||||
|
||||
/// Container of the configuration state for binary static mirror scanning
|
||||
/// instance
|
||||
typedef void *swift_static_mirror_t;
|
||||
|
||||
/// Opaque container to a conformance type info of a given protocol conformance.
|
||||
typedef struct swift_static_mirror_conformance_info_s
|
||||
*swift_static_mirror_conformance_info_t;
|
||||
|
||||
typedef struct {
|
||||
swift_static_mirror_conformance_info_t *conformances;
|
||||
size_t count;
|
||||
} swift_static_mirror_conformances_set_t;
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_type_name(
|
||||
swift_static_mirror_conformance_info_t);
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_protocol_name(
|
||||
swift_static_mirror_conformance_info_t);
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_mangled_type_name(
|
||||
swift_static_mirror_conformance_info_t);
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC void
|
||||
swift_static_mirror_conformance_info_dispose(
|
||||
swift_static_mirror_conformance_info_t);
|
||||
|
||||
/// Create an \c swift_static_mirror_t instance.
|
||||
/// The returned \c swift_static_mirror_t is owned by the caller and must be
|
||||
/// disposed of using \c swift_static_mirror_dispose .
|
||||
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_t
|
||||
swift_static_mirror_create(int, const char **, const char *);
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC void
|
||||
swift_static_mirror_dispose(swift_static_mirror_t);
|
||||
|
||||
/// Identify and collect all types conforming to any of the protocol names
|
||||
/// specified as arguments
|
||||
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_conformances_set_t *
|
||||
swift_static_mirror_conformances_set_create(
|
||||
swift_static_mirror_t, int, const char **);
|
||||
|
||||
SWIFTSTATICMIRROR_PUBLIC void swift_static_mirror_conformances_set_dispose(
|
||||
swift_static_mirror_conformances_set_t *);
|
||||
|
||||
SWIFTSTATICMIRROR_END_DECLS
|
||||
|
||||
#endif // SWIFT_C_BINARY_SCAN_H
|
||||
31
include/swift-c/StaticMirror/StaticMirrorMacros.h
Normal file
31
include/swift-c/StaticMirror/StaticMirrorMacros.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//===-- DependencyScanMacros.h - Swift Dependency Scanning Macros -*- 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define SWIFTSTATICMIRROR_BEGIN_DECLS extern "C" {
|
||||
# define SWIFTSTATICMIRROR_END_DECLS }
|
||||
#else
|
||||
# define SWIFTSTATICMIRROR_BEGIN_DECLS
|
||||
# define SWIFTSTATICMIRROR_END_DECLS
|
||||
#endif
|
||||
|
||||
#ifndef SWIFTSTATICMIRROR_PUBLIC
|
||||
# ifdef _WIN32
|
||||
# ifdef libStaticMirror_EXPORTS
|
||||
# define SWIFTSTATICMIRROR_PUBLIC __declspec(dllexport)
|
||||
# else
|
||||
# define SWIFTSTATICMIRROR_PUBLIC __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define SWIFTSTATICMIRROR_PUBLIC
|
||||
# endif
|
||||
#endif
|
||||
4
include/swift-c/StaticMirror/module.modulemap
Normal file
4
include/swift-c/StaticMirror/module.modulemap
Normal file
@@ -0,0 +1,4 @@
|
||||
module _InternalStaticMirror {
|
||||
header "BinaryScan.h"
|
||||
link "_InternalStaticMirror"
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift-c/DependencyScan/DependencyScan.h"
|
||||
#include "swift-c/CommonString/CommonString.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
#include <string>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
//=== Private Utility Functions--------------------------------------------===//
|
||||
namespace swift {
|
||||
namespace dependencies {
|
||||
namespace c_string_utils {
|
||||
|
||||
/// Create null string
|
||||
swiftscan_string_ref_t create_null();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#ifndef SWIFT_C_BINARY_SCAN_IMPL_H
|
||||
#define SWIFT_C_BINARY_SCAN_IMPL_H
|
||||
|
||||
#include "swift-c/DependencyScan/BinaryScan.h"
|
||||
#include "swift-c/StaticMirror/BinaryScan.h"
|
||||
|
||||
namespace swift {
|
||||
namespace static_mirror {
|
||||
@@ -24,10 +24,10 @@ class BinaryScanningTool;
|
||||
}
|
||||
} // namespace swift
|
||||
|
||||
struct swiftscan_conformance_info_s {
|
||||
swiftscan_string_ref_t type_name;
|
||||
swiftscan_string_ref_t mangled_type_name;
|
||||
swiftscan_string_ref_t protocol_name;
|
||||
struct swift_static_mirror_conformance_info_s {
|
||||
swift_static_mirror_string_ref_t type_name;
|
||||
swift_static_mirror_string_ref_t mangled_type_name;
|
||||
swift_static_mirror_string_ref_t protocol_name;
|
||||
};
|
||||
|
||||
#endif // SWIFT_C_BINARY_SCAN_IMPL_H
|
||||
|
||||
@@ -53,7 +53,7 @@ llvm::ErrorOr<swiftscan_string_ref_t> getTargetInfo(ArrayRef<const char *> Comma
|
||||
std::string ResultStr;
|
||||
llvm::raw_string_ostream StrOS(ResultStr);
|
||||
swift::targetinfo::printTargetInfo(Invocation, StrOS);
|
||||
return create_clone(ResultStr.c_str());
|
||||
return c_string_utils::create_clone(ResultStr.c_str());
|
||||
}
|
||||
|
||||
DependencyScanningTool::DependencyScanningTool()
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
using namespace swift;
|
||||
using namespace swift::dependencies;
|
||||
using namespace swift::c_string_utils;
|
||||
using namespace llvm::yaml;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace swift {
|
||||
namespace dependencies {
|
||||
namespace c_string_utils {
|
||||
|
||||
swiftscan_string_ref_t create_null() {
|
||||
swiftscan_string_ref_t str;
|
||||
@@ -64,5 +64,5 @@ swiftscan_string_set_t *create_empty_set() {
|
||||
const char *get_C_string(swiftscan_string_ref_t string) {
|
||||
return static_cast<const char *>(string.data);
|
||||
}
|
||||
} // namespace dependencies
|
||||
} // namespace c_string_utils
|
||||
} // namespace swift
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
add_swift_host_library(swiftStaticMirror STATIC
|
||||
BinaryScanningTool.cpp
|
||||
ObjectFileContext.cpp)
|
||||
ObjectFileContext.cpp
|
||||
LLVM_LINK_COMPONENTS object support)
|
||||
|
||||
target_link_libraries(swiftStaticMirror PRIVATE
|
||||
swiftFrontend
|
||||
swiftReflection)
|
||||
|
||||
@@ -32,6 +32,7 @@ add_swift_tool_subdirectory(swift-llvm-opt)
|
||||
add_swift_tool_subdirectory(swift-ast-script)
|
||||
add_swift_tool_subdirectory(swift-refactor)
|
||||
add_swift_tool_subdirectory(libSwiftScan)
|
||||
add_swift_tool_subdirectory(libStaticMirror)
|
||||
if(SWIFT_BUILD_SYNTAXPARSERLIB)
|
||||
add_swift_tool_subdirectory(libSwiftSyntaxParser)
|
||||
if(SWIFT_INCLUDE_TESTS OR SWIFT_BUILD_SYNTAXPARSERTEST OR SWIFT_INCLUDE_TEST_BINARIES)
|
||||
|
||||
39
tools/libStaticMirror/CMakeLists.txt
Normal file
39
tools/libStaticMirror/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
# Use an 'internal' name, for now
|
||||
set(SWIFT_SCAN_LIB_NAME "_InternalSwiftStaticMirror")
|
||||
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libStaticMirror.exports)
|
||||
|
||||
add_swift_host_library(libStaticMirror SHARED
|
||||
libStaticMirror.cpp
|
||||
c-include-check.c
|
||||
LLVM_LINK_COMPONENTS object support
|
||||
)
|
||||
if(NOT SWIFT_BUILT_STANDALONE AND NOT CMAKE_C_COMPILER_ID MATCHES Clang)
|
||||
add_dependencies(libStaticMirror clang)
|
||||
endif()
|
||||
|
||||
add_dependencies(libStaticMirror
|
||||
swiftStaticMirror)
|
||||
|
||||
target_link_libraries(libStaticMirror PRIVATE
|
||||
swiftStaticMirror
|
||||
swiftReflection)
|
||||
|
||||
set_target_properties(libStaticMirror
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${SWIFT_SCAN_LIB_NAME})
|
||||
|
||||
add_llvm_symbol_exports(libStaticMirror ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
|
||||
# Adds -dead_strip option
|
||||
add_link_opts(libStaticMirror)
|
||||
|
||||
add_dependencies(static-mirror-lib libStaticMirror)
|
||||
swift_install_in_component(TARGETS libStaticMirror
|
||||
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" COMPONENT static-mirror-lib
|
||||
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" COMPONENT static-mirror-lib
|
||||
RUNTIME DESTINATION "bin" COMPONENT static-mirror-lib)
|
||||
swift_install_in_component(DIRECTORY "${SWIFT_MAIN_INCLUDE_DIR}/swift-c/StaticMirror/"
|
||||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SCAN_LIB_NAME}"
|
||||
COMPONENT static-mirror-lib)
|
||||
5
tools/libStaticMirror/c-include-check.c
Normal file
5
tools/libStaticMirror/c-include-check.c
Normal file
@@ -0,0 +1,5 @@
|
||||
// This file serves as a sanity check to ensure that the header is parseable
|
||||
// from C and that no C++ code has sneaked in.
|
||||
|
||||
#include "swift-c/StaticMirror/BinaryScan.h"
|
||||
typedef swift_static_mirror_t _check_mirror_type_exists;
|
||||
138
tools/libStaticMirror/libStaticMirror.cpp
Normal file
138
tools/libStaticMirror/libStaticMirror.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
//===------------ DependencyScanImpl.cpp - Swift Compiler -----------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Implementation of the dependency scanning C API
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Basic/LLVMInitialize.h"
|
||||
#include "swift/StaticMirror/BinaryScanningTool.h"
|
||||
#include "swift/StaticMirror/BinaryScanImpl.h"
|
||||
#include "swift/DependencyScan/StringUtils.h"
|
||||
//#include "swift/Option/Options.h"
|
||||
|
||||
// FIXME: Code duplication with StringUtils.cpp
|
||||
namespace swift {
|
||||
namespace c_string_utils {
|
||||
|
||||
swiftscan_string_ref_t create_null() {
|
||||
swiftscan_string_ref_t str;
|
||||
str.data = nullptr;
|
||||
str.length = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t create_clone(const char *string) {
|
||||
if (!string)
|
||||
return create_null();
|
||||
|
||||
if (string[0] == '\0')
|
||||
return create_null();
|
||||
|
||||
swiftscan_string_ref_t str;
|
||||
str.data = strdup(string);
|
||||
str.length = strlen(string);
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace c_string_utils
|
||||
} // namespace swift
|
||||
|
||||
using namespace swift::static_mirror;
|
||||
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BinaryScanningTool, swift_static_mirror_t)
|
||||
|
||||
//=== Private Cleanup Functions -------------------------------------------===//
|
||||
|
||||
/// Free the given string.
|
||||
void swift_static_mirror_string_dispose(swift_static_mirror_string_ref_t string) {
|
||||
if (string.data)
|
||||
free(const_cast<void *>(string.data));
|
||||
}
|
||||
|
||||
//=== Static Mirror Scan Functions ---------------------------------------===//
|
||||
swift_static_mirror_t
|
||||
swift_static_mirror_create(int num_binaries, const char **binary_paths,
|
||||
const char *arch) {
|
||||
//INITIALIZE_LLVM();
|
||||
std::vector<std::string> inputBinaryPaths;
|
||||
for (unsigned SI = 0, SE = num_binaries; SI < SE; ++SI)
|
||||
inputBinaryPaths.push_back(binary_paths[SI]);
|
||||
|
||||
return wrap(new BinaryScanningTool(inputBinaryPaths, arch));
|
||||
}
|
||||
|
||||
void swift_static_mirror_dispose(
|
||||
swift_static_mirror_t c_static_mirror) {
|
||||
delete unwrap(c_static_mirror);
|
||||
}
|
||||
|
||||
swift_static_mirror_conformances_set_t *
|
||||
swift_static_mirror_conformances_set_create(
|
||||
swift_static_mirror_t static_mirror, int num_protocols,
|
||||
const char **protocol_names) {
|
||||
std::vector<std::string> protocols;
|
||||
for (unsigned SI = 0, SE = num_protocols; SI < SE; ++SI)
|
||||
protocols.push_back(protocol_names[SI]);
|
||||
BinaryScanningTool *scanTool = unwrap(static_mirror);
|
||||
auto scanResult = scanTool->collectConformances(protocols);
|
||||
|
||||
// Bridge to the C interface
|
||||
swift_static_mirror_conformances_set_t *conformanceSet =
|
||||
new swift_static_mirror_conformances_set_t;
|
||||
conformanceSet->count = scanResult.Conformances.size();
|
||||
conformanceSet->conformances =
|
||||
new swift_static_mirror_conformance_info_t[conformanceSet->count];
|
||||
|
||||
size_t idx = 0;
|
||||
for (auto &conformance : scanResult.Conformances) {
|
||||
swift_static_mirror_conformance_info_s *conformanceInfo = new swift_static_mirror_conformance_info_s;
|
||||
conformanceSet->conformances[idx] = conformanceInfo;
|
||||
conformanceInfo->type_name = swift::c_string_utils::create_clone(conformance.TypeName.c_str());
|
||||
conformanceInfo->mangled_type_name = swift::c_string_utils::create_clone(conformance.MangledTypeName.c_str());
|
||||
conformanceInfo->protocol_name = swift::c_string_utils::create_clone(conformance.ProtocolName.c_str());
|
||||
idx += 1;
|
||||
}
|
||||
return conformanceSet;
|
||||
}
|
||||
|
||||
swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_type_name(swift_static_mirror_conformance_info_t info) {
|
||||
return info->type_name;
|
||||
}
|
||||
|
||||
swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_protocol_name(swift_static_mirror_conformance_info_t info) {
|
||||
return info->protocol_name;
|
||||
}
|
||||
|
||||
swift_static_mirror_string_ref_t
|
||||
swift_static_mirror_conformance_info_get_mangled_type_name(swift_static_mirror_conformance_info_t info) {
|
||||
return info->mangled_type_name;
|
||||
}
|
||||
|
||||
void swift_static_mirror_conformance_info_dispose(
|
||||
swift_static_mirror_conformance_info_t info) {
|
||||
swift_static_mirror_conformance_info_s *info_impl = info;
|
||||
swift_static_mirror_string_dispose(info_impl->type_name);
|
||||
swift_static_mirror_string_dispose(info_impl->mangled_type_name);
|
||||
swift_static_mirror_string_dispose(info_impl->protocol_name);
|
||||
}
|
||||
|
||||
void swift_static_mirror_conformances_set_dispose(
|
||||
swift_static_mirror_conformances_set_t *set) {
|
||||
for (size_t i = 0; i < set->count; ++i) {
|
||||
swift_static_mirror_conformance_info_dispose(set->conformances[i]);
|
||||
}
|
||||
delete[] set->conformances;
|
||||
delete set;
|
||||
}
|
||||
8
tools/libStaticMirror/libStaticMirror.exports
Normal file
8
tools/libStaticMirror/libStaticMirror.exports
Normal file
@@ -0,0 +1,8 @@
|
||||
swift_static_mirror_conformances_set_create
|
||||
swift_static_mirror_conformances_set_dispose
|
||||
swift_static_mirror_conformance_info_dispose
|
||||
swift_static_mirror_conformance_info_get_type_name
|
||||
swift_static_mirror_conformance_info_get_protocol_name
|
||||
swift_static_mirror_conformance_info_get_mangled_type_name
|
||||
swift_static_mirror_create
|
||||
swift_static_mirror_dispose
|
||||
@@ -18,25 +18,13 @@
|
||||
#include "swift/DriverTool/DriverTool.h"
|
||||
#include "swift/DependencyScan/DependencyScanImpl.h"
|
||||
#include "swift/DependencyScan/DependencyScanningTool.h"
|
||||
#include "swift/StaticMirror/BinaryScanningTool.h"
|
||||
#include "swift/StaticMirror/BinaryScanImpl.h"
|
||||
#include "swift/DependencyScan/StringUtils.h"
|
||||
#include "swift/Option/Options.h"
|
||||
|
||||
using namespace swift::dependencies;
|
||||
using namespace swift::static_mirror;
|
||||
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DependencyScanningTool, swiftscan_scanner_t)
|
||||
|
||||
inline BinaryScanningTool *unwrap_static_mirror(swiftscan_static_mirror_t P) {
|
||||
return reinterpret_cast<BinaryScanningTool *>(P);
|
||||
}
|
||||
inline swiftscan_static_mirror_t
|
||||
wrap_static_mirror(const BinaryScanningTool *P) {
|
||||
return reinterpret_cast<swiftscan_static_mirror_t>(
|
||||
const_cast<BinaryScanningTool *>(P));
|
||||
}
|
||||
|
||||
//=== Private Cleanup Functions -------------------------------------------===//
|
||||
|
||||
/// Free the given string.
|
||||
@@ -146,7 +134,7 @@ swiftscan_dependency_graph_create(swiftscan_scanner_t scanner,
|
||||
int argc = invocation->argv->count;
|
||||
std::vector<const char *> Compilation;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
|
||||
Compilation.push_back(swift::c_string_utils::get_C_string(invocation->argv->strings[i]));
|
||||
|
||||
// Execute the scan and bridge the result
|
||||
auto ScanResult = ScanningTool->getDependencies(Compilation, {});
|
||||
@@ -164,13 +152,13 @@ swiftscan_batch_scan_result_create(swiftscan_scanner_t scanner,
|
||||
int argc = invocation->argv->count;
|
||||
std::vector<const char *> Compilation;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
|
||||
Compilation.push_back(swift::c_string_utils::get_C_string(invocation->argv->strings[i]));
|
||||
|
||||
std::vector<BatchScanInput> BatchInput;
|
||||
for (size_t i = 0; i < batch_input->count; ++i) {
|
||||
swiftscan_batch_scan_entry_s *Entry = batch_input->modules[i];
|
||||
BatchInput.push_back({get_C_string(Entry->module_name),
|
||||
get_C_string(Entry->arguments),
|
||||
BatchInput.push_back({swift::c_string_utils::get_C_string(Entry->module_name),
|
||||
swift::c_string_utils::get_C_string(Entry->arguments),
|
||||
/*outputPath*/ "", Entry->is_swift});
|
||||
}
|
||||
|
||||
@@ -201,7 +189,7 @@ swiftscan_import_set_create(swiftscan_scanner_t scanner,
|
||||
int argc = invocation->argv->count;
|
||||
std::vector<const char *> Compilation;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
|
||||
Compilation.push_back(swift::c_string_utils::get_C_string(invocation->argv->strings[i]));
|
||||
|
||||
// Execute the scan and bridge the result
|
||||
auto PreScanResult = ScanningTool->getImports(Compilation);
|
||||
@@ -385,12 +373,12 @@ swiftscan_batch_scan_entry_t swiftscan_batch_scan_entry_create() {
|
||||
|
||||
void swiftscan_batch_scan_entry_set_module_name(
|
||||
swiftscan_batch_scan_entry_t entry, const char *name) {
|
||||
entry->module_name = create_clone(name);
|
||||
entry->module_name = swift::c_string_utils::create_clone(name);
|
||||
}
|
||||
|
||||
void swiftscan_batch_scan_entry_set_arguments(
|
||||
swiftscan_batch_scan_entry_t entry, const char *arguments) {
|
||||
entry->arguments = create_clone(arguments);
|
||||
entry->arguments = swift::c_string_utils::create_clone(arguments);
|
||||
}
|
||||
|
||||
void swiftscan_batch_scan_entry_set_is_swift(swiftscan_batch_scan_entry_t entry,
|
||||
@@ -428,13 +416,13 @@ swiftscan_scan_invocation_t swiftscan_scan_invocation_create() {
|
||||
|
||||
void swiftscan_scan_invocation_set_working_directory(
|
||||
swiftscan_scan_invocation_t invocation, const char *working_directory) {
|
||||
invocation->working_directory = create_clone(working_directory);
|
||||
invocation->working_directory = swift::c_string_utils::create_clone(working_directory);
|
||||
}
|
||||
|
||||
SWIFTSCAN_PUBLIC void
|
||||
swiftscan_scan_invocation_set_argv(swiftscan_scan_invocation_t invocation,
|
||||
int argc, const char **argv) {
|
||||
invocation->argv = create_set(argc, argv);
|
||||
invocation->argv = swift::c_string_utils::create_set(argc, argv);
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t swiftscan_scan_invocation_get_working_directory(
|
||||
@@ -518,11 +506,11 @@ swiftscan_compiler_target_info_query(swiftscan_scan_invocation_t invocation) {
|
||||
int argc = invocation->argv->count;
|
||||
std::vector<const char *> Compilation;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
|
||||
Compilation.push_back(swift::c_string_utils::get_C_string(invocation->argv->strings[i]));
|
||||
|
||||
auto TargetInfo = getTargetInfo(Compilation);
|
||||
if (TargetInfo.getError())
|
||||
return create_null();
|
||||
return swift::c_string_utils::create_null();
|
||||
return TargetInfo.get();
|
||||
}
|
||||
|
||||
@@ -535,7 +523,7 @@ swiftscan_compiler_supported_arguments_query() {
|
||||
addFrontendFlagOption(*table, swift::options::OPT_##ID, frontendFlags);
|
||||
#include "swift/Option/Options.inc"
|
||||
#undef OPTION
|
||||
return create_set(frontendFlags);
|
||||
return swift::c_string_utils::create_set(frontendFlags);
|
||||
}
|
||||
|
||||
swiftscan_string_set_t *
|
||||
@@ -543,85 +531,7 @@ swiftscan_compiler_supported_features_query() {
|
||||
std::vector<std::string> allFeatures;
|
||||
allFeatures.emplace_back("library-level");
|
||||
allFeatures.emplace_back("emit-abi-descriptor");
|
||||
return create_set(allFeatures);
|
||||
}
|
||||
|
||||
//=== Static Mirror Scan Functions ---------------------------------------===//
|
||||
swiftscan_static_mirror_t
|
||||
swiftscan_static_mirror_create(int num_binaries, const char **binary_paths,
|
||||
const char *arch) {
|
||||
INITIALIZE_LLVM();
|
||||
std::vector<std::string> inputBinaryPaths;
|
||||
for (unsigned SI = 0, SE = num_binaries; SI < SE; ++SI)
|
||||
inputBinaryPaths.push_back(binary_paths[SI]);
|
||||
|
||||
return wrap_static_mirror(new BinaryScanningTool(inputBinaryPaths, arch));
|
||||
}
|
||||
|
||||
void swiftscan_static_mirror_dispose(
|
||||
swiftscan_static_mirror_t c_static_mirror) {
|
||||
delete unwrap_static_mirror(c_static_mirror);
|
||||
}
|
||||
|
||||
swiftscan_static_mirror_conformances_set_t *
|
||||
swiftscan_static_mirror_conformances_set_create(
|
||||
swiftscan_static_mirror_t static_mirror, int num_protocols,
|
||||
const char **protocol_names) {
|
||||
std::vector<std::string> protocols;
|
||||
for (unsigned SI = 0, SE = num_protocols; SI < SE; ++SI)
|
||||
protocols.push_back(protocol_names[SI]);
|
||||
BinaryScanningTool *scanTool = unwrap_static_mirror(static_mirror);
|
||||
auto scanResult = scanTool->collectConformances(protocols);
|
||||
|
||||
// Bridge to the C interface
|
||||
swiftscan_static_mirror_conformances_set_t *conformanceSet =
|
||||
new swiftscan_static_mirror_conformances_set_t;
|
||||
conformanceSet->count = scanResult.Conformances.size();
|
||||
conformanceSet->conformances =
|
||||
new swiftscan_static_mirror_conformance_info_t[conformanceSet->count];
|
||||
|
||||
size_t idx = 0;
|
||||
for (auto &conformance : scanResult.Conformances) {
|
||||
swiftscan_conformance_info_s *conformanceInfo = new swiftscan_conformance_info_s;
|
||||
conformanceSet->conformances[idx] = conformanceInfo;
|
||||
conformanceInfo->type_name = create_clone(conformance.TypeName.c_str());
|
||||
conformanceInfo->mangled_type_name = create_clone(conformance.MangledTypeName.c_str());
|
||||
conformanceInfo->protocol_name = create_clone(conformance.ProtocolName.c_str());
|
||||
idx += 1;
|
||||
}
|
||||
return conformanceSet;
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t
|
||||
swiftscan_static_mirror_conformance_info_get_type_name(swiftscan_static_mirror_conformance_info_t info) {
|
||||
return info->type_name;
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t
|
||||
swiftscan_static_mirror_conformance_info_get_protocol_name(swiftscan_static_mirror_conformance_info_t info) {
|
||||
return info->protocol_name;
|
||||
}
|
||||
|
||||
swiftscan_string_ref_t
|
||||
swiftscan_static_mirror_conformance_info_get_mangled_type_name(swiftscan_static_mirror_conformance_info_t info) {
|
||||
return info->mangled_type_name;
|
||||
}
|
||||
|
||||
void swiftscan_static_mirror_conformance_info_dispose(
|
||||
swiftscan_static_mirror_conformance_info_t info) {
|
||||
swiftscan_conformance_info_s *info_impl = info;
|
||||
swiftscan_string_dispose(info_impl->type_name);
|
||||
swiftscan_string_dispose(info_impl->mangled_type_name);
|
||||
swiftscan_string_dispose(info_impl->protocol_name);
|
||||
}
|
||||
|
||||
void swiftscan_static_mirror_conformances_set_dispose(
|
||||
swiftscan_static_mirror_conformances_set_t *set) {
|
||||
for (size_t i = 0; i < set->count; ++i) {
|
||||
swiftscan_static_mirror_conformance_info_dispose(set->conformances[i]);
|
||||
}
|
||||
delete[] set->conformances;
|
||||
delete set;
|
||||
return swift::c_string_utils::create_set(allFeatures);
|
||||
}
|
||||
|
||||
//=== Experimental Compiler Invocation Functions ------------------------===//
|
||||
|
||||
@@ -59,12 +59,4 @@ swiftscan_compiler_target_info_query
|
||||
swiftscan_scanner_cache_serialize
|
||||
swiftscan_scanner_cache_load
|
||||
swiftscan_scanner_cache_reset
|
||||
swiftscan_static_mirror_conformances_set_create
|
||||
swiftscan_static_mirror_conformances_set_dispose
|
||||
swiftscan_static_mirror_conformance_info_dispose
|
||||
swiftscan_static_mirror_conformance_info_get_type_name
|
||||
swiftscan_static_mirror_conformance_info_get_protocol_name
|
||||
swiftscan_static_mirror_conformance_info_get_mangled_type_name
|
||||
swiftscan_static_mirror_create
|
||||
swiftscan_static_mirror_dispose
|
||||
invoke_swift_compiler
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST_F(ScanTest, TestTargetInfoQuery) {
|
||||
llvm::errs() << "\nERROR:" << targetInfo.getError().message() << "\n";
|
||||
}
|
||||
|
||||
auto targetInfoStr = std::string(get_C_string(targetInfo.get()));
|
||||
auto targetInfoStr = std::string(swift::c_string_utils::get_C_string(targetInfo.get()));
|
||||
EXPECT_NE(targetInfoStr.find("\"triple\": \"x86_64-apple-macosx12.0\""), std::string::npos);
|
||||
EXPECT_NE(targetInfoStr.find("\"librariesRequireRPath\": false"), std::string::npos);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
# Buildbots for Darwin OSes
|
||||
#===------------------------------------------------------------------------===#
|
||||
[preset: mixin_buildbot_install_components]
|
||||
swift-install-components=back-deployment;compiler;clang-builtin-headers;stdlib;sdk-overlay;parser-lib;editor-integration;tools;toolchain-tools;testsuite-tools;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers;
|
||||
swift-install-components=back-deployment;compiler;clang-builtin-headers;stdlib;sdk-overlay;parser-lib;static-mirror-lib;editor-integration;tools;toolchain-tools;testsuite-tools;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers;
|
||||
|
||||
[preset: mixin_buildbot_install_components_with_clang]
|
||||
swift-install-components=back-deployment;compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;parser-lib;toolchain-tools;license;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers
|
||||
|
||||
swift-install-components=back-deployment;compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;parser-lib;static-mirror-lib;toolchain-tools;license;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers
|
||||
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-resource-headers;compiler-rt;clangd;dsymutil;LTO;clang-features-file
|
||||
|
||||
[preset: mixin_buildbot_trunk_base]
|
||||
@@ -809,7 +810,8 @@ no-swift-stdlib-assertions
|
||||
# Linux Builders
|
||||
#===------------------------------------------------------------------------===#
|
||||
[preset: mixin_linux_install_components_with_clang]
|
||||
swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;parser-lib;toolchain-tools;license;sourcekit-inproc
|
||||
|
||||
swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;parser-lib;static-mirror-lib;toolchain-tools;license;sourcekit-inproc
|
||||
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-resource-headers;compiler-rt;clangd;lld;LTO;clang-features-file
|
||||
|
||||
[preset: mixin_linux_installation]
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
# utils/build-parser-lib - Helper tool for building the parser library -*- python -*-
|
||||
# utils/build-tooling-libs - Helper tool for building the SwiftSyntax paresr
|
||||
# and SwiftStaticMirror libraries -*- python -*-
|
||||
#
|
||||
# This source file is part of the Swift.org open source project
|
||||
#
|
||||
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
||||
# Copyright (c) 2014 - 2022 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 is a utility for building only the syntax parser library as fast as possible
|
||||
# by only building the necessary libraries for the parser library and nothing
|
||||
# extraneous. To achieve this it does a single unified CMake configuration for
|
||||
# llvm/clang/swift and builds only the parser library target.
|
||||
# This is a utility for building only the syntax parser and swift static-mirror
|
||||
# libraries as fast as possible by only building the necessary dependency libraries
|
||||
# and nothing extraneous. To achieve this it does a single unified CMake configuration for
|
||||
# llvm/clang/swift and builds only the required CMake targets for the two libraries.
|
||||
# This mechanism is fundamentally different from build-script, which builds llvm/clang
|
||||
# in a separate build directory than swift.
|
||||
#
|
||||
@@ -42,6 +43,9 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain
|
||||
isDarwin = platform.system() == "Darwin"
|
||||
isSwiftContainedInLLVMProject = os.path.exists(os.path.join(SWIFT_SOURCE_ROOT, "llvm"))
|
||||
|
||||
syntaxParserLibTarget = "tools/swift/tools/libSwiftSyntaxParser/install"
|
||||
staticMirrorLibTarget = "tools/swift/tools/libStaticMirror/install"
|
||||
syntaxParserTesterTarget = "swift-syntax-parser-test"
|
||||
|
||||
class Builder(object):
|
||||
def __init__(
|
||||
@@ -266,12 +270,22 @@ class Builder(object):
|
||||
cmake_args += [llvm_src_path]
|
||||
self.call(cmake_args, env=environment)
|
||||
|
||||
def build_target(self, build_dir, target, env=None):
|
||||
def build_targets(self, build_dir, targets, env=None):
|
||||
invocation = [self.toolchain.cmake, "--build", build_dir]
|
||||
invocation += ["--", "-j%d" % self.jobs]
|
||||
|
||||
# libStaticMirror requires a DESTDIR for the build action
|
||||
# Ensure that if one was not provided, we still have a temporary
|
||||
# location for it.
|
||||
if env is None or (env is not None and env["DESTDIR"] is not None):
|
||||
if self.install_destdir:
|
||||
env = {"DESTDIR": self.install_destdir}
|
||||
else:
|
||||
env = {"DESTDIR": os.path.join(build_dir, "install")}
|
||||
|
||||
if self.verbose:
|
||||
invocation += ["-v"]
|
||||
invocation += [target]
|
||||
invocation += targets
|
||||
self.call(invocation, env=env, without_sleeping=True)
|
||||
|
||||
def install(self):
|
||||
@@ -279,8 +293,9 @@ class Builder(object):
|
||||
env = None
|
||||
if self.install_destdir:
|
||||
env = {"DESTDIR": self.install_destdir}
|
||||
self.build_target(
|
||||
self.build_dir, "tools/swift/tools/libSwiftSyntaxParser/install", env=env
|
||||
self.build_targets(
|
||||
self.build_dir, [syntaxParserLibTarget,
|
||||
staticMirrorLibTarget], env=env
|
||||
)
|
||||
|
||||
def get_profile_data(self, profile_dir):
|
||||
@@ -288,13 +303,13 @@ class Builder(object):
|
||||
instrumentation = "IR" if self.pgo_type == "ir" else "Frontend"
|
||||
with shell.pushd(profile_dir, dry_run=self.dry_run):
|
||||
self.configure(enable_debuginfo=False, instrumentation=instrumentation)
|
||||
self.build_target(profile_dir, "swift-syntax-parser-test")
|
||||
self.build_targets(profile_dir, [syntaxParserTesterTarget])
|
||||
# Delete existing profile data that were generated during building from
|
||||
# running tablegen.
|
||||
shell.rmtree("profiles", dry_run=self.dry_run)
|
||||
self.call(
|
||||
[
|
||||
os.path.join("bin", "swift-syntax-parser-test"),
|
||||
os.path.join("bin", syntaxParserTesterTarget),
|
||||
self.profile_input,
|
||||
"-time",
|
||||
]
|
||||
@@ -314,7 +329,7 @@ class Builder(object):
|
||||
with shell.pushd(self.build_dir, dry_run=self.dry_run):
|
||||
self.configure(enable_debuginfo=True, profile_data=self.profile_data)
|
||||
|
||||
self.build_target(self.build_dir, "swift-syntax-parser-test")
|
||||
self.build_targets(self.build_dir, [syntaxParserTesterTarget, staticMirrorLibTarget])
|
||||
|
||||
if self.install_destdir:
|
||||
self.install()
|
||||
@@ -340,20 +355,20 @@ def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description="""
|
||||
Builds Swift Syntax Parser library.
|
||||
Builds Swift Syntax Parser and Swift Static Mirror libraries.
|
||||
|
||||
Example invocations:
|
||||
|
||||
* Building for host (macOS, linux):
|
||||
|
||||
$ utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build
|
||||
$ utils/build-tooling-libs --release --no-assertions --build-dir /tmp/tooling-libs-build
|
||||
|
||||
* Building for iOS
|
||||
|
||||
$ utils/build-parser-lib --release --no-assertions --build-dir \
|
||||
/tmp/parser-lib-build-iossim --host iphonesimulator --architectures x86_64
|
||||
$ utils/build-parser-lib --release --no-assertions --build-dir \
|
||||
/tmp/parser-lib-build-ios --host iphoneos --architectures arm64
|
||||
$ utils/build-tooling-libs --release --no-assertions --build-dir \
|
||||
/tmp/tooling-libs-build-iossim --host iphonesimulator --architectures x86_64
|
||||
$ utils/build-tooling-libs --release --no-assertions --build-dir \
|
||||
/tmp/tooling-libs-build-ios --host iphoneos --architectures arm64
|
||||
|
||||
""",
|
||||
)
|
||||
@@ -372,7 +387,7 @@ Example invocations:
|
||||
SWIFT_SOURCE_ROOT, "swift", "utils", "parser-lib", "profile-input.swift"
|
||||
)
|
||||
default_jobs = multiprocessing.cpu_count()
|
||||
default_build_dir = os.path.join(SWIFT_BUILD_ROOT, "parser-lib")
|
||||
default_build_dir = os.path.join(SWIFT_BUILD_ROOT, "tooling-libs")
|
||||
default_install_prefix = (
|
||||
defaults.DARWIN_INSTALL_PREFIX if isDarwin else defaults.UNIX_INSTALL_PREFIX
|
||||
)
|
||||
@@ -554,8 +569,7 @@ Example invocations:
|
||||
shell.makedirs(native_build_dir, dry_run=tmpargs.dry_run)
|
||||
with shell.pushd(native_build_dir, dry_run=tmpargs.dry_run):
|
||||
builder.configure(enable_debuginfo=False)
|
||||
builder.build_target(native_build_dir, "llvm-tblgen")
|
||||
builder.build_target(native_build_dir, "clang-tblgen")
|
||||
builder.build_targets(native_build_dir, ["llvm-tblgen", "clang-tblgen"])
|
||||
|
||||
for arch in architectures:
|
||||
args.build_dir = os.path.join(objroot, arch, "obj")
|
||||
Reference in New Issue
Block a user