Skip to content

Commit

Permalink
Update lib.rs
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
  • Loading branch information
FedericoBruzzone committed Jun 20, 2024
1 parent 22643c7 commit 9ba6ebc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
62 changes: 32 additions & 30 deletions tdlib-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,41 +206,43 @@ fn download_tdlib() {
}

fn main() -> std::io::Result<()> {
#[cfg(all(feature = "docs", feature = "pkg-config"))]
compile_error!(
"feature \"docs\" and feature \"pkg-config\" cannot be enabled at the same time"
);
#[cfg(all(feature = "docs", feature = "download-tdlib"))]
compile_error!(
"feature \"docs\" and feature \"download-tdlib\" cannot be enabled at the same time"
);
#[cfg(all(feature = "pkg-config", feature = "download-tdlib"))]
compile_error!(
"feature \"pkg-config\" and feature \"download-tdlib\" cannot be enabled at the same time"
);
if cfg!(debug_assertions) {
#[cfg(all(feature = "docs", feature = "pkg-config"))]
compile_error!(
"feature \"docs\" and feature \"pkg-config\" cannot be enabled at the same time"
);
#[cfg(all(feature = "docs", feature = "download-tdlib"))]
compile_error!(
"feature \"docs\" and feature \"download-tdlib\" cannot be enabled at the same time"
);
#[cfg(all(feature = "pkg-config", feature = "download-tdlib"))]
compile_error!(
"feature \"pkg-config\" and feature \"download-tdlib\" cannot be enabled at the same time"
);

#[cfg(not(any(feature = "docs", feature = "pkg-config", feature = "download-tdlib")))]
println!("cargo:rerun-if-env-changed=LOCAL_TDLIB_PATH");
#[cfg(not(any(feature = "docs", feature = "pkg-config", feature = "download-tdlib")))]
println!("cargo:rerun-if-env-changed=LOCAL_TDLIB_PATH");

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=build.rs");

// Prevent linking libraries to avoid documentation failure
#[cfg(not(feature = "docs"))]
{
// It requires the following variables to be set:
// - export PKG_CONFIG_PATH=$HOME/lib/tdlib/lib/pkgconfig/:$PKG_CONFIG_PATH
// - export LD_LIBRARY_PATH=$HOME/lib/tdlib/lib/:$LD_LIBRARY_PATH
#[cfg(feature = "pkg-config")]
system_deps::Config::new().probe().unwrap();
// Prevent linking libraries to avoid documentation failure
#[cfg(not(feature = "docs"))]
{
// It requires the following variables to be set:
// - export PKG_CONFIG_PATH=$HOME/lib/tdlib/lib/pkgconfig/:$PKG_CONFIG_PATH
// - export LD_LIBRARY_PATH=$HOME/lib/tdlib/lib/:$LD_LIBRARY_PATH
#[cfg(feature = "pkg-config")]
system_deps::Config::new().probe().unwrap();

#[cfg(feature = "download-tdlib")]
download_tdlib();
#[cfg(feature = "download-tdlib")]
download_tdlib();

#[cfg(not(feature = "pkg-config"))]
{
#[cfg(not(feature = "download-tdlib"))]
copy_local_tdlib();
generic_build();
#[cfg(not(feature = "pkg-config"))]
{
#[cfg(not(feature = "download-tdlib"))]
copy_local_tdlib();
generic_build();
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions tdlib-rs/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn check_features() {
#[cfg(all(feature = "docs", feature = "pkg-config"))]
compile_error!(
"feature \"docs\" and feature \"pkg-config\" cannot be enabled at the same time"
);
#[cfg(all(feature = "docs", feature = "download-tdlib"))]
compile_error!(
"feature \"docs\" and feature \"download-tdlib\" cannot be enabled at the same time"
);
#[cfg(all(feature = "pkg-config", feature = "download-tdlib"))]
compile_error!(
"feature \"pkg-config\" and feature \"download-tdlib\" cannot be enabled at the same time"
);
}
1 change: 1 addition & 0 deletions tdlib-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
mod generated;
mod observer;
mod tdjson;
pub mod build;

pub use generated::{enums, functions, types};

Expand Down

0 comments on commit 9ba6ebc

Please sign in to comment.