Skip to content

Commit d9b5492

Browse files
committed
make default goal compile on Linux
To be able to test vminitd/vmexec/linux specific packages on ci it'd be a heck of a lot easier if `make` just worked. This should be the last bit needed. The default goal currently compiles just fine after the linux specific `make deps` is ran. Next in line would be adding decent unit tests/actually getting ci setup for the linux bits.
1 parent 586385f commit d9b5492

11 files changed

Lines changed: 68 additions & 38 deletions

File tree

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ KATA_BINARY_PACKAGE := https://github.com/kata-containers/kata-containers/releas
4040
include Protobuf.Makefile
4141
.DEFAULT_GOAL := all
4242

43+
.PHONY: deps
44+
deps:
45+
ifeq ($(UNAME_S),Linux)
46+
sudo apt-get install -y libarchive-dev libbz2-dev liblzma-dev libssl-dev
47+
else
48+
@echo "No additional dependencies required on $(UNAME_S)"
49+
endif
50+
4351
.PHONY: all
4452
all: containerization
4553
all: init
@@ -57,11 +65,13 @@ containerization:
5765
@echo Copying containerization binaries...
5866
@mkdir -p bin
5967
@install "$(BUILD_BIN_DIR)/cctl" ./bin/
68+
ifeq ($(UNAME_S),Darwin)
6069
@install "$(BUILD_BIN_DIR)/containerization-integration" ./bin/
6170

6271
@echo Signing containerization binaries...
6372
@codesign --force --sign - --timestamp=none --entitlements=signing/vz.entitlements bin/cctl
6473
@codesign --force --sign - --timestamp=none --entitlements=signing/vz.entitlements bin/containerization-integration
74+
endif
6575

6676
.PHONY: init
6777
init: containerization vminitd

Package.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,6 @@ let package = Package(
8484
"ContainerizationOS",
8585
]
8686
),
87-
.executableTarget(
88-
name: "containerization-integration",
89-
dependencies: [
90-
.product(name: "Logging", package: "swift-log"),
91-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
92-
"Containerization",
93-
],
94-
path: "Sources/Integration"
95-
),
9687
.testTarget(
9788
name: "ContainerizationUnitTests",
9889
dependencies: ["Containerization"],
@@ -266,3 +257,17 @@ let package = Package(
266257
),
267258
]
268259
)
260+
261+
#if os(macOS)
262+
package.targets.append(
263+
.executableTarget(
264+
name: "containerization-integration",
265+
dependencies: [
266+
.product(name: "Logging", package: "swift-log"),
267+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
268+
"Containerization",
269+
],
270+
path: "Sources/Integration"
271+
)
272+
)
273+
#endif

Sources/Containerization/Image/Unpacker/EXT4Unpacker.swift

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

17+
import ContainerizationArchive
18+
import ContainerizationEXT4
1719
import ContainerizationError
1820
import ContainerizationExtras
1921
import ContainerizationOCI
2022
import Foundation
21-
22-
#if os(macOS)
23-
import ContainerizationArchive
24-
import ContainerizationEXT4
2523
import SystemPackage
26-
#endif
2724

2825
public struct EXT4Unpacker: Unpacker {
2926
let blockSizeInBytes: UInt64
@@ -32,7 +29,6 @@ public struct EXT4Unpacker: Unpacker {
3229
self.blockSizeInBytes = blockSizeInBytes
3330
}
3431

35-
#if os(macOS)
3632
/// Performs the unpacking of a tar archive into a filesystem.
3733
/// - Parameters:
3834
/// - archive: The archive to unpack.
@@ -56,7 +52,6 @@ public struct EXT4Unpacker: Unpacker {
5652
compression: compression
5753
)
5854
}
59-
#endif
6055

