Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cmake #620

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .github/workflows/continuous-integration-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@ jobs:
- name: cargo check
run: cd test-vendored && cargo check

deny:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: recursive
- uses: EmbarkStudios/cargo-deny-action@v1
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "prost-build/third-party/protobuf"]
path = prost-build/third-party/protobuf
url = git@github.com:protocolbuffers/protobuf
url = https://github.com/protocolbuffers/protobuf
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prost"
version = "0.10.1"
version = "0.10.3"
authors = [
"Dan Burkert <dan@danburkert.com>",
"Tokio Contributors <team@tokio.rs>",
Expand Down
17 changes: 17 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[advisories]
ignore = [
# serde_cbor is unmaintained, but brought in by criterion
"RUSTSEC-2021-0127",
]

[licenses]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent here to impose Embark Studio’s deny configuration onto Prost?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't "our" deny configuration, this is just a way to ensure that the dependency this PR is removing doesn't return in the future.

allow = ["Apache-2.0", "MIT", "BSD-3-Clause"]

[bans]
deny = [{ name = "cmake" }]
skip = [
# old csv via old criterion
{ name = "itoa", version = "=0.4.8" },
# Proptest includes 2 version :(
{ name = "quick-error", version = "=1.2.3" },
]
4 changes: 2 additions & 2 deletions prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ lazy_static = "1.4.0"
regex = { version = "1.5.5", default-features = false, features = ["std", "unicode-bool"] }

[build-dependencies]
which = { version = "4", default-features = false }
cc = { version = "1.0", features = ["parallel"] }
cfg-if = "1"
cmake = "0.1"
which = { version = "4", default-features = false }

[dev-dependencies]
env_logger = { version = "0.8", default-features = false }
Expand Down
120 changes: 105 additions & 15 deletions prost-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! 2. The bundled Protobuf include directory.
//!

use cfg_if::cfg_if;
use std::env;
use std::path::PathBuf;
use which::which;
Expand Down Expand Up @@ -64,36 +63,126 @@ fn path_protoc() -> Option<PathBuf> {

/// Returns true if the vendored flag is enabled.
fn vendored() -> bool {
cfg_if! {
if #[cfg(feature = "vendored")] {
true
} else {
false
}
}
env::var("CARGO_FEATURE_VENDORED").is_ok()
}

/// Compile `protoc` via `cmake`.
fn compile() -> Option<PathBuf> {
let protobuf_src = bundle_path().join("protobuf").join("cmake");
/// Compile `protoc`. If stub is true, this won't do anything other than emit
/// the single function we need to link, this is needed if the `vendored`
/// feature is being used, but the user has also set the `PROTOC_NO_VENDOR` flag
/// so protoc will be used at runtime
fn compile(stub: bool) -> Option<PathBuf> {
let protobuf_src = bundle_path().join("protobuf/src/google/protobuf");

println!("cargo:rerun-if-changed={}", protobuf_src.display());

let dst = cmake::Config::new(protobuf_src).build();
// compile our protoc wrapper lib
{
let mut build = cc::Build::new();
build
.cpp(true)
// We _always_ want to build optmized, protoc code is far too slow otherwise
.opt_level_str("2");

// Disable all the compiler warnings for the protoc code we have no
// intention of changing
if !build.get_compiler().is_like_msvc() {
build
.flag("-std=c++11")
.flag("-Wno-unused-parameter")
.flag("-Wno-redundant-move")
.flag("-Wno-sign-compare")
.flag("-Wno-stringop-overflow");
}

Some(dst.join("bin").join("protoc"))
build.includes(&[bundle_path().join("protobuf/src")]);

if !stub {
build.files(
[
"any.cc",
"any_lite.cc",
"arena.cc",
"arenastring.cc",
"descriptor.cc",
"descriptor.pb.cc",
"descriptor_database.cc",
"dynamic_message.cc",
"extension_set.cc",
"extension_set_heavy.cc",
"implicit_weak_message.cc",
"map.cc",
"map_field.cc",
"message.cc",
"message_lite.cc",
"generated_message_reflection.cc",
"generated_message_util.cc",
"parse_context.cc",
"reflection_ops.cc",
"repeated_field.cc",
"repeated_ptr_field.cc",
"text_format.cc",
"unknown_field_set.cc",
"wire_format.cc",
"wire_format_lite.cc",
"compiler/importer.cc",
"compiler/parser.cc",
"io/coded_stream.cc",
"io/strtod.cc",
"io/tokenizer.cc",
"io/zero_copy_stream.cc",
"io/zero_copy_stream_impl.cc",
"io/zero_copy_stream_impl_lite.cc",
"stubs/common.cc",
"stubs/stringpiece.cc",
"stubs/stringprintf.cc",
"stubs/structurally_valid.cc",
"stubs/strutil.cc",
"stubs/substitute.cc",
]
.iter()
.map(|fname| protobuf_src.join(fname)),
);

if env::var("CARGO_CFG_TARGET_FAMILY").as_deref() == Ok("windows") {
build.files(
["io/io_win32.cc", "stubs/int128.cc", "stubs/status.cc"]
.iter()
.map(|fname| protobuf_src.join(fname)),
);
}
}

if stub {
build.define("STUB_ONLY", "1");
}

// This is our little wrapper that only does the 1 thing prost-build
// actually needs from the the bloated protoc binary
build.file("src/libprotoc.cpp");
build.compile("protoc");

println!("cargo:rerun-if-changed=src/libprotoc.cpp");
}

Some(PathBuf::from("linked"))
}

/// Try to find a `protoc` through a few methods.
///
/// Check module docs for more info.
fn protoc() -> Option<PathBuf> {
if env::var_os("PROTOC_NO_VENDOR").is_some() {
compile(true);
path_protoc()
} else if vendored() {
compile()
compile(false)
} else {
path_protoc().or_else(compile)
if let Some(path) = path_protoc() {
compile(true);
Some(path)
} else {
compile(false)
}
}
}

Expand All @@ -115,4 +204,5 @@ fn main() {
);
println!("cargo:rerun-if-env-changed=PROTOC");
println!("cargo:rerun-if-env-changed=PROTOC_INCLUDE");
println!("cargo:rerun-if-env-changed=PROTOC_NO_VENDOR");
}
Loading