Skip to content

Commit

Permalink
Fix linking in windows
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
Co-authored-by: Andrea Longoni <Andreal2000@users.noreply.github.com>
  • Loading branch information
FedericoBruzzone and Andreal2000 committed Aug 8, 2024
1 parent c0a04c7 commit 89f6146
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export RUST_BACKTRACE := 1
# Available bin_name:
# get_me

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

build_local:
cargo build --no-default-features --features local-tdlib
Expand Down
1 change: 1 addition & 0 deletions tdlib-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ serde_with = "3.2"
system-deps = { version = "7", optional = true }
reqwest = { version = "0.12.4", features = ["blocking"], optional = true }
zip = { version = "2.0.0", optional = true }
dirs = "5.0.1"

[build-dependencies]
tdlib-rs-gen = { path = "../tdlib-rs-gen", version = "1.0.4" }
Expand Down
31 changes: 31 additions & 0 deletions tdlib-rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ fn download_tdlib() {
/// If the tdlib library is not found at the specified path, the function will panic.
/// The function will panic if the tdlib library is not found at the specified path.
fn generic_build(lib_path: Option<String>) {
use crate::tdjson;

let correct_lib_path: String;
match lib_path {
Some(lib_path) => {
Expand Down Expand Up @@ -178,6 +180,33 @@ fn generic_build(lib_path: Option<String>) {
panic!("tdjson shared library not found at {}", mut_lib_path);
}

// This should be not necessary, but it is a workaround because windows does not find the
// tdjson.dll using the commands below.
// TODO: investigate and if it is a bug in `cargo` or `rustc`, open an issue to `cargo` to fix
// this.
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
{
let bin_dir = format!(r"{}\bin", prefix);
let cargo_bin = format!("{}/.cargo/bin", dirs::home_dir().unwrap().to_str().unwrap());

let libcrypto3x64 = format!(r"{}\libcrypto-3-x64.dll", bin_dir);
let libssl3x64 = format!(r"{}\libssl-3-x64.dll", bin_dir);
let tdjson = format!(r"{}\tdjson.dll", bin_dir);
let zlib1 = format!(r"{}\zlib1.dll", bin_dir);

// Delete the files if they exist
let _ = std::fs::remove_file(libcrypto3x64);
let _ = std::fs::remove_file(libssl3x64);
let _ = std::fs::remove_file(tdjson);
let _ = std::fs::remove_file(zlib1);

// Move all files to cargo_bin
let _ = std::fs::copy(libcrypto3x64.clone(), cargo_bin.clone());
let _ = std::fs::copy(libssl3x64.clone(), cargo_bin.clone());
let _ = std::fs::copy(tdjson.clone(), cargo_bin.clone());
let _ = std::fs::copy(zlib1.clone(), cargo_bin.clone());
}

#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
{
let bin_dir = format!(r"{}\bin", prefix);
Expand Down Expand Up @@ -409,6 +438,7 @@ pub fn build_local_tdlib() {
/// [dependencies]
/// tdlib = { version = "...", features = ["download-tdlib"] }
///

/// [build-dependencies]
/// tdlib = { version = "...", features = [ "download-tdlib" ] }
/// ```
Expand All @@ -424,6 +454,7 @@ pub fn build_local_tdlib() {
pub fn build(_dest_path: Option<String>) {
check_features();
set_rerun_if();

#[cfg(feature = "pkg-config")]
build_pkg_config();
#[cfg(feature = "download-tdlib")]
Expand Down

0 comments on commit 89f6146

Please sign in to comment.