Skip to content

Commit c8fe3bb

Browse files
authored
Move the VminitdCore library to the top-level package (#742)
External Swift Package Manager consumers can only see products declared in the top-level `Package.swift`. The `VminitdCore` library was declared inside the `vminitd` subpackage, so it was impossible to build a custom `vminitd` against it via a URL dependency on `containerization`. This change moves the `VminitdCore` to the top-level `Package.swift`.
1 parent db5b5b9 commit c8fe3bb

29 files changed

Lines changed: 164 additions & 79 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ xcuserdata/
77
DerivedData/
88
.swiftpm/
99
.netrc
10-
.swiftpm
1110
workdir/
1211
installer/
1312
.venv/

Package.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import CompilerPluginSupport
2121
import Foundation
2222
import PackageDescription
2323

24+
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
25+
let gitTag = ProcessInfo.processInfo.environment["GIT_TAG"] ?? ""
26+
let buildTime = ProcessInfo.processInfo.environment["BUILD_TIME"] ?? "unspecified"
27+
2428
let package = Package(
2529
name: "containerization",
2630
platforms: [.macOS("15.0")],
@@ -33,6 +37,7 @@ let package = Package(
3337
.library(name: "ContainerizationOS", targets: ["ContainerizationOS"]),
3438
.library(name: "ContainerizationExtras", targets: ["ContainerizationExtras"]),
3539
.library(name: "ContainerizationArchive", targets: ["ContainerizationArchive"]),
40+
.library(name: "VminitdCore", targets: ["VminitdCore", "Cgroup", "LCShim"]),
3641
.executable(name: "cctl", targets: ["cctl"]),
3742
],
3843
dependencies: [
@@ -259,6 +264,50 @@ let package = Package(
259264
.target(
260265
name: "CShim"
261266
),
267+
.target(
268+
name: "CVersion",
269+
path: "vminitd/Sources/CVersion",
270+
cSettings: [
271+
.define("GIT_COMMIT", to: "\"\(gitCommit)\""),
272+
.define("GIT_TAG", to: "\"\(gitTag)\""),
273+
.define("BUILD_TIME", to: "\"\(buildTime)\""),
274+
]
275+
),
276+
.target(
277+
name: "LCShim",
278+
path: "vminitd/Sources/LCShim"
279+
),
280+
.target(
281+
name: "Cgroup",
282+
dependencies: [
283+
.product(name: "Logging", package: "swift-log"),
284+
"ContainerizationOCI",
285+
"ContainerizationOS",
286+
.product(name: "SystemPackage", package: "swift-system"),
287+
"LCShim",
288+
],
289+
path: "vminitd/Sources/Cgroup"
290+
),
291+
.target(
292+
name: "VminitdCore",
293+
dependencies: [
294+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
295+
.product(name: "Logging", package: "swift-log"),
296+
"Containerization",
297+
"ContainerizationArchive",
298+
"ContainerizationNetlink",
299+
"ContainerizationIO",
300+
"ContainerizationOS",
301+
.product(name: "SystemPackage", package: "swift-system"),
302+
.product(name: "GRPCCore", package: "grpc-swift-2"),
303+
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
304+
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
305+
"LCShim",
306+
"CVersion",
307+
"Cgroup",
308+
],
309+
path: "vminitd/Sources/VminitdCore"
310+
),
262311
]
263312
)
264313

vminitd/Package.swift

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,79 +17,29 @@
1717

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

20-
import Foundation
2120
import PackageDescription
2221

23-
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
24-
let gitTag = ProcessInfo.processInfo.environment["GIT_TAG"] ?? ""
25-
let buildTime = ProcessInfo.processInfo.environment["BUILD_TIME"] ?? "unspecified"
26-
2722
let package = Package(
2823
name: "swift-vminitd",
2924
platforms: [.macOS("15")],
3025
products: [
31-
.library(name: "VminitdCore", targets: ["VminitdCore"]),
3226
.executable(name: "vminitd", targets: ["vminitd"]),
3327
.executable(name: "vmexec", targets: ["vmexec"]),
3428
],
3529
dependencies: [
3630
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"),
3731
.package(url: "https://github.com/apple/swift-log.git", from: "1.10.1"),
38-
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.36.0"),
3932
.package(url: "https://github.com/apple/swift-system.git", from: "1.6.4"),
40-
.package(url: "https://github.com/grpc/grpc-swift-2.git", from: "2.3.0"),
41-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "2.4.4"),
42-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "2.2.0"),
4333
.package(name: "containerization", path: "../"),
4434
],
4535
targets: [
46-
.target(
47-
name: "CVersion",
48-
cSettings: [
49-
.define("GIT_COMMIT", to: "\"\(gitCommit)\""),
50-
.define("GIT_TAG", to: "\"\(gitTag)\""),
51-
.define("BUILD_TIME", to: "\"\(buildTime)\""),
52-
]
53-
),
54-
.target(
55-
name: "LCShim"
56-
),
57-
.target(
58-
name: "Cgroup",
59-
dependencies: [
60-
.product(name: "Logging", package: "swift-log"),
61-
.product(name: "ContainerizationOCI", package: "containerization"),
62-
.product(name: "ContainerizationOS", package: "containerization"),
63-
.product(name: "SystemPackage", package: "swift-system"),
64-
"LCShim",
65-
]
66-
),
67-
.target(
68-
name: "VminitdCore",
69-
dependencies: [
70-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
71-
.product(name: "Logging", package: "swift-log"),
72-
.product(name: "Containerization", package: "containerization"),
73-
.product(name: "ContainerizationArchive", package: "containerization"),
74-
.product(name: "ContainerizationNetlink", package: "containerization"),
75-
.product(name: "ContainerizationIO", package: "containerization"),
76-
.product(name: "ContainerizationOS", package: "containerization"),
77-
.product(name: "SystemPackage", package: "swift-system"),
78-
.product(name: "GRPCCore", package: "grpc-swift-2"),
79-
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
80-
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
81-
"LCShim",
82-
"CVersion",
83-
"Cgroup",
84-
]
85-
),
8636
.executableTarget(
8737
name: "vminitd",
8838
dependencies: [
8939
.product(name: "ArgumentParser", package: "swift-argument-parser"),
9040
.product(name: "ContainerizationOS", package: "containerization"),
9141
.product(name: "Logging", package: "swift-log"),
92-
"VminitdCore",
42+
.product(name: "VminitdCore", package: "containerization"),
9343
]
9444
),
9545
.executableTarget(
@@ -100,8 +50,7 @@ let package = Package(
10050
.product(name: "SystemPackage", package: "swift-system"),
10151
.product(name: "Containerization", package: "containerization"),
10252
.product(name: "ContainerizationOS", package: "containerization"),
103-
"LCShim",
104-
"Cgroup",
53+
.product(name: "VminitdCore", package: "containerization"),
10554
]
10655
),
10756
]

vminitd/Sources/Cgroup/Cgroup2Manager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
#if os(Linux)
18+
1719
// NOTE: Ideally this should live in ContainerizationOS/Linux, or just ContainerizationCgroups
1820
// or something similar, but it's not there yet. It does what we need, but it'd need a lot more
1921
// features and testing before it's ready to be public.
2022

21-
#if os(Linux)
22-
2323
#if canImport(Musl)
2424
import Musl
2525
#elseif canImport(Glibc)
@@ -43,8 +43,8 @@ package enum Cgroup2Controller: String {
4343

4444
// Extremely simple cgroup manager. Our needs are simple for now, and this is
4545
// reflected in the type.
46-
package struct Cgroup2Manager: Sendable {
47-
package static let defaultMountPoint = URL(filePath: "/sys/fs/cgroup")
46+
public struct Cgroup2Manager: Sendable {
47+
public static let defaultMountPoint = URL(filePath: "/sys/fs/cgroup")
4848

4949
private static let killFile = "cgroup.kill"
5050
private static let procsFile = "cgroup.procs"
@@ -66,7 +66,7 @@ package struct Cgroup2Manager: Sendable {
6666
self.logger = logger
6767
}
6868

69-
package static func load(
69+
public static func load(
7070
mountPoint: URL = Self.defaultMountPoint,
7171
group: URL,
7272
logger: Logger? = nil
@@ -183,7 +183,7 @@ package struct Cgroup2Manager: Sendable {
183183
}
184184
}
185185

186-
package func addProcess(pid: Int32) throws {
186+
public func addProcess(pid: Int32) throws {
187187
self.logger?.debug(
188188
"adding new proc to cgroup",
189189
metadata: [
@@ -199,7 +199,7 @@ package struct Cgroup2Manager: Sendable {
199199
)
200200
}
201201

202-
package func applyResources(resources: ContainerizationOCI.LinuxResources) throws {
202+
public func applyResources(resources: ContainerizationOCI.LinuxResources) throws {
203203
self.logger?.debug(
204204
"applying cgroup resources",
205205
metadata: [

vminitd/Sources/LCShim/include/syscall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#define __SYSCALL_H
2323

2424
#include <sys/types.h>
25+
#ifdef __linux__
2526
#include <sys/vfs.h>
27+
#endif
2628

2729
// CLONE_* flags
2830
#ifndef CLONE_NEWNS

vminitd/Sources/LCShim/syscall.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
#ifdef __linux__
1718
#include <sys/prctl.h>
1819
#include <sys/resource.h>
1920
#include <sys/syscall.h>
@@ -48,3 +49,4 @@ int CZ_setrlimit(int resource, unsigned long long soft,
4849
limit.rlim_max = (rlim_t)hard;
4950
return setrlimit(resource, &limit);
5051
}
52+
#endif

vminitd/Sources/VminitdCore/AgentCommand.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
#if os(Linux)
18+
1719
import ArgumentParser
1820
import CVersion
1921
import Cgroup
@@ -44,7 +46,7 @@ public struct AgentCommand: AsyncParsableCommand {
4446
private static let foregroundEnvVar = "FOREGROUND"
4547
public static let vsockPort = 1024
4648

47-
@OptionGroup public var options: LogLevelOption
49+
@OptionGroup var options: LogLevelOption
4850

4951
public init() {}
5052

@@ -214,3 +216,5 @@ public struct AgentCommand: AsyncParsableCommand {
214216
}
215217
}
216218
}
219+
220+
#endif

vminitd/Sources/VminitdCore/CommandRunner.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
#if os(Linux)
18+
1719
import ContainerizationOS
1820
import Foundation
1921
import Synchronization
@@ -102,3 +104,5 @@ final class ReaperCommandRunner: CommandRunner, Sendable {
102104
}
103105
}
104106
}
107+
108+
#endif

vminitd/Sources/VminitdCore/ContainerProcess.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
#if os(Linux)
18+
1719
import ContainerizationOS
1820
import Foundation
1921

@@ -64,3 +66,5 @@ protocol ContainerProcess: Sendable {
6466
/// Set the exit status of the process.
6567
func setExit(_ status: Int32)
6668
}
69+
70+
#endif

vminitd/Sources/VminitdCore/HostStdio.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
#if os(Linux)
18+
1719
struct HostStdio: Sendable {
1820
let stdin: UInt32?
1921
let stdout: UInt32?
2022
let stderr: UInt32?
2123
let terminal: Bool
2224
}
25+
26+
#endif

0 commit comments

Comments
 (0)