Skip to content

Commit

Permalink
Upstream 2024.3.4 (#17)
Browse files Browse the repository at this point in the history
* rebuild tonlyb-sys only if ton revision or sources are changed
* use --depth=1 for clone: ~35sec speed-up
* use --shallow-submodules for clone: ~40sec speed up
* use -j {cpu_num} for tonlibjsob: ~110sec speed up
* use -j {cpu_num} for tonlibjsob: ~4sec speed up
* use available_parallelism() instead of num_cpus
* use TON_DIR everywhere

---------

Authored-by: Dmitrii Korchagin <[email protected]>
  • Loading branch information
dbaranovstonfi authored May 1, 2024
1 parent 7c4ff86 commit 159a196
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 46 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tonlib-sys"
version = "2024.3.3"
version = "2024.3.4"
edition = "2021"
description = "Rust bindings for tonlibjson library"
license = "MIT"
Expand All @@ -12,11 +12,10 @@ include = [
]

[features]
default = ["cmake", "num_cpus"]
default = ["cmake"]
shared-tonlib = []

[dependencies]

[build-dependencies]
cmake = { version = "0.1", optional = true }
num_cpus = { version = "1", optional = true }
102 changes: 59 additions & 43 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
use std::env;
use std::path::Path;
use std::thread::available_parallelism;
use std::{env, fs};

fn main() {
build();
}

const TON_MONOREPO_REVISION: &str = "25f61dff161b9c76dce0fc62dc51da911a208b68";
const TON_MONOREPO_DIR: &str = "./ton";

#[cfg(not(feature = "shared-tonlib"))]
fn build() {
env::set_var("TON_MONOREPO_REVISION", TON_MONOREPO_REVISION);
println!("cargo:rerun-if-env-changed=TON_MONOREPO_REVISION");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src");

use std::process::Command;

if !std::path::Path::new("ton/tonlib").is_dir() {
let clone_status = std::process::Command::new("git")
.args([
"clone",
"--recurse-submodules",
"https://github.com/ton-blockchain/ton",
"--branch",
"testnet",
])
// cleanup tonlib after previous build
if Path::new(TON_MONOREPO_DIR).exists() {
let _ = fs::remove_dir_all(TON_MONOREPO_DIR);
}

let clone_status = Command::new("git")
.args([
"clone",
"--branch",
"testnet",
"--depth",
"1", // get only the latest commit
"--recurse-submodules", // clone submodules as well
"--shallow-submodules", // get only the latest commit of submodules
"https://github.com/ton-blockchain/ton",
TON_MONOREPO_DIR,
])
.status()
.unwrap();
if clone_status.success() {
let checkout_status = Command::new("git")
.current_dir(TON_MONOREPO_DIR)
.args(["checkout", TON_MONOREPO_DIR])
.status()
.unwrap();
if clone_status.success() {
let checkout_status = std::process::Command::new("git")
.current_dir("ton")
.args(["checkout", "25f61dff161b9c76dce0fc62dc51da911a208b68"])
.status()
.unwrap();

if checkout_status.success() {
println!("Cloned and checked out specific commit successfully!");
} else {
println!("Failed to checkout specific commit!");
}

if checkout_status.success() {
println!("Cloned and checked out specific commit successfully!");
} else {
println!("Failed to clone repository!");
}
if !clone_status.success() {
panic!("Git clone TON repo fail");
}
let update_submodules_status = std::process::Command::new("git")
.current_dir("./ton")
.args(["submodule", "update", "--init", "--recursive"])
.status()
.unwrap();
if !update_submodules_status.success() {
panic!("Git update submodules for TON repo fail");
println!("Failed to checkout specific commit!");
}
} else {
println!("Failed to clone repository!");
}
if !clone_status.success() {
panic!("Git clone TON repo fail");
}
let update_submodules_status = Command::new("git")
.current_dir(TON_MONOREPO_DIR)
.args(["submodule", "update", "--init", "--recursive"])
.status()
.unwrap();
if !update_submodules_status.success() {
panic!("Git update submodules for TON repo fail");
}

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

if cfg!(target_os = "macos") {
env::set_var("NUM_JOBS", num_cpus::get().to_string());

// OpenSSL
let openssl_installed = Command::new("brew")
.args(["--prefix", "openssl@3"])
Expand Down Expand Up @@ -122,7 +134,7 @@ fn build() {
}

fn build_tonlibjson(march: &str) {
let mut cfg = cmake::Config::new("ton");
let mut cfg = cmake::Config::new(TON_MONOREPO_DIR);
let mut dst = cfg
.configure_arg("-DTON_ONLY_TONLIB=true")
.configure_arg("-DBUILD_SHARED_LIBS=false")
Expand All @@ -131,6 +143,9 @@ fn build_tonlibjson(march: &str) {
.define("BUILD_SHARED_LIBS", "OFF")
.define("PORTABLE", "1")
.define("CMAKE_BUILD_TYPE", "Release")
// multi-thread build used to fail compilation. Please try comment out next 2 lines if you have build errors
.build_arg("-j")
.build_arg(available_parallelism().unwrap().get().to_string())
.configure_arg("-Wno-dev")
.build_target("tonlibjson")
.always_configure(true)
Expand Down Expand Up @@ -239,21 +254,19 @@ fn build_tonlibjson(march: &str) {
"cargo:rustc-link-search=native={}/build/emulator",
dst.display()
);
println!("cargo:rerun-if-changed={}/build/emulator", dst.display());
println!("cargo:rustc-link-lib=static=emulator_static");

println!(
"cargo:rustc-link-search=native={}/build/tonlib",
dst.display()
);
println!("cargo:rerun-if-changed={}/build/tonlib", dst.display());
println!("cargo:rustc-link-lib=static=tonlibjson");
println!("cargo:rustc-link-lib=static=tonlib");
println!("cargo:rustc-link-lib=static=tonlibjson_private");
}

fn build_emulator(march: &str) {
let mut cfg = cmake::Config::new("ton");
let mut cfg = cmake::Config::new(TON_MONOREPO_DIR);
let mut dst = cfg
.configure_arg("-DTON_ONLY_TONLIB=true")
.configure_arg("-Wno-dev")
Expand All @@ -262,6 +275,9 @@ fn build_emulator(march: &str) {
.configure_arg("-Wno-deprecated-declarations")
.define("PORTABLE", "1")
.define("CMAKE_BUILD_TYPE", "Release")
// multi-thread build used to fail compilation. Please try comment out next 2 lines if you have build errors
.build_arg("-j")
.build_arg(available_parallelism().unwrap().get().to_string())
.build_target("emulator")
.always_configure(true)
.very_verbose(false);
Expand Down

0 comments on commit 159a196

Please sign in to comment.