Skip to content

Commit 593b210

Browse files
committed
✨[feat]: swift 6 대응 및 진행
1 parent 86a0e8f commit 593b210

File tree

11 files changed

+71
-39
lines changed

11 files changed

+71
-39
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
name: "LogMacro",
99
platforms: [
1010
.macOS(.v10_15),
11-
.iOS(.v12)
11+
.iOS(.v13)
1212
],
1313
products: [
1414
.library(
@@ -22,7 +22,7 @@ let package = Package(
2222
],
2323
dependencies: [
2424
.package(
25-
url: "https://github.com/apple/swift-syntax.git", "509.0.2"..<"602.0.0"),
25+
url: "https://github.com/apple/swift-syntax.git", from: "600.0.0"),
2626
.package(url: "https://github.com/apple/swift-docc-plugin.git", exact: "1.4.4"),
2727
],
2828
targets: [
@@ -31,23 +31,38 @@ let package = Package(
3131
dependencies: [
3232
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
3333
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
34+
],
35+
swiftSettings: [
36+
.enableUpcomingFeature("StrictConcurrency")
3437
]
3538
),
3639
.target(
3740
name: "LogMacro",
3841
dependencies: [
3942
"LogMacroMacro"
4043
],
44+
swiftSettings: [
45+
.enableUpcomingFeature("StrictConcurrency")
46+
],
4147
linkerSettings: [
4248
.linkedFramework("OSLog")
4349
]
4450
),
45-
.executableTarget(name: "LogMacroClient", dependencies: ["LogMacro"]),
51+
.executableTarget(
52+
name: "LogMacroClient",
53+
dependencies: ["LogMacro"],
54+
swiftSettings: [
55+
.enableUpcomingFeature("StrictConcurrency")
56+
]
57+
),
4658
.testTarget(
4759
name: "LogMacroTests",
4860
dependencies: [
4961
"LogMacroMacro",
5062
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
63+
],
64+
swiftSettings: [
65+
.enableUpcomingFeature("StrictConcurrency")
5166
]
5267
),
5368
],

Sources/LogMacro/Log/Extension+Log.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99

1010
// MARK: - Log Extension for Structured Logging
1111

12+
@available(iOS 13.0, macOS 10.15, *)
1213
public extension Log {
1314
// MARK: - Debug Logs
1415

Sources/LogMacro/Log/Extension+OSLog.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111

1212
// MARK: - OSLog Extension
1313

14+
@available(iOS 13.0, macOS 10.15, *)
1415
extension OSLog {
1516
/// 앱 번들 식별자를 기반으로 하는 기본 서브시스템 식별자.
1617
static let subsystem = Bundle.main.bundleIdentifier ?? "com.default.subsystem"

Sources/LogMacro/Log/Log.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import OSLog
1212
///
1313
/// 다양한 로그 레벨을 정의하고, 해당 레벨에 맞춰
1414
/// iOS/macOS 버전에 따라 적절한 로거(API)를 사용해 메시지를 출력합니다.
15-
public struct Log {
15+
@available(iOS 13.0, macOS 10.15, *)
16+
public struct Log: Sendable {
1617
/// 기본 생성자
1718
public init() {}
1819

@@ -24,7 +25,7 @@ public struct Log {
2425
// MARK: - LogLevel
2526

2627
/// 지원하는 로그 레벨 및 커스텀 카테고리를 정의합니다.
27-
public enum LogLevel {
28+
public enum LogLevel: Sendable {
2829
/// 디버깅 목적으로 남기는 로그
2930
case debug
3031
/// 문제 해결 정보, 상태 등을 남기는 정보성 로그

Sources/LogMacro/Log/LogMacroExport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
// Created by Wonji Suh on 10/5/24.
66
//
77

8-
@_exported import OSLog
8+
@_exported @preconcurrency import OSLog

Sources/LogMacro/Macro/LogMacro.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The Swift Programming Language
22
// https://docs.swift.org/swift-book
33

4-
import OSLog
4+
@preconcurrency import OSLog
55

66
// MARK: - Stringify Macro
77

@@ -24,6 +24,7 @@ public macro stringify<T>(_ value: T) -> (T, String) =
2424
/// - message: 로그에 남길 주 메시지.
2525
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
2626
/// - Note: `os_log` 또는 `Logger` API를 호출하는 코드를 컴파일 시점에 삽입합니다.
27+
@available(iOS 13.0, macOS 10.15, *)
2728
@freestanding(expression)
2829
public macro logDebug(_ message: Any, _ arguments: Any...) =
2930
#externalMacro(module: "LogMacroMacro", type: "LogDebugMacro")
@@ -35,6 +36,7 @@ public macro logDebug(_ message: Any, _ arguments: Any...) =
3536
/// - Parameters:
3637
/// - message: 로그에 남길 주 메시지.
3738
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
39+
@available(iOS 13.0, macOS 10.15, *)
3840
@freestanding(expression)
3941
public macro logInfo(_ message: Any, _ arguments: Any...) =
4042
#externalMacro(module: "LogMacroMacro", type: "LogInfoMacro")
@@ -46,6 +48,7 @@ public macro logInfo(_ message: Any, _ arguments: Any...) =
4648
/// - Parameters:
4749
/// - message: 네트워크 이벤트 메시지.
4850
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
51+
@available(iOS 13.0, macOS 10.15, *)
4952
@freestanding(expression)
5053
public macro logNetwork(_ message: Any, _ arguments: Any...) =
5154
#externalMacro(module: "LogMacroMacro", type: "LogNetworkMacro")
@@ -57,6 +60,7 @@ public macro logNetwork(_ message: Any, _ arguments: Any...) =
5760
/// - Parameters:
5861
/// - message: 에러 메시지.
5962
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
63+
@available(iOS 13.0, macOS 10.15, *)
6064
@freestanding(expression)
6165
public macro logError(_ message: Any, _ arguments: Any...) =
6266
#externalMacro(module: "LogMacroMacro", type: "LogErrorMacro")
@@ -68,6 +72,7 @@ public macro logError(_ message: Any, _ arguments: Any...) =
6872
/// - Parameters:
6973
/// - message: 테스트 로그 메시지.
7074
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
75+
@available(iOS 13.0, macOS 10.15, *)
7176
@freestanding(expression)
7277
public macro logTest(_ message: Any, _ arguments: Any...) =
7378
#externalMacro(module: "LogMacroMacro", type: "LogTestMacro")
@@ -80,6 +85,7 @@ public macro logTest(_ message: Any, _ arguments: Any...) =
8085
/// - category: 커스텀 카테고리 식별자.
8186
/// - message: 로그에 남길 주 메시지.
8287
/// - arguments: 메시지 포맷에 전달할 추가 인자들.
88+
@available(iOS 13.0, macOS 10.15, *)
8389
@freestanding(expression)
8490
public macro logCustom(
8591
_ category: String,

Sources/LogMacroClient/main.swift

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@
66
//
77

88
import LogMacro
9-
import OSLog
9+
@preconcurrency import OSLog
1010

11-
// MARK: - LogMacro 사용 예시
11+
@available(iOS 13.0, macOS 10.15, *)
12+
func runLogMacroExamples() {
13+
// MARK: - LogMacro 사용 예시
1214

13-
/// `Log` 구조체 메서드를 직접 호출하는 예시
14-
Log.debug("Debug") // → OSLog.debug, .debug 타입으로 출력
15-
Log.network("Network") // → OSLog.network, .default 타입으로 출력
16-
Log.info("Info") // → OSLog.info, .info 타입으로 출력
17-
Log.error("Error") // → OSLog.error, .error 타입으로 출력
18-
Log.test("Test") // → OSLog.test, .debug 타입으로 출력
19-
Log.custom(category: "Network", "Request started")
20-
// → OSLog.debug(category: "🟢 Network"), .debug 타입으로 출력
15+
/// `Log` 구조체 메서드를 직접 호출하는 예시
16+
Log.debug("Debug") // → OSLog.debug, .debug 타입으로 출력
17+
Log.network("Network") // → OSLog.network, .default 타입으로 출력
18+
Log.info("Info") // → OSLog.info, .info 타입으로 출력
19+
Log.error("Error") // → OSLog.error, .error 타입으로 출력
20+
Log.test("Test") // → OSLog.test, .debug 타입으로 출력
21+
Log.custom(category: "Network", "Request started")
22+
// → OSLog.debug(category: "🟢 Network"), .debug 타입으로 출력
2123

22-
/// 매크로(`@freestanding`)를 사용해 컴파일 시점에 자동으로
23-
/// 호출 위치, 파일명, 라인 정보 등을 포함할 수 있는 예시
24-
#logDebug("Debug")
25-
#logNetwork("Network")
26-
#logInfo("Info")
27-
#logError("Error")
28-
#logTest("Test")
29-
#logCustom("Network", "Request started")
24+
/// 매크로(`@freestanding`)를 사용해 컴파일 시점에 자동으로
25+
/// 호출 위치, 파일명, 라인 정보 등을 포함할 수 있는 예시
26+
#logDebug("Debug")
27+
#logNetwork("Network")
28+
#logInfo("Info")
29+
#logError("Error")
30+
#logTest("Test")
31+
#logCustom("Network", "Request started")
32+
}
33+
34+
if #available(iOS 13.0, macOS 10.15, *) {
35+
runLogMacroExamples()
36+
} else {
37+
print("LogMacro requires iOS 13.0+ or macOS 10.15+")
38+
}

Sources/LogMacroMacro/LogMacroMacro.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import OSLog
2222
/// #logDebug("Value:", x, y)
2323
/// // → Log.debug("Value:", x, y)
2424
/// ```
25-
public struct LogDebugMacro: ExpressionMacro {
25+
public struct LogDebugMacro: ExpressionMacro, Sendable {
2626
public static func expansion(
2727
of node: some FreestandingMacroExpansionSyntax,
2828
in context: some MacroExpansionContext
@@ -49,7 +49,7 @@ public struct LogDebugMacro: ExpressionMacro {
4949
/// #logInfo("Started")
5050
/// // → Log.info("Started")
5151
/// ```
52-
public struct LogInfoMacro: ExpressionMacro {
52+
public struct LogInfoMacro: ExpressionMacro, Sendable {
5353
public static func expansion(
5454
of node: some FreestandingMacroExpansionSyntax,
5555
in context: some MacroExpansionContext
@@ -71,7 +71,7 @@ public struct LogInfoMacro: ExpressionMacro {
7171
/// `#logNetwork(...)` 매크로 확장.
7272
///
7373
/// - `Log.network(...)` 호출로 변환합니다.
74-
public struct LogNetworkMacro: ExpressionMacro {
74+
public struct LogNetworkMacro: ExpressionMacro, Sendable {
7575
public static func expansion(
7676
of node: some FreestandingMacroExpansionSyntax,
7777
in context: some MacroExpansionContext
@@ -93,7 +93,7 @@ public struct LogNetworkMacro: ExpressionMacro {
9393
/// `#logError(...)` 매크로 확장.
9494
///
9595
/// - `Log.error(...)` 호출로 변환합니다.
96-
public struct LogErrorMacro: ExpressionMacro {
96+
public struct LogErrorMacro: ExpressionMacro, Sendable {
9797
public static func expansion(
9898
of node: some FreestandingMacroExpansionSyntax,
9999
in context: some MacroExpansionContext
@@ -115,7 +115,7 @@ public struct LogErrorMacro: ExpressionMacro {
115115
/// `#logTest(...)` 매크로 확장.
116116
///
117117
/// - `Log.test(...)` 호출로 변환합니다.
118-
public struct LogTestMacro: ExpressionMacro {
118+
public struct LogTestMacro: ExpressionMacro, Sendable {
119119
public static func expansion(
120120
of node: some FreestandingMacroExpansionSyntax,
121121
in context: some MacroExpansionContext
@@ -137,7 +137,7 @@ public struct LogTestMacro: ExpressionMacro {
137137
/// `#logCustom(category:message:...)` 매크로 확장.
138138
///
139139
/// - `Log.custom(category: , ...)` 호출로 변환합니다.
140-
public struct LogCustomMacro: ExpressionMacro {
140+
public struct LogCustomMacro: ExpressionMacro, Sendable {
141141
/// `#logCustom(category: "Category", "Message", args...)` 매크로를 `Log.custom(...)` 호출로 변환합니다.
142142
///
143143
/// - Parameters:
@@ -153,11 +153,11 @@ public struct LogCustomMacro: ExpressionMacro {
153153
guard node.arguments.count >= 2 else {
154154
fatalError("compiler bug: the macro does not have enough arguments")
155155
}
156-
156+
157157
// 첫 번째 인자는 카테고리, 두 번째 인자는 메시지
158158
let category = node.arguments.first!.expression
159159
let message = node.arguments.dropFirst().first!.expression
160-
160+
161161
// 나머지 인자가 있으면 쉼표로 연결
162162
let arguments = node.arguments
163163
.dropFirst(2)

Sources/LogMacroMacro/Plugins.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftCompilerPlugin
99
import SwiftSyntaxMacros
1010

1111
@main
12-
struct MyMacroPlugin: CompilerPlugin {
12+
struct MyMacroPlugin: CompilerPlugin {
1313
let providingMacros: [Macro.Type] = [
1414
LogDebugMacro.self,
1515
LogInfoMacro.self,

0 commit comments

Comments
 (0)