Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
15 changes: 12 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
import Foundation
import PackageDescription

Expand Down Expand Up @@ -55,6 +56,7 @@ let package = Package(
.package(url: "https://github.com/orlandos-nl/DNSClient.git", from: "2.4.1"),
.package(url: "https://github.com/Bouke/DNS.git", from: "1.2.0"),
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "602.0.0"),
],
targets: [
.executableTarget(
Expand Down Expand Up @@ -259,6 +261,7 @@ let package = Package(
"ContainerPlugin",
"ContainerXPC",
"TerminalProgress",
"HelperMacros",
]
),
.testTarget(
Expand Down Expand Up @@ -373,5 +376,18 @@ let package = Package(
.define("BUILDER_SHIM_VERSION", to: "\"\(builderShimVersion)\""),
]
),
.macro(
name: "HelperMacrosMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),

// Library that exposes a macro as part of its API, which is used in client programs.
.target(
name: "HelperMacros",
dependencies: ["HelperMacrosMacros"]
),
]
)
7 changes: 7 additions & 0 deletions Sources/ContainerClient/Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
import ArgumentParser
import ContainerizationError
import Foundation
import HelperMacros

public struct Flags {
@OptionGroupPassthrough
public struct Global: ParsableArguments {
public init() {}

@Flag(name: .long, help: "Enable debug output [environment: CONTAINER_DEBUG]")
public var debug = false
}

@OptionGroupPassthrough
public struct Process: ParsableArguments {
public init() {}

Expand Down Expand Up @@ -63,6 +66,7 @@ public struct Flags {
public var cwd: String?
}

@OptionGroupPassthrough
public struct Resource: ParsableArguments {
public init() {}

Expand All @@ -76,6 +80,7 @@ public struct Flags {
public var memory: String?
}

@OptionGroupPassthrough
public struct Registry: ParsableArguments {
public init() {}

Expand All @@ -87,6 +92,7 @@ public struct Flags {
public var scheme: String = "auto"
}

@OptionGroupPassthrough
public struct Management: ParsableArguments {
public init() {}

Expand Down Expand Up @@ -201,6 +207,7 @@ public struct Flags {
public var virtualization: Bool = false
}

@OptionGroupPassthrough
public struct Progress: ParsableArguments {
public init() {}

Expand Down
28 changes: 28 additions & 0 deletions Sources/HelperMacros/HelperMacros.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the container project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

//
// HelperMacros.swift
// container
//
// Created by Morris Richman on 10/3/25.
//

import Foundation

/// Creates a function in OptionGroups called `passThroughCommands` to return an array of strings to be appended and passed down for Plugin support.
@attached(member, names: named(passThroughCommands))
public macro OptionGroupPassthrough() = #externalMacro(module: "HelperMacrosMacros", type: "OptionGroupPassthrough")
47 changes: 47 additions & 0 deletions Sources/HelperMacrosMacros/HelperMacrosMacros.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the container project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

//
// HelperMacrosMacros.swift
// container
//
// Created by Morris Richman on 10/3/25.
//

import SwiftCompilerPlugin
import SwiftDiagnostics
import SwiftSyntaxMacros

@main
struct SwiftMacrosAndMePlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
OptionGroupPassthrough.self
]
}

extension String: @retroactive Error {
}

enum MacroExpansionError: Error {
case unsupportedDeclaration

var localizedDescription: String {
switch self {
case .unsupportedDeclaration:
return "Unsupported declaration for macro expansion."
}
}
}
Loading