Skip to content
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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Main

on:
push:
branches: [main]

jobs:
unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
28 changes: 28 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
license_header_check_project_name: "SwiftAsyncDNSResolver"
yamllint_check_enabled: false
api_breakage_check_enabled: false

unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
18 changes: 18 additions & 0 deletions .github/workflows/pull_request_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PR label

on:
pull_request:
types: [labeled, unlabeled, opened, reopened, synchronize]

jobs:
semver-label-check:
name: Semantic Version label check
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Check for Semantic Version label
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
20 changes: 20 additions & 0 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Scheduled

on:
schedule:
- cron: "0 8,20 * * *"

jobs:
unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
13 changes: 13 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.gitignore
.licenseignore
.swiftformatignore
.spi.yml
.swift-format
.github/
**.md
**.txt
**Package.swift
docker/*
.gitmodules
.editorconfig
Sources/CAsyncDNSResolver/c-ares
62 changes: 62 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
19 changes: 0 additions & 19 deletions .swiftformat

This file was deleted.

25 changes: 3 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,10 @@ A good patch is:
3. Documented, adding API documentation as needed to cover new functions and properties.
4. Accompanied by a great commit message, using our commit message template.

### Run `./scripts/soundness.sh`
### Run CI checks locally

The scripts directory contains a [soundness.sh script](https://github.com/apple/swift-async-dns-resolver/blob/main/scripts/soundness.sh)
that enforces additional checks, like license headers and formatting style.

Please make sure to `./scripts/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail
on minor changes such as a missing `self.` or similar formatting issues.

For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks),
which you can do via executing the following command in the project root directory:

```bash
cat << EOF > .git/hooks/pre-push

if [[ -f "scripts/soundness.sh" ]]; then
scripts/soundness.sh
fi
EOF
```

Which makes the script execute, and only allow the `git push` to complete if the check has passed.

In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again.
You can run the Github Actions workflows locally using
[act](https://github.com/nektos/act). For detailed steps on how to do this please see [https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally](https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally).

## How to contribute your work

Expand Down
11 changes: 5 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// swift-tools-version:5.6

import class Foundation.FileManager
import PackageDescription

import class Foundation.FileManager

var caresExclude = [
"./c-ares/src/lib/cares.rc",
"./c-ares/src/lib/CMakeLists.txt",
Expand All @@ -22,11 +23,9 @@ do {
let package = Package(
name: "swift-async-dns-resolver",
products: [
.library(name: "AsyncDNSResolver", targets: ["AsyncDNSResolver"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.library(name: "AsyncDNSResolver", targets: ["AsyncDNSResolver"])
],
dependencies: [],
targets: [
.target(
name: "CAsyncDNSResolver",
Expand All @@ -43,7 +42,7 @@ let package = Package(
.target(
name: "AsyncDNSResolver",
dependencies: [
"CAsyncDNSResolver",
"CAsyncDNSResolver"
]
),

Expand Down
9 changes: 8 additions & 1 deletion Sources/AsyncDNSResolver/AsyncDNSResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,14 @@ public struct NAPTRRecord: Sendable, Hashable, CustomStringConvertible {
"\(Self.self)(flags=\(self.flags ?? ""), service=\(self.service ?? ""), regExp=\(self.regExp ?? ""), replacement=\(self.replacement), order=\(self.order), preference=\(self.preference))"
}

public init(flags: String?, service: String?, regExp: String?, replacement: String, order: UInt16, preference: UInt16) {
public init(
flags: String?,
service: String?,
regExp: String?,
replacement: String,
order: UInt16,
preference: UInt16
) {
self.flags = flags
self.service = service
self.regExp = regExp
Expand Down
6 changes: 4 additions & 2 deletions Sources/AsyncDNSResolver/c-ares/AresOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ extension String {

extension Sequence {
fileprivate func deallocate<T>() where Element == UnsafeMutablePointer<T>? {
self.forEach { $0?.deallocate() }
for entry in self {
entry?.deallocate()
}
}
}

Expand All @@ -365,7 +367,7 @@ struct AresOptionMasks: OptionSet {
let rawValue: CInt

static let FLAGS = AresOptionMasks(rawValue: ARES_OPT_FLAGS)
static let TIMEOUT = AresOptionMasks(rawValue: ARES_OPT_TIMEOUT) // Deprecated by TIMEOUTMS
static let TIMEOUT = AresOptionMasks(rawValue: ARES_OPT_TIMEOUT) // Deprecated by TIMEOUTMS
static let TRIES = AresOptionMasks(rawValue: ARES_OPT_TRIES)
static let NDOTS = AresOptionMasks(rawValue: ARES_OPT_NDOTS)
static let UDP_PORT = AresOptionMasks(rawValue: ARES_OPT_UDP_PORT)
Expand Down
21 changes: 15 additions & 6 deletions Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ extension QueryType {

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
class Ares {
typealias QueryCallback = @convention(c) (UnsafeMutableRawPointer?, CInt, CInt, UnsafeMutablePointer<CUnsignedChar>?, CInt) -> Void
typealias QueryCallback = @convention(c) (
UnsafeMutableRawPointer?, CInt, CInt, UnsafeMutablePointer<CUnsignedChar>?, CInt
) -> Void

let options: AresOptions
let channel: AresChannel
Expand Down Expand Up @@ -193,11 +195,11 @@ class Ares {
extension Ares {
// TODO: implement this more nicely using NIO EventLoop?
// See:
// https://github.com/dimbleby/c-ares-resolver/blob/master/src/unix/eventloop.rs
// https://github.com/dimbleby/rust-c-ares/blob/master/src/channel.rs
// https://github.com/dimbleby/rust-c-ares/blob/master/examples/event-loop.rs
// https://github.com/dimbleby/c-ares-resolver/blob/master/src/unix/eventloop.rs // ignore-unacceptable-language
// https://github.com/dimbleby/rust-c-ares/blob/master/src/channel.rs // ignore-unacceptable-language
// https://github.com/dimbleby/rust-c-ares/blob/master/examples/event-loop.rs // ignore-unacceptable-language
class QueryProcessor {
static let defaultPollInterval: UInt64 = 10 * 1_000_000 // 10ms
static let defaultPollInterval: UInt64 = 10 * 1_000_000 // 10ms

private let channel: AresChannel
private let pollIntervalNanos: UInt64
Expand Down Expand Up @@ -449,7 +451,14 @@ extension Ares {
let hostentPtrPtr = UnsafeMutablePointer<UnsafeMutablePointer<hostent>?>.allocate(capacity: 1)
defer { hostentPtrPtr.deallocate() }

let parseStatus = ares_parse_ptr_reply(buffer, length, dummyAddrPointer, INET_ADDRSTRLEN, AF_INET, hostentPtrPtr)
let parseStatus = ares_parse_ptr_reply(
buffer,
length,
dummyAddrPointer,
INET_ADDRSTRLEN,
AF_INET,
hostentPtrPtr
)

switch parseStatus {
case ARES_SUCCESS:
Expand Down
Loading