Skip to content

Add swift-crypto dependency #3202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,6 +47,7 @@ if(FIND_PM_DEPS)
endif()

find_package(ArgumentParser CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)
endif()

Expand Down
7 changes: 7 additions & 0 deletions Documentation/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -323,11 +323,13 @@ 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", .branch(relatedDependenciesBranch)),
]
} else {
package.dependencies += [
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-driver"),
.package(path: "../swift-crypto"),
]
}
4 changes: 4 additions & 0 deletions Sources/PackageCollections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ target_link_libraries(PackageCollections PUBLIC
TSCBasic
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
"$<$<PLATFORM_ID:Darwin>:SHELL:-Xlinker -framework -Xlinker Security>")

if(USE_CMAKE_INSTALL)
install(TARGETS PackageCollections
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how swift-crypto will be used. We will need the Security framework as well. I added it so we can test everything together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this stub is really helpful to see how it gets used.

18 changes: 17 additions & 1 deletion Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -559,6 +561,17 @@ 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)

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"
Expand All @@ -578,6 +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"),
"-DSwiftCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"),
"-DFIND_PM_DEPS:BOOL=YES",
]
else:
Expand All @@ -598,6 +612,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."""
Expand Down Expand Up @@ -694,6 +709,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':
Expand Down