Skip to content
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

Use swift-crypto #5852

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ swift_library(
"@sourcekitten_com_github_jpsim_yams//:Yams",
"@swiftlint_com_github_scottrhoyt_swifty_text_table//:SwiftyTextTable",
] + select({
"@platforms//os:linux": ["@com_github_krzyzanowskim_cryptoswift//:CryptoSwift"],
"@platforms//os:linux": ["@com_github_apple_swift_crypto//:Crypto"],
"//conditions:default": [":DyldWarningWorkaround"],
}),
)
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_apple", version = "3.8.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_cc", version = "0.0.16", repo_name = "build_bazel_rules_cc")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure whether we need to do anything else to make sure downstream packages handle rules_cc correctly

Copy link
Collaborator

Choose a reason for hiding this comment

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

No should be fine. IIRC rules_cc was split out of Bazel’s core in 7.0.

bazel_dep(name = "sourcekitten", version = "0.36.0", repo_name = "com_github_jpsim_sourcekitten")
bazel_dep(name = "swift-syntax", version = "600.0.0", repo_name = "SwiftSyntax")
bazel_dep(name = "swift_argument_parser", version = "1.3.1.1", repo_name = "sourcekitten_com_github_apple_swift_argument_parser")
Expand All @@ -19,7 +20,7 @@ swiftlint_repos = use_extension("//bazel:repos.bzl", "swiftlint_repos_bzlmod")
use_repo(
swiftlint_repos,
"com_github_johnsundell_collectionconcurrencykit",
"com_github_krzyzanowskim_cryptoswift",
"com_github_apple_swift_crypto",
"swiftlint_com_github_scottrhoyt_swifty_text_table",
)

