From 9c8f193ef1ed333d558c5658cd36ef2b5fbbf31d Mon Sep 17 00:00:00 2001 From: Guillaume Pinot Date: Fri, 10 Sep 2021 20:38:28 +0200 Subject: [PATCH] Don't depend on or-tools for docs.rs --- Cargo.toml | 8 ++++++++ build.rs | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d854faa..c38120b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,10 @@ keywords = ["constraint", "programming", "CP"] categories = ["api-bindings", "mathematics", "science"] readme = "README.md" +[features] +# the doc feature will not build C++ wrappers (not needed by the doc) +doc = [] + [dependencies] prost = "0.8" bytes = "1.1.0" @@ -18,3 +22,7 @@ libc = "0.2.101" [build-dependencies] prost-build = { version = "0.8" } cc = "1.0" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +features = ["doc"] diff --git a/build.rs b/build.rs index 1b6dd98..3636e6b 100644 --- a/build.rs +++ b/build.rs @@ -7,16 +7,18 @@ fn main() { ) .unwrap(); - let ortools_prefix = std::env::var("ORTOOLS_PREFIX") - .ok() - .unwrap_or("/opt/ortools".into()); - cc::Build::new() - .cpp(true) - .flag("-std=c++17") - .file("src/cp_sat_wrapper.cpp") - .include(&[&ortools_prefix, "/include"].concat()) - .compile("cp_sat_wrapper.a"); + if !std::env::var("CARGO_FEATURE_DOC").is_ok() { + let ortools_prefix = std::env::var("ORTOOLS_PREFIX") + .ok() + .unwrap_or("/opt/ortools".into()); + cc::Build::new() + .cpp(true) + .flag("-std=c++17") + .file("src/cp_sat_wrapper.cpp") + .include(&[&ortools_prefix, "/include"].concat()) + .compile("cp_sat_wrapper.a"); - println!("cargo:rustc-link-lib=dylib=ortools"); - println!("cargo:rustc-link-search=native={}/lib", ortools_prefix); + println!("cargo:rustc-link-lib=dylib=ortools"); + println!("cargo:rustc-link-search=native={}/lib", ortools_prefix); + } }