You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/08/15 03:24:19 UTC

[skywalking-rust] branch master updated: Add feature vendored, to auto build protoc. (#43)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new 4d786ff  Add feature vendored, to auto build protoc. (#43)
4d786ff is described below

commit 4d786ff5236caca11ff96cb8b0a0c9afda66bd0f
Author: jmjoy <jm...@apache.org>
AuthorDate: Mon Aug 15 11:24:15 2022 +0800

    Add feature vendored, to auto build protoc. (#43)
---
 .github/workflows/ci.yaml |  2 ++
 Cargo.toml                |  2 ++
 README.md                 | 34 ++++++++++++++++++++++++++++++++++
 build.rs                  |  3 +++
 4 files changed, 41 insertions(+)

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 577121e..27f4355 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -75,6 +75,7 @@ jobs:
       matrix:
         features:
           - ""
+          - "--features vendored"
           - "--all-features"
     runs-on: ubuntu-20.04
     steps:
@@ -83,6 +84,7 @@ jobs:
           submodules: 'recursive'
       - name: Install protoc
         run: sudo apt-get install -y protobuf-compiler=3.6.1.3-2ubuntu5
+        if: ${{ matrix.features != '--features vendored' }}
       - name: Install Rust toolchain
         run: rustup toolchain install stable --component clippy
       - name: Run check
diff --git a/Cargo.toml b/Cargo.toml
index 1ccc728..aef34c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,6 +33,7 @@ homepage = "https://skywalking.apache.org/"
 repository = "https://github.com/apache/skywalking-rust"
 
 [features]
+vendored = ["protobuf-src"]
 mock = []  # For internal integration testing only, do not use.
 
 [dependencies]
@@ -52,6 +53,7 @@ tracing = "0.1.36"
 uuid = { version = "1.1.2", features = ["serde", "v4"] }
 
 [build-dependencies]
+protobuf-src = { version = "1.0.5", optional = true }
 tonic-build = "0.8.0"
 
 [dev-dependencies]
diff --git a/README.md b/README.md
index 169b391..7cf924a 100644
--- a/README.md
+++ b/README.md
@@ -131,6 +131,40 @@ Using `cargo build` generates a library. If you'd like to verify the behavior, w
 use `cargo run --example simple_trace_report`
 which outputs executable, then run it.
 
+## NOTICE
+
+This crate automatically generates protobuf related code, which requires `protoc` before compile.
+
+Please choose one of the ways to install `protoc`.
+
+1. Using your OS package manager.
+
+   For Debian-base system:
+
+   ```shell
+   sudo apt install protobuf-compiler
+   ```
+
+   For MacOS:
+
+   ```shell
+   brew install protobuf
+   ```
+
+2. Auto compile `protoc` in the crate build script, just by adding the feature `vendored` in the `Cargo.toml`:
+
+   ```shell
+   cargo add skywalking --features vendored
+   ```
+
+3. Build from [source](https://github.com/protocolbuffers/protobuf). If `protc` isn't install inside $PATH, the env value `PROTOC` should be set.
+
+   ```shell
+   PROTOC=/the/path/of/protoc
+   ```
+
+For details, please refer to [prost-build:sourcing-protoc](https://docs.rs/prost-build/latest/prost_build/index.html#sourcing-protoc).
+
 # Release
 
 The SkyWalking committer(PMC included) could follow [this doc](Release-guide.md) to release an official version.
diff --git a/build.rs b/build.rs
index bd5da88..fa64567 100644
--- a/build.rs
+++ b/build.rs
@@ -15,6 +15,9 @@
 //
 
 fn main() -> Result<(), Box<dyn std::error::Error>> {
+    #[cfg(feature = "vendored")]
+    std::env::set_var("PROTOC", protobuf_src::protoc());
+
     tonic_build::configure()
         .build_server(false)
         .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")