Skip to content

Commit

Permalink
Upstream 2024.3.3 (#16)
Browse files Browse the repository at this point in the history

* Supported crosscompilation

---------

Co-authored-by: dbaranov34 <[email protected]>
  • Loading branch information
dbaranovstonfi and dbaranov34 authored Apr 19, 2024
1 parent b4e37fd commit 7c4ff86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tonlib-sys"
version = "2024.3.2"
version = "2024.3.3"
edition = "2021"
description = "Rust bindings for tonlibjson library"
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Then, in your Rust code, you can import the library with:
use tonlib_sys;
```

## Cross-compilation
In order to cross-compile for specific cpu microachitecture set environment variable `TARGET_CPU_MARCH` to the required. Supported values are listen in https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html


## Contributing

If you want to contribute to this library, please feel free to open a pull request on GitHub.
Expand Down
39 changes: 28 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::env;

fn main() {
build();
}

#[cfg(not(feature = "shared-tonlib"))]
fn build() {
use std::{env, process::Command};
use std::process::Command;

if !std::path::Path::new("ton/tonlib").is_dir() {
let clone_status = std::process::Command::new("git")
Expand Down Expand Up @@ -114,12 +116,14 @@ fn build() {

env::set_var("LD_LIBRARY_PATH", "lib/x86_64-linux-gnu");

build_tonlibjson();
build_emulator();
let march = env::var("TARGET_CPU_MARCH").unwrap_or_default();
build_tonlibjson(march.as_str());
build_emulator(march.as_str());
}

fn build_tonlibjson() {
let dst = cmake::Config::new("ton")
fn build_tonlibjson(march: &str) {
let mut cfg = cmake::Config::new("ton");
let mut dst = cfg
.configure_arg("-DTON_ONLY_TONLIB=true")
.configure_arg("-DBUILD_SHARED_LIBS=false")
.configure_arg("-DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/lib")
Expand All @@ -130,8 +134,14 @@ fn build_tonlibjson() {
.configure_arg("-Wno-dev")
.build_target("tonlibjson")
.always_configure(true)
.very_verbose(false)
.build();
.very_verbose(false);

if !march.is_empty() {
dst = dst
.configure_arg(format!("-DCMAKE_C_FLAGS=-march={}", march))
.configure_arg(format!("-DCMAKE_CXX_FLAGS=-march={}", march));
}
let dst = dst.build();

println!("cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu");
println!("cargo:rustc-link-search=native=/usr/include");
Expand Down Expand Up @@ -242,8 +252,9 @@ fn build_tonlibjson() {
println!("cargo:rustc-link-lib=static=tonlibjson_private");
}

fn build_emulator() {
let dst = cmake::Config::new("ton")
fn build_emulator(march: &str) {
let mut cfg = cmake::Config::new("ton");
let mut dst = cfg
.configure_arg("-DTON_ONLY_TONLIB=true")
.configure_arg("-Wno-dev")
.configure_arg("-Wno-unused")
Expand All @@ -253,8 +264,14 @@ fn build_emulator() {
.define("CMAKE_BUILD_TYPE", "Release")
.build_target("emulator")
.always_configure(true)
.very_verbose(false)
.build();
.very_verbose(false);

if !march.is_empty() {
dst = dst
.configure_arg(format!("-DCMAKE_C_FLAGS=-march={}", march))
.configure_arg(format!("-DCMAKE_CXX_FLAGS=-march={}", march));
}
let dst = dst.build();

println!("cargo:rustc-link-lib=dylib=sodium");
println!("cargo:rustc-link-lib=dylib=secp256k1");
Expand Down

0 comments on commit 7c4ff86

Please sign in to comment.