Expand Down
27 changes: 18 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
"version" : "0.2.0"
}
},
{
"identity" : "cryptoswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "c9c3df6ab812de32bae61fc0cd1bf6d45170ebf0",
"version" : "1.8.2"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
Expand All @@ -36,6 +27,24 @@
"version" : "1.3.1"
}
},
{
"identity" : "swift-asn1",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-asn1.git",
"state" : {
"revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
"version" : "1.3.0"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "06dc63c6d8da54ee11ceb268cde1fa68161afc96",
"version" : "3.9.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let package = Package(
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.6"),
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.8.0")),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "3.9.1")),
],
targets: [
.plugin(
Expand Down Expand Up @@ -68,7 +68,7 @@ let package = Package(
.target(
name: "SwiftLintCore",
dependencies: [
.product(name: "CryptoSwift", package: "CryptoSwift", condition: .when(platforms: [.linux])),
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux])),
.target(name: "DyldWarningWorkaround", condition: .when(platforms: [.macOS])),
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftIDEUtils", package: "swift-syntax"),
Expand Down
3 changes: 0 additions & 3 deletions Source/SwiftLintCore/Extensions/Configuration+Cache.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#if canImport(CryptoSwift)
import CryptoSwift
#endif
import Foundation

extension Configuration {
Expand Down
17 changes: 8 additions & 9 deletions Source/SwiftLintCore/Extensions/String+sha256.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#if canImport(CommonCrypto)
import CommonCrypto
#if canImport(CryptoKit)
import CryptoKit
#elseif canImport(Crypto)
import Crypto
#endif

import Foundation

extension Data {
internal func sha256() -> Data {
withUnsafeBytes { bytes in
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
_ = CC_SHA256(bytes.baseAddress, CC_LONG(count), &hash)
return Data(hash)
}
Data(SHA256.hash(data: self))
}

internal func toHexString() -> String {
Expand All @@ -18,7 +18,6 @@ extension Data {

extension String {
internal func sha256() -> String {
data(using: .utf8)!.sha256().toHexString()
Data(utf8).sha256().toHexString()
}
}
#endif
3 changes: 0 additions & 3 deletions Source/SwiftLintCore/Reporters/CodeClimateReporter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#if canImport(CryptoSwift)
import CryptoSwift
#endif
import Foundation
import SourceKittenFramework

Expand Down
11 changes: 0 additions & 11 deletions bazel/CryptoSwift.BUILD

This file was deleted.

86 changes: 86 additions & 0 deletions bazel/SwiftCrypto.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
Swift Crypto is an open-source implementation of a substantial portion of the API of
[Apple CryptoKit](https://developer.apple.com/documentation/cryptokit) suitable for
use on Linux platforms. It enables cross-platform or server applications with the
advantages of CryptoKit.

This build overlay is borrowed from aaronsky/asc-swift:
https://github.com/aaronsky/asc-swift/blob/386bb669/bazel/third_party/com_github_apple_swift_crypto/BUILD.overlay
"""

load("@build_bazel_rules_cc//cc:defs.bzl", "cc_library")
load("@build_bazel_rules_swift//swift:swift_interop_hint.bzl", "swift_interop_hint")
load("@build_bazel_rules_swift//swift:swift_library.bzl", "swift_library")

_crypto_non_apple_deps = [
":CCryptoBoringSSL",
":CCryptoBoringSSLShims",
":CryptoBoringWrapper",
]

swift_library(
name = "Crypto",
srcs = glob(["Sources/Crypto/**/*.swift"]),
defines = [
"MODULE_IS_CRYPTO",
"CRYPTO_IN_SWIFTPM",
] + select({
"@platforms//os:linux": ["CRYPTO_IN_SWIFTPM_FORCE_BUILD_API"],
"@platforms//os:android": ["CRYPTO_IN_SWIFTPM_FORCE_BUILD_API"],
"@platforms//os:windows": ["CRYPTO_IN_SWIFTPM_FORCE_BUILD_API"],
"@platforms//os:wasi": ["CRYPTO_IN_SWIFTPM_FORCE_BUILD_API"],
"//conditions:default": [],
}),
module_name = "Crypto",
visibility = ["//visibility:public"],
deps = select({
"@platforms//os:linux": _crypto_non_apple_deps,
"@platforms//os:android": _crypto_non_apple_deps,
"@platforms//os:windows": _crypto_non_apple_deps,
"@platforms//os:wasi": _crypto_non_apple_deps,
"//conditions:default": [],
}),
)

cc_library(
name = "CCryptoBoringSSL",
srcs = glob([
"Sources/CCryptoBoringSSL/crypto/**/*.c",
"Sources/CCryptoBoringSSL/crypto/**/*.h",
"Sources/CCryptoBoringSSL/crypto/**/*.S",
"Sources/CCryptoBoringSSL/third_party/**/*.h",
"Sources/CCryptoBoringSSL/third_party/**/*.S",
]),
hdrs = glob(["Sources/CCryptoBoringSSL/include/**/*.h"]),
aspect_hints = [":CCryptoBoringSSL_interop"],
includes = ["Sources/CCryptoBoringSSL/include"],
)

swift_interop_hint(
name = "CCryptoBoringSSL_interop",
module_name = "CCryptoBoringSSL",
)

cc_library(
name = "CCryptoBoringSSLShims",
srcs = ["Sources/CCryptoBoringSSLShims/shims.c"],
hdrs = ["Sources/CCryptoBoringSSLShims/include/CCryptoBoringSSLShims.h"],
aspect_hints = [":CCryptoBoringSSLShims_interop"],
includes = ["Sources/CCryptoBoringSSLShims/include"],
deps = [":CCryptoBoringSSL"],
)

swift_interop_hint(
name = "CCryptoBoringSSLShims_interop",
module_name = "CCryptoBoringSSLShims",
)

swift_library(
name = "CryptoBoringWrapper",
srcs = glob(["Sources/CryptoBoringWrapper/**/*.swift"]),
module_name = "CryptoBoringWrapper",
deps = [
":CCryptoBoringSSL",
":CCryptoBoringSSLShims",
],
)
10 changes: 5 additions & 5 deletions bazel/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def swiftlint_repos(bzlmod = False):
)

http_archive(
name = "com_github_krzyzanowskim_cryptoswift",
sha256 = "3d649cccfe9ae0572163cde0201f013d10349a035c15225e7a4bd83c85fb0d1d",
build_file = "@SwiftLint//bazel:CryptoSwift.BUILD",
strip_prefix = "CryptoSwift-1.8.0",
url = "https://github.com/krzyzanowskim/CryptoSwift/archive/refs/tags/1.8.0.tar.gz",
name = "com_github_apple_swift_crypto",
build_file = "@SwiftLint//bazel:SwiftCrypto.BUILD",
sha256 = "f4a012b5b1898574bd4426855af65a9d1934c9d13a73e3a0586e129069a376f3",
strip_prefix = "swift-crypto-3.9.1",
url = "https://github.com/apple/swift-crypto/archive/refs/tags/3.9.1.zip",
)

def _swiftlint_repos_bzlmod(_):
Expand Down
Loading