Crates.io | protoc-prebuilt |
lib.rs | protoc-prebuilt |
version | 0.3.0 |
source | src |
created_at | 2023-02-22 13:59:37.811404 |
updated_at | 2024-03-05 23:58:58.29517 |
description | Protobuf compiler protoc pre-built binaries installer |
homepage | |
repository | https://github.com/sergeiivankov/protoc-prebuilt |
max_upload_size | |
id | 791822 |
size | 48,942 |
Protobuf compiler protoc
pre-built binaries installer.
Installed binaries stored in OUT_DIR
of the crate using the library.
Library export init
function which takes version
parameter. Version parameter should be a tag name from protobuf repository without v
prefix, for example, "21.12" or "22.0-rc3" (see protobuf repository tags). Function return a tuple contains paths to protoc
binary and include
directory.
In next examples provided build.rs
script content for different generators. For example, we have next simplified project structure with protobuf files:
src/
proto/
apple.proto
orange.proto
build.rs
With prost-build:
use prost_build::compile_protos;
use protoc_prebuilt::init;
use std::env::set_var;
fn main() {
let (protoc_bin, _) = init("22.0").unwrap();
set_var("PROTOC", protoc_bin);
compile_protos(
&["src/proto/apple.proto", "src/proto/orange.proto"],
&["src/proto"]
).unwrap();
}
With protobuf-codegen:
use protobuf_codegen::Codegen;
use protoc_prebuilt::init;
use std::env::set_var;
fn main() {
let (protoc_bin, _) = init("22.0").unwrap();
Codegen::new()
.protoc()
.protoc_path(&protoc_bin)
.includes(&["src/proto"])
.inputs(&["src/proto/apple.proto", "src/proto/orange.proto"])
.cargo_out_dir("proto")
.run_from_script();
}
To avoid GitHub API limits library add Authorization
header to requests to API with GITHUB_TOKEN
environment variable content.
To prevent this behavior, set PROTOC_PREBUILT_NOT_ADD_GITHUB_TOKEN
environment variable to any value reduced to true
(see var_bool
function in sources).
To force this library to use autorization token from another environment variable, set its name to PROTOC_PREBUILT_GITHUB_TOKEN_ENV_NAME
environment variable.
If you have custom protobuf installation and need to use this installed version, use next environment variables to change default behavior:
PROTOC_PREBUILT_FORCE_PROTOC_PATH
to set force use path to protoc
binary from value of this variable, if it variable exists, protoc-prebuilt
not download protobuf from GitHub;
PROTOC_PREBUILT_FORCE_INCLUDE_PATH
to set force use path to includes
directory from value of this variable, if it variable not exists, protoc-prebuilt
calculate path to includes
directory himself from protoc
binary path depending on version (see get_include_path
function in sources).
For setup HTTP proxy protoc-prebuilt
use environment variables same as curl does it. Library use HTTP_PROXY
, HTTPS_PROXY
and them lowercase analogues.
To disable proxy usage with curl
agreement you can add github.com
(to bypass proxy in asset downloading), api.github.com
(to bypass proxy in version exists cheking), .github.com
(to bypass proxy in both variants) to NO_PROXY
or no_proxy
environment variable.
To disable any use of proxy in protoc-prebuilt
set PROTOC_PREBUILT_NOT_USE_PROXY
environment variable to any value reduced to true
(see var_bool
function in sources).
After installation protoc-prebuilt
run protoc
binary with "--version" argument and compare result with required version. It need to make sure the installation is correct and check version of custom protobuf installation.
If you need disable this behavior, set PROTOC_PREBUILT_NOT_CHECK_VERSION
environment variable to any value reduced to true
(see var_bool
function in sources).
windows
target and compilers versions hardcoded, so you can't use specify version.