Skip to content

Commit

Permalink
Update CI, Makefile and build.rs
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <[email protected]>
  • Loading branch information
FedericoBruzzone committed Jun 24, 2024
1 parent aad1a5d commit 6af64d5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Run cargo test
run: cargo test --verbose --workspace --exclude tdlib-rs -- --nocapture --test-threads=1
- name: Run cargo clippy
run: cargo clippy --features ${{ matrix.feature }} -- -D warnings
run: cargo clippy --all-targets --features ${{ matrix.feature }} -- -D warnings
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo run
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Run cargo test
run: cargo test --verbose --workspace --exclude tdlib-rs -- --nocapture --test-threads=1
- name: Run cargo clippy
run: cargo clippy --features ${{ matrix.feature }} -- -D warnings
run: cargo clippy --all-targets --features ${{ matrix.feature }} -- -D warnings
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo run
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Run cargo test
run: cargo test --verbose --workspace --exclude tdlib-rs -- --nocapture --test-threads=1
- name: Run cargo clippy
run: cargo clippy --features ${{ matrix.feature }} -- -D warnings
run: cargo clippy --all-targets --features ${{ matrix.feature }} -- -D warnings
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo run
Expand Down
58 changes: 0 additions & 58 deletions Justfile

This file was deleted.

32 changes: 29 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
export RUST_BACKTRACE := 1

# Usage: make <command> ARGS="--features <feature> --bin <bin_name>"
#
# Avaialble commands:
# all
# build
# run
# test
# clippy
# fmt
# clean
#
# Available features:
# local-tdlib
# download-tdlib
# pkg-config
#
# Available bin_name:
# get_me

all: fmt clippy test build
all:
$(MAKE) fmt
$(MAKE) clippy # ARGS="--features download-tdlib"
$(MAKE) test # ARGS="--features download-tdlib"

build_local:
cargo build --no-default-features --features local-tdlib

# Example 1: make build ARGS="--features download-tdlib"
# Example 2: make build ARGS="--features download-tdlib --example telegram"
build:
cargo build $(ARGS)
cargo build $(ARGS)

# Example: make run ARGS="--package tdlib-rs --example get_me"
# Example: make run ARGS="--package tdlib-rs --example get_me --features download-tdlib"
run:
cargo run $(ARGS)

Expand Down
3 changes: 0 additions & 3 deletions tdlib-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ 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"
Expand Down Expand Up @@ -244,8 +243,6 @@ fn main() -> std::io::Result<()> {
generic_build();
}



let out_dir = env::var("OUT_DIR").unwrap();

let definitions = load_tl("tl/api.tl")?;
Expand Down
27 changes: 17 additions & 10 deletions tdlib-rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/// - `local-tdlib`
/// - `pkg-config`
/// - `download-tdlib`
///
#[allow(dead_code)]
#[cfg(not(any(feature = "docs", feature = "pkg-config")))]
Expand Down Expand Up @@ -249,6 +248,7 @@ pub fn set_rerun_if() {
}

#[cfg(feature = "pkg-config")]
#[allow(clippy::needless_doctest_main)]
/// Build the project using the `pkg-config` feature.
/// Using the `pkg-config` feature, the function will probe the system dependencies.
/// It means that the function assumes that the tdlib library is compiled in the system.
Expand All @@ -258,19 +258,21 @@ pub fn set_rerun_if() {
/// If the variables are not set, the function will panic.
///
/// # Example
/// Cargo.toml:
/// ```toml
/// // Cargo.toml
/// [dependencies]
/// tdlib = { version = "...", features = ["pkg-config"] }
/// ```
///
/// build.rs:
/// ```rust
/// // build.rs
/// fn main() {
/// tdlib_rs::build::check_features();
/// tdlib_rs::build::set_rerun_if();
/// tdlib_rs::build::build_pkg_config();
/// // Other build configurations
/// // ...
/// }
/// ```
pub fn build_pkg_config() {
#[cfg(not(feature = "docs"))]
Expand All @@ -280,6 +282,7 @@ pub fn build_pkg_config() {
}

#[cfg(feature = "download-tdlib")]
#[allow(clippy::needless_doctest_main)]
/// Build the project using the `download-tdlib` feature.
///
/// # Arguments
Expand All @@ -303,23 +306,24 @@ pub fn build_pkg_config() {
/// If the OS or architecture is not supported, the function will panic.
///
/// # Example
/// Cargo.toml:
/// ```toml
/// // Cargo.toml
/// [dependencies]
/// tdlib = { version = "...", features = ["download-tdlib"] }
///
//// [build-dependencies]
/// [build-dependencies]
/// tdlib = { version = "...", features = [ "download-tdlib" ] }
/// ```
///
/// build.rs:
/// ```rust
/// // build.rs
/// fn main() {
/// tdlib_rs::build::check_features();
/// tdlib_rs::build::set_rerun_if();
/// tdlib_rs::build::build_download_tdlib(None);
/// // Other build configurations
/// // ...
/// }
/// ```
pub fn build_download_tdlib(dest_path: Option<String>) {
#[cfg(not(feature = "docs"))]
Expand All @@ -340,6 +344,7 @@ pub fn build_download_tdlib(dest_path: Option<String>) {
}

#[cfg(feature = "local-tdlib")]
#[allow(clippy::needless_doctest_main)]
/// Build the project using the `local-tdlib` feature.
/// Using the `local-tdlib` feature, the function will copy the tdlib library from the
/// `LOCAL_TDLIB_PATH` environment variable.
Expand All @@ -357,17 +362,17 @@ pub fn build_download_tdlib(dest_path: Option<String>) {
/// If the `LOCAL_TDLIB_PATH` environment variable is not set, the function will panic.
///
/// # Example
/// Cargo.toml:
/// ```toml
/// // Cargo.toml
/// [dependencies]
/// tdlib = { version = "...", features = ["local-tdlib"] }
///
/// [build-dependencies]
/// tdlib = { version = "...", features = [ "download-tdlib" ] }
/// ```
///
/// build.rs:
/// ```rust
/// // build.rs
/// fn main() {
/// tdlib_rs::build::check_features();
/// tdlib_rs::build::set_rerun_if();
Expand All @@ -385,6 +390,7 @@ pub fn build_local_tdlib() {
}
}

#[allow(clippy::needless_doctest_main)]
/// Build the project using the enabled features.
///
/// # Arguments
Expand All @@ -398,22 +404,23 @@ pub fn build_local_tdlib() {
/// The function will build the project using the enabled feature.
///
/// # Example
/// Cargo.toml:
/// ```toml
/// // Cargo.toml
/// [dependencies]
/// tdlib = { version = "...", features = ["download-tdlib"] }
///
/// [build-dependencies]
/// tdlib = { version = "...", features = [ "download-tdlib" ] }
/// ```
///
/// build.rs:
/// ```rust
/// // build.rs
/// fn main() {
/// tdlib_rs::build::build(None);
/// // Other build configurations
/// // ...
/// }
/// ```
pub fn build(_dest_path: Option<String>) {
check_features();
set_rerun_if();
Expand Down

0 comments on commit 6af64d5

Please sign in to comment.