Proto2swift requires github-apple /swift-protobuf: Plugin and Runtime library for using protobuf with Swift

Protoc-gen-swift compilation plug-in needs to be generated in different system environments, and Swift needs to be installed in Linux compilation.

Install the Swift,

The following are the steps for installing SWIFT in centos: Firstly, download the compiled binary package of release version from swift official website

Decompress and configure the path to the environment variable

PATH = $PATH: / usr/local/swift/swift - 5.3.3 - RELEASE - centos7 / usr/bin export PATHCopy the code

Check whether swift is configured successfully

swift -version
#If the output content is similar to the following, it is successful
#Swift version 5.3.3 (Swift - 5.3.3 - RELEASE)
# Target: x86_64-unknown-linux-gnu
Copy the code

Build protoc-gen-Swift plugin

Pull swift-Protobuf project and perform the build

git clone https://github.com/apple/swift-protobuf
swift build -c release
Copy the code

Protoc-gen-swift file will be generated in the.build/release directory after successful execution, and protoc-gen-swift will be configured to environment variables.

conversion

Perform the transformation and output the.swift file

protoc --swift_out=. my.proto
Copy the code