Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,26 @@ let defaultSwiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("MemberImportVisibility"),
]

extension Context {
fileprivate static var versionString: String {
guard let git = Self.gitInformation else { return "" }

if let tag = git.currentTag {
return tag
} else {
let suffix = git.hasUncommittedChanges ? " (modified)" : ""
return git.currentCommit + suffix
}
}
}

let targets: [Target] = [
// protoc plugin for grpc-swift
.executableTarget(
name: "protoc-gen-grpc-swift",
dependencies: [
.target(name: "GRPCProtobufCodeGen"),
.target(name: "CGRPCProtobuf"),
.product(name: "GRPCCodeGen", package: "grpc-swift"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
Expand Down Expand Up @@ -110,6 +124,13 @@ let targets: [Target] = [
swiftSettings: defaultSwiftSettings
),

.target(
name: "CGRPCProtobuf",
cSettings: [
.define("CGRPC_GRPC_SWIFT_PROTOBUF_VERSION", to: "\"\(Context.versionString)\"")
]
),

// Code generator build plugin
.plugin(
name: "GRPCProtobufGenerator",
Expand Down
21 changes: 21 additions & 0 deletions Sources/CGRPCProtobuf/CGRPCProtobuf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2025, gRPC Authors All rights reserved.
*
* 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
*
* http://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.
*/

#include "CGRPCProtobuf.h"

const char *cgrprc_grpc_swift_protobuf_version() {
return CGRPC_GRPC_SWIFT_PROTOBUF_VERSION;
}
22 changes: 22 additions & 0 deletions Sources/CGRPCProtobuf/include/CGRPCProtobuf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2025, gRPC Authors All rights reserved.
*
* 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
*
* http://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.
*/

#ifndef CGRPC_PROTOBUF_H_
#define CGRPC_PROTOBUF_H_

const char *cgrprc_grpc_swift_protobuf_version();

#endif // CGRPC_PROTOBUF_H_
21 changes: 3 additions & 18 deletions Sources/protoc-gen-grpc-swift/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@
* limitations under the License.
*/

internal enum Version {
/// The major version.
internal static let major = 1

/// The minor version.
internal static let minor = 0

/// The patch version.
internal static let patch = 0

/// Any additional label.
internal static let label = "development"
private import CGRPCProtobuf

internal enum Version {
/// The version string.
internal static var versionString: String {
let version = "\(Self.major).\(Self.minor).\(Self.patch)"
if Self.label.isEmpty {
return version
} else {
return version + "-" + Self.label
}
String(cString: cgrprc_grpc_swift_protobuf_version())
}
}
Loading