6156
/// Returns a `Mount` point after unpacking the image into a filesystem.
6257
/// - Parameters:
@@ -70,9 +65,6 @@ public struct EXT4Unpacker: Unpacker {
7065
at path: URL,
7166
progress: ProgressHandler? = nil
7267
) async throws -> Mount {
73-
#if !os(macOS)
74-
throw ContainerizationError(.unsupported, message: "cannot unpack an image on current platform")
75-
#else
7668
let cleanedPath = try prepareUnpackPath(path: path)
7769
let manifest = try await image.manifest(for: platform)
7870
let filesystem = try EXT4.Formatter(
@@ -144,7 +136,6 @@ public struct EXT4Unpacker: Unpacker {
144136
destination: "/",
145137
options: []
146138
)
147-
#endif
148139
}
149140

150141
private func prepareUnpackPath(path: URL) throws -> String {
@@ -155,7 +146,6 @@ public struct EXT4Unpacker: Unpacker {
155146
return blockPath
156147
}
157148

158-
#if os(macOS)
159149
private func compressionFilter(for mediaType: String) throws -> ContainerizationArchive.Filter {
160150
switch mediaType {
161151
case MediaTypes.imageLayer, MediaTypes.dockerImageLayer:
@@ -168,5 +158,4 @@ public struct EXT4Unpacker: Unpacker {
168158
throw ContainerizationError(.unsupported, message: "media type \(mediaType) not supported.")
169159
}
170160
}
171-
#endif
172161
}

Sources/Integration/ContainerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,12 +1294,12 @@ extension IntegrationSuite {
12941294
config.stderr = stderrBuffer
12951295
}
12961296

1297-
let started = CFAbsoluteTimeGetCurrent()
1297+
let started = Date().timeIntervalSinceReferenceDate
12981298

12991299
try await exec.start()
13001300
let status = try await exec.wait()
13011301

1302-
let lasted = CFAbsoluteTimeGetCurrent() - started
1302+
let lasted = Date().timeIntervalSinceReferenceDate - started
13031303
print("Test \(id) finished process ingesting stdio in \(lasted)")
13041304

13051305
guard status.exitCode == 0 else {

Sources/Integration/Suite.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ struct IntegrationSuite: AsyncParsableCommand {
282282
// Hopefully this improves over time.
283283
func run() async throws {
284284
try Self.adjustLimits()
285-
let suiteStarted = CFAbsoluteTimeGetCurrent()
285+
let suiteStarted = Date().timeIntervalSinceReferenceDate
286286
log.info("starting integration suite\n")
287287

288288
let tests: [Test] =
@@ -439,9 +439,9 @@ struct IntegrationSuite: AsyncParsableCommand {
439439
do {
440440
log.info("test \(job.name) started...")
441441

442-
let started = CFAbsoluteTimeGetCurrent()
442+
let started = Date().timeIntervalSinceReferenceDate
443443
try await job.work()
444-
let lasted = CFAbsoluteTimeGetCurrent() - started
444+
let lasted = Date().timeIntervalSinceReferenceDate - started
445445

446446
log.info("✅ test \(job.name) complete in \(lasted)s.")
447447
passed.add(1, ordering: .relaxed)
@@ -460,7 +460,7 @@ struct IntegrationSuite: AsyncParsableCommand {
460460
let passedCount = passed.load(ordering: .acquiring)
461461
let skippedCount = skipped.load(ordering: .acquiring)
462462

463-
let ended = CFAbsoluteTimeGetCurrent() - suiteStarted
463+
let ended = Date().timeIntervalSinceReferenceDate - suiteStarted
464464
var finishingText = "\n\nIntegration suite completed in \(ended)s with \(passedCount)/\(filteredTests.count) passed"
465465
if skipped.load(ordering: .acquiring) > 0 {
466466
finishingText += " and \(skippedCount)/\(filteredTests.count) skipped"

Sources/cctl/ImageCommand.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ContainerizationExtras
2222
import ContainerizationOCI
2323
import Foundation
2424

25+
#if os(macOS)
2526
extension Application {
2627
struct Images: AsyncParsableCommand {
2728
static let configuration = CommandConfiguration(
@@ -292,3 +293,4 @@ extension Application {
292293
}
293294
}
294295
}
296+
#endif

Sources/cctl/LoginCommand.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import ContainerizationExtras
2121
import ContainerizationOCI
2222
import Foundation
2323

24+
#if os(macOS)
2425
extension Application {
2526
struct Login: AsyncParsableCommand {
2627

@@ -84,3 +85,4 @@ extension Application {
8485
}
8586
}
8687
}
88+
#endif

Sources/cctl/RunCommand.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ContainerizationOCI
2222
import ContainerizationOS
2323
import Foundation
2424

25+
#if os(macOS)
2526
extension Application {
2627
struct Run: AsyncParsableCommand {
2728
static let configuration = CommandConfiguration(
@@ -192,3 +193,4 @@ extension Application {
192193
}()
193194
}
194195
}
196+
#endif

Sources/cctl/cctl.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ struct Application: AsyncParsableCommand {
6161
commandName: "cctl",
6262
abstract: "Utility CLI for Containerization",
6363
version: "2.0.0",
64-
subcommands: [
65-
Images.self,
66-
Login.self,
67-
Rootfs.self,
68-
Run.self,
69-
]
64+
subcommands: {
65+
var commands: [any ParsableCommand.Type] = [
66+
Rootfs.self
67+
]
68+
#if os(macOS)
69+
commands += [
70+
Images.self,
71+
Login.self,
72+
Run.self,
73+
]
74+
#endif
75+
return commands
76+
}()
7077
)
7178
}
7279

Tests/ContainerizationExtrasTests/TestIPv6Address+Parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct IPv6AddressParseTests {
161161
let testInput = "FFFF"
162162

163163
// Measure performance of parsing operation
164-
let startTime = CFAbsoluteTimeGetCurrent()
164+
let startTime = Date().timeIntervalSinceReferenceDate
165165
let count = 10000
166166
for _ in 0..<count {
167167
let utf8 = testInput.utf8
@@ -171,7 +171,7 @@ struct IPv6AddressParseTests {
171171
)
172172
}
173173

174-
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
174+
let timeElapsed = Date().timeIntervalSinceReferenceDate - startTime
175175

176176
// Expect parsing to be reasonably fast (less than 1ms per operation on average)
177177
print("Parsed \(count) IPv6 addresses in \(timeElapsed)s")

0 commit comments

Comments
 (0)