File tree Expand file tree Collapse file tree 5 files changed +91
-1
lines changed
Expand file tree Collapse file tree 5 files changed +91
-1
lines changed Original file line number Diff line number Diff line change 1414
1515BUILD_CONFIGURATION ?= debug
1616WARNINGS_AS_ERRORS ?= true
17+ export GIT_COMMIT := $(shell git rev-parse HEAD)
18+ export GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null || echo "")
19+ export BUILD_TIME := $(shell date -u +% Y-% m-% dT% H:% M:% SZ)
1720SWIFT_WARNING_CONFIG := $(if $(filter-out false,$(WARNINGS_AS_ERRORS ) ) ,-Xswiftc -warnings-as-errors)
1821SWIFT_CONFIGURATION := --swift-sdk aarch64-swift-linux-musl $(SWIFT_WARNING_CONFIG ) -Xlinker -s --disable-automatic-resolution
1922
Original file line number Diff line number Diff line change 1717
1818// The swift-tools-version declares the minimum version of Swift required to build this package.
1919
20+ import Foundation
2021import PackageDescription
2122
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+
2227let package = Package (
2328 name: " swift-vminitd " ,
2429 platforms: [ . macOS( " 15 " ) ] ,
@@ -33,6 +38,14 @@ let package = Package(
3338 . package ( name: " containerization " , path: " ../ " ) ,
3439 ] ,
3540 targets: [
41+ . target(
42+ name: " CVersion " ,
43+ cSettings: [
44+ . define( " GIT_COMMIT " , to: " \" \( gitCommit) \" " ) ,
45+ . define( " GIT_TAG " , to: " \" \( gitTag) \" " ) ,
46+ . define( " BUILD_TIME " , to: " \" \( buildTime) \" " ) ,
47+ ]
48+ ) ,
3649 . target(
3750 name: " LCShim "
3851 ) ,
@@ -56,6 +69,7 @@ let package = Package(
5669 . product( name: " ContainerizationIO " , package : " containerization " ) ,
5770 . product( name: " ContainerizationOS " , package : " containerization " ) ,
5871 . product( name: " SystemPackage " , package : " swift-system " ) ,
72+ " CVersion " ,
5973 " LCShim " ,
6074 " Cgroup " ,
6175 ]
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright © 2026 Apple Inc. and the Containerization project authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ #ifndef CZ_VERSION_H
18+ #define CZ_VERSION_H
19+
20+ const char * CZ_get_git_commit (void );
21+ const char * CZ_get_git_tag (void );
22+ const char * CZ_get_build_time (void );
23+
24+ #endif
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright © 2026 Apple Inc. and the Containerization project authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ #include "version.h"
18+
19+ #ifndef GIT_COMMIT
20+ #define GIT_COMMIT "unspecified"
21+ #endif
22+
23+ #ifndef GIT_TAG
24+ #define GIT_TAG ""
25+ #endif
26+
27+ #ifndef BUILD_TIME
28+ #define BUILD_TIME "unspecified"
29+ #endif
30+
31+ const char * CZ_get_git_commit (void ) {
32+ return GIT_COMMIT ;
33+ }
34+
35+ const char * CZ_get_git_tag (void ) {
36+ return GIT_TAG ;
37+ }
38+
39+ const char * CZ_get_build_time (void ) {
40+ return BUILD_TIME ;
41+ }
Original file line number Diff line number Diff line change 1515//===----------------------------------------------------------------------===//
1616
1717import ArgumentParser
18+ import CVersion
1819import Cgroup
1920import Containerization
2021import ContainerizationError
@@ -67,7 +68,14 @@ struct AgentCommand: AsyncParsableCommand {
6768
6869 signal ( SIGPIPE, SIG_IGN)
6970
70- log. info ( " vminitd booting " , metadata: [ " version " : " \( Application . configuration. version) " ] )
71+ let gitCommit = String ( cString: CZ_get_git_commit ( ) )
72+ let gitTag = String ( cString: CZ_get_git_tag ( ) )
73+ let buildTime = String ( cString: CZ_get_build_time ( ) )
74+ var metadata : Logger . Metadata = [ " commit " : " \( gitCommit) " , " built " : " \( buildTime) " ]
75+ if !gitTag. isEmpty {
76+ metadata [ " tag " ] = " \( gitTag) "
77+ }
78+ log. info ( " vminitd booting " , metadata: metadata)
7179
7280 // Set of mounts necessary to be mounted prior to taking any RPCs.
7381 // 1. /proc as the sysctl rpc wouldn't make sense if it wasn't there (NOTE: This is done before this method
You can’t perform that action at this time.
0 commit comments