From 5d125c2593a21a5237f76dd0063cdf1f42f6f877 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 14 Jan 2021 15:46:00 -0800 Subject: [PATCH 1/4] Add swift-crypto dependency Motivation: Package collections feature will require swift-crypto dependency. Modifications: - Add swift-crypto dependency - Bump minimum macOS version to 10.15, for it's required by swift-crypto --- Package.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 16f796a2aca..c9743227602 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ let macOSPlatform: SupportedPlatform if let deploymentTarget = ProcessInfo.processInfo.environment["SWIFTPM_MACOS_DEPLOYMENT_TARGET"] { macOSPlatform = .macOS(deploymentTarget) } else { - macOSPlatform = .macOS(.v10_10) + macOSPlatform = .macOS(.v10_15) } let package = Package( @@ -156,7 +156,7 @@ let package = Package( .target( /** Data structures and support for package collections */ name: "PackageCollections", - dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl", "PackageCollectionsModel"]), + dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl", "PackageCollectionsModel", "Crypto"]), // MARK: Package Manager Functionality @@ -323,6 +323,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { // dependency version changes here with those projects. .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")), .package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)), + .package(url: "https://github.com/apple/swift-crypto.git", .upToNextMajor(from: "1.1.0")), ] } else { package.dependencies += [ From e330a39c6da7264aedaf263904131426c232b163 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Sun, 17 Jan 2021 10:05:33 -0800 Subject: [PATCH 2/4] fix build? --- CMakeLists.txt | 1 + Package.swift | 1 + Sources/PackageCollections/CMakeLists.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbc4e361522..6ae4e7ede99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ if(FIND_PM_DEPS) endif() find_package(ArgumentParser CONFIG REQUIRED) + find_package(Crypto CONFIG REQUIRED) find_package(SwiftDriver CONFIG REQUIRED) endif() diff --git a/Package.swift b/Package.swift index c9743227602..c6a4dc37fc9 100644 --- a/Package.swift +++ b/Package.swift @@ -330,5 +330,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { .package(path: "../swift-tools-support-core"), .package(path: "../swift-argument-parser"), .package(path: "../swift-driver"), + .package(path: "../swift-crypto"), ] } diff --git a/Sources/PackageCollections/CMakeLists.txt b/Sources/PackageCollections/CMakeLists.txt index fa94a4b451f..f5c5a20da85 100644 --- a/Sources/PackageCollections/CMakeLists.txt +++ b/Sources/PackageCollections/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(PackageCollections PUBLIC TSCBasic TSCUtility Basics + Crypto PackageModel SourceControl) # NOTE(compnerd) workaround for CMake not setting up include flags yet From e20976419f0f9f0231d363da46df98f7c41e4e29 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Wed, 27 Jan 2021 23:59:24 -0800 Subject: [PATCH 3/4] More progress --- Documentation/Contributing.md | 7 +++++++ Package.swift | 4 ++-- Utilities/bootstrap | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Documentation/Contributing.md b/Documentation/Contributing.md index 7667de91346..ba0fbbfbea3 100644 --- a/Documentation/Contributing.md +++ b/Documentation/Contributing.md @@ -152,6 +152,13 @@ For example, if the latest tag is 0.3.1: $> git clone https://github.com/apple/swift-argument-parser --branch 0.3.1 ``` +5. Clone [swift-crypto](https://github.com/apple/swift-crypto) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags). + +For example, if the latest tag is 1.1.3: +```bash +$> git clone https://github.com/apple/swift-crypto --branch 1.1.3 +``` + #### Building ```bash diff --git a/Package.swift b/Package.swift index c6a4dc37fc9..e36d2d6b607 100644 --- a/Package.swift +++ b/Package.swift @@ -3,7 +3,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors + Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See http://swift.org/LICENSE.txt for license information @@ -323,7 +323,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { // dependency version changes here with those projects. .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")), .package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)), - .package(url: "https://github.com/apple/swift-crypto.git", .upToNextMajor(from: "1.1.0")), + .package(url: "https://github.com/apple/swift-crypto.git", .branch(relatedDependenciesBranch)), ] } else { package.dependencies += [ diff --git a/Utilities/bootstrap b/Utilities/bootstrap index ead6af68a9c..4be4c695ea7 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -3,7 +3,7 @@ """ This source file is part of the Swift.org open source project - Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors + Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See http://swift.org/LICENSE.txt for license information @@ -171,6 +171,7 @@ def parse_global_args(args): args.yams_source_dir = os.path.join(args.project_root, "..", "yams") args.swift_argument_parser_source_dir = os.path.join(args.project_root, "..", "swift-argument-parser") args.swift_driver_source_dir = os.path.join(args.project_root, "..", "swift-driver") + args.swift_crypto_source_dir = os.path.join(args.project_root, "..", "swift-crypto") args.source_root = os.path.join(args.project_root, "Sources") if platform.system() == 'Darwin': @@ -307,6 +308,7 @@ def build(args): build_yams(args) build_swift_argument_parser(args) build_swift_driver(args) + build_swift_crypto(args) build_swiftpm_with_cmake(args) build_swiftpm_with_swiftpm(args,integrated_swift_driver=False) @@ -559,6 +561,18 @@ def build_swift_driver(args): cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) build_with_cmake(args, cmake_flags, args.swift_driver_source_dir, args.swift_driver_build_dir) + +def build_swift_crypto(args): + note("Building SwiftCrypto") + args.swift_crypto_build_dir = os.path.join(args.target_dir, "swift-crypto") + + cmake_flags = [] + if platform.system() == 'Darwin': + cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) + cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + + cmake_flags.append("-DBUILD_SHARED_LIBS=YES") + build_with_cmake(args, cmake_flags, args.swift_crypto_source_dir, args.swift_crypto_build_dir) def add_rpath_for_cmake_build(args, rpath): "Adds the given rpath to the CMake-built swift-build" @@ -578,6 +592,7 @@ def build_swiftpm_with_cmake(args): "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), "-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"), "-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"), + "-DCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"), "-DFIND_PM_DEPS:BOOL=YES", ] else: @@ -598,6 +613,7 @@ def build_swiftpm_with_cmake(args): add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "lib")) add_rpath_for_cmake_build(args, os.path.join(args.swift_argument_parser_build_dir, "lib")) add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_crypto_build_dir, "lib")) def build_swiftpm_with_swiftpm(args, integrated_swift_driver): """Builds SwiftPM using the version of SwiftPM built with CMake.""" @@ -694,6 +710,7 @@ def get_swiftpm_env_cmd(args): os.path.join(args.yams_build_dir, "lib"), os.path.join(args.swift_argument_parser_build_dir, "lib"), os.path.join(args.swift_driver_build_dir, "lib"), + os.path.join(args.swift_crypto_build_dir, "lib"), ] + args.target_info["paths"]["runtimeLibraryPaths"]) if platform.system() == 'Darwin': From 0d7b44087d81fd706ca5cbdb3ee3a6a1dc28fb22 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 28 Jan 2021 15:03:25 -0800 Subject: [PATCH 4/4] Fix build Requires https://github.com/apple/swift-crypto/pull/65 --- CMakeLists.txt | 4 ++-- Sources/PackageCollections/CMakeLists.txt | 3 +++ .../Signing/PackageCollectionSignature.swift | 16 ++++++++++++++++ Utilities/bootstrap | 3 +-- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 Sources/PackageCollections/Signing/PackageCollectionSignature.swift diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae4e7ede99..1755ec9a897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # 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 - 2021 Apple Inc. and the Swift project authors # Licensed under Apache License v2.0 with Runtime Library Exception # # See http://swift.org/LICENSE.txt for license information @@ -47,7 +47,7 @@ if(FIND_PM_DEPS) endif() find_package(ArgumentParser CONFIG REQUIRED) - find_package(Crypto CONFIG REQUIRED) + find_package(SwiftCrypto CONFIG REQUIRED) find_package(SwiftDriver CONFIG REQUIRED) endif() diff --git a/Sources/PackageCollections/CMakeLists.txt b/Sources/PackageCollections/CMakeLists.txt index f5c5a20da85..9293c4f9ab4 100644 --- a/Sources/PackageCollections/CMakeLists.txt +++ b/Sources/PackageCollections/CMakeLists.txt @@ -33,11 +33,14 @@ target_link_libraries(PackageCollections PUBLIC TSCUtility Basics Crypto + CCryptoBoringSSL PackageModel SourceControl) # NOTE(compnerd) workaround for CMake not setting up include flags yet set_target_properties(PackageCollections PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_link_options(PackageCollections PRIVATE + "$<$:SHELL:-Xlinker -framework -Xlinker Security>") if(USE_CMAKE_INSTALL) install(TARGETS PackageCollections diff --git a/Sources/PackageCollections/Signing/PackageCollectionSignature.swift b/Sources/PackageCollections/Signing/PackageCollectionSignature.swift new file mode 100644 index 00000000000..edab6e32ab5 --- /dev/null +++ b/Sources/PackageCollections/Signing/PackageCollectionSignature.swift @@ -0,0 +1,16 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2021 Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for Swift project authors + */ + +import Crypto +#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +import Security +#else +import CCryptoBoringSSL +#endif diff --git a/Utilities/bootstrap b/Utilities/bootstrap index 4be4c695ea7..01aa3efd1c1 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -571,7 +571,6 @@ def build_swift_crypto(args): cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) - cmake_flags.append("-DBUILD_SHARED_LIBS=YES") build_with_cmake(args, cmake_flags, args.swift_crypto_source_dir, args.swift_crypto_build_dir) def add_rpath_for_cmake_build(args, rpath): @@ -592,7 +591,7 @@ def build_swiftpm_with_cmake(args): "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), "-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"), "-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"), - "-DCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"), + "-DSwiftCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"), "-DFIND_PM_DEPS:BOOL=YES", ] else: