Skip to content

Commit

Permalink
Add local-tdlib feature
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 4424d41 commit 46d71e5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: [default, download-tdlib, pkg-config, docs]
feature: [local-tdlib, download-tdlib, pkg-config, docs]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download TDLib
if: matrix.feature == 'default' || matrix.feature == 'pkg-config'
if: matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config'
run: |
gh release download --pattern 'tdlib-*-linux-x86_64.zip'
unzip -q *.zip -d .
Expand All @@ -40,8 +40,8 @@ jobs:
run: |
echo "PKG_CONFIG_PATH=$(pwd)/tdlib/lib/pkgconfig" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$(pwd)/tdlib/lib" >> $GITHUB_ENV
- name: Set default environment variables
if: matrix.feature == 'default'
- name: Set local-tdlib environment variables
if: matrix.feature == 'local-tdlib'
run: echo "LOCAL_TDLIB_PATH=$(pwd)/tdlib/" >> $GITHUB_ENV
- name: Run cargo build
run: cargo build --verbose --features ${{ matrix.feature }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
fail-fast: false
matrix:
os: [macos-13, macos-14]
feature: [default, download-tdlib, pkg-config, docs]
feature: [local-tdlib, download-tdlib, pkg-config, docs]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download TDLib
if: matrix.feature == 'default' || matrix.feature == 'pkg-config'
if: matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config'
run: |
gh release download --pattern ${{ runner.arch == 'ARM64' && 'tdlib-*-macos-aarch64.zip' || 'tdlib-*-macos-x86_64.zip' }}
unzip -q *.zip -d .
Expand All @@ -41,8 +41,8 @@ jobs:
run: |
echo "PKG_CONFIG_PATH=$(pwd)/tdlib/lib/pkgconfig" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=$(pwd)/tdlib/lib" >> $GITHUB_ENV
- name: Set default environment variables
if: matrix.feature == 'default'
- name: Set local-tdlib environment variables
if: matrix.feature == 'local-tdlib'
run: echo "LOCAL_TDLIB_PATH=$(pwd)/tdlib/" >> $GITHUB_ENV
- name: Run cargo build
run: cargo build --verbose --features ${{ matrix.feature }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: [default, download-tdlib, pkg-config, docs]
feature: [local-tdlib, download-tdlib, pkg-config, docs]

runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download TDLib
if: matrix.feature == 'default' || matrix.feature == 'pkg-config'
if: matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config'
run: |
gh release download --pattern 'tdlib-*-windows-x86_64.zip'
unzip -q *.zip -d .
Expand All @@ -57,8 +57,8 @@ jobs:
echo "PKG_CONFIG_PATH=$((Get-Item .).FullName)\tdlib\lib\pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$((Get-Item .).FullName)\tdlib\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh
- name: Set default environment variables
if: matrix.feature == 'default'
- name: Set local-tdlib environment variables
if: matrix.feature == 'local-tdlib'
run: echo "LOCAL_TDLIB_PATH=$((Get-Item .).FullName)\tdlib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh
- name: Run cargo build
Expand Down
2 changes: 2 additions & 0 deletions tdlib-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ default = []
bots-only-api = []
# This feature is used to build the documentation preventing linking to the tdjson library
docs = []
# This feature is used to build the library using the tdlib library installed in the system
local-tdlib = []
# This feature is used to build the library using pkg-config
pkg-config = ["dep:system-deps"]
# This feature is used to build the library using the tdlib library downloaded from github
Expand Down
33 changes: 19 additions & 14 deletions tdlib-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// #[cfg(not(any(feature = "docs", feature = "pkg-config")))]
// use lazy_static::lazy_static;
use std::env;
use std::fs::File;
use std::io::{BufWriter, Read, Write};
Expand Down Expand Up @@ -40,7 +38,7 @@ fn load_tl(file: &str) -> std::io::Result<Vec<Definition>> {
.collect())
}

#[cfg(not(any(feature = "docs", feature = "pkg-config", feature = "download-tdlib")))]
#[cfg(feature = "local-tdlib")]
/// Copy all files from a directory to another.
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
std::fs::create_dir_all(&dst)?;
Expand All @@ -56,7 +54,7 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result
Ok(())
}

#[cfg(not(any(feature = "docs", feature = "pkg-config", feature = "download-tdlib")))]
#[cfg(feature = "local-tdlib")]
/// Copy all the tdlib folder find in the LOCAL_TDLIB_PATH environment variable to the OUT_DIR/tdlib folder
fn copy_local_tdlib() {
match env::var("LOCAL_TDLIB_PATH") {
Expand All @@ -71,7 +69,7 @@ fn copy_local_tdlib() {
};
}

#[cfg(not(any(feature = "docs", feature = "pkg-config")))]
#[cfg(any(feature = "download-tdlib", feature = "local-tdlib"))]
/// Build the project using the generic build configuration.
/// The current supported platforms are:
/// - Linux x86_64
Expand Down Expand Up @@ -206,6 +204,14 @@ fn download_tdlib() {
}

fn main() -> std::io::Result<()> {
// #[cfg(not(any(
// feature = "docs",
// feature = "local-tdlib",
// feature = "pkg-config",
// feature = "download-tdlib"
// )))]
// println!("cargo:warning=No features enabled, you must enable at least one of the following features: docs, local-tdlib, pkg-config, download-tdlib");

#[cfg(all(feature = "docs", feature = "pkg-config"))]
compile_error!(
"feature \"docs\" and feature \"pkg-config\" cannot be enabled at the same time"
Expand All @@ -219,11 +225,11 @@ fn main() -> std::io::Result<()> {
"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");

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

#[cfg(feature = "local-tdlib")]
println!("cargo:rerun-if-env-changed=LOCAL_TDLIB_PATH");

// Prevent linking libraries to avoid documentation failure
#[cfg(not(feature = "docs"))]
{
Expand All @@ -236,12 +242,11 @@ fn main() -> std::io::Result<()> {
#[cfg(feature = "download-tdlib")]
download_tdlib();

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

#[cfg(any(feature = "download-tdlib", feature = "local-tdlib"))]
generic_build();
}

let out_dir = env::var("OUT_DIR").unwrap();
Expand Down
7 changes: 4 additions & 3 deletions tdlib-rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ pub fn check_features() {
}

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

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

// You have to build the tdlib
// TODO: Try to change the .pc file
#[cfg(feature = "pkg-config")]
pub fn build_pkg_config() {
#[cfg(not(feature = "docs"))]
{
Expand Down Expand Up @@ -149,7 +150,7 @@ fn copy_dir_all(
Ok(())
}

#[cfg(not(any(feature = "docs", feature = "pkg-config")))]
#[cfg(any(feature = "download-tdlib", feature = "local-tdlib"))]
/// Build the project using the generic build configuration.
/// The current supported platforms are:
/// - Linux x86_64
Expand Down Expand Up @@ -238,7 +239,7 @@ pub fn build_download_tdlib(dest_path: Option<String>) {
// };
// }

#[cfg(not(any(feature = "docs", feature = "pkg-config", feature = "download-tdlib")))]
#[cfg(feature = "local-tdlib")]
pub fn build_local_tdlib() {
// copy_local_tdlib();
let path = std::env::var("LOCAL_TDLIB_PATH").unwrap();
Expand Down

0 comments on commit 46d71e5

Please sign in to comment.