Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream 2024.4.0 #21

Merged
merged 35 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8d3fa96
Ni: crosscompilation
dbaranovstonfi Apr 19, 2024
1acdcca
Merge branch 'NI-rustflags-passing' into 'main'
dbaranovstonfi Apr 19, 2024
43d83e2
NI: rebuild tonlyb-sys only if ton revision or sources are changed
Apr 22, 2024
d42e18a
NI: use --depth=1 for clone: ~35sec speed-up
Apr 22, 2024
44a4291
NI: use --shallow-submodules for clone: ~40sec speed up
Apr 22, 2024
5dfa352
NI: use -j {cpu_num} for tonlibjsob: ~110sec speed up
Apr 22, 2024
96bd49f
NI: use -j {cpu_num} for tonlibjsob: ~4sec speed up
Apr 22, 2024
81ed423
NI: use available_parallelism() instead of num_cpus
Apr 23, 2024
2c5e9f7
NI: use TON_DIR everywhere
Apr 23, 2024
075cf0f
NI: review fixes
Apr 23, 2024
d6db863
Merge branch 'NI-fix-tonlyb-rebuild' into 'main'
Apr 23, 2024
1a97f0d
Upstream 2024.3.3 (#16)
dbaranovstonfi May 1, 2024
0d08c28
Merge branch 'downstream-2024.3.4' into 'main'
dbaranovstonfi May 1, 2024
56daf3e
NI: repair old mac build
May 6, 2024
d4bcbcb
Merge branch 'ni-repair-old-mac-build' into 'main'
dbaranovstonfi May 6, 2024
ad9c8de
Impl NI: no_avx512 flag added
dbaranovstonfi May 8, 2024
b8889b7
Merge branch 'ston-481-cflags' into 'main'
dbaranovstonfi May 8, 2024
4d4a1b1
Impl #NI: fix avx build for macos
May 10, 2024
45a8560
Merge branch 'NI-fix-noavx-build-on-macos' into 'main'
dbaranovstonfi May 10, 2024
fc6f02d
NI: make no_avx works with gcc
May 10, 2024
cfcd7bc
NI: add job to test build with no_avx
May 10, 2024
1c3d60e
Merge branch 'NI-fix-noavx-build-on-macos' into 'main'
dbaranovstonfi May 10, 2024
08c368d
Impl #NI: push all mac-deps in loop
May 10, 2024
8d3e09d
Impl #NI: add build for arm_m3 in MR pipeline
May 10, 2024
7297bfe
Merge branch 'NI-mac-deps-in-loop' into 'main'
dbaranovstonfi May 13, 2024
6f7ee42
Impl #NI: support tx_emulator [src + tests]
May 16, 2024
b3de43c
Impl #NI: put tests to related mods
May 16, 2024
fe6ab26
Impl #NI: don't rebuild tonlibs if revision is not changed
May 16, 2024
11ab251
Merge branch 'NI-support-tx-emulator' into 'main'
May 17, 2024
48de10b
Impl #NI: update tick-tock emulation coms
May 28, 2024
8194869
Merge branch 'ni-update-ticktock-emulate-comms' into 'main'
May 28, 2024
4254d8b
bump ton to 2024.4
dbaranov34 Jun 6, 2024
ba2d268
Merge branch 'NI-ton-2024.4' into 'main'
dbaranovstonfi Jun 6, 2024
0411dc1
Merge remote-tracking branch 'upstream/main' into upstream-2024.4.0
dbaranov34 Jun 6, 2024
8bdc64a
typo
dbaranov34 Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.7"
version = "2024.4.0"
edition = "2021"
description = "Rust bindings for tonlibjson library"
license = "MIT"
Expand Down
78 changes: 28 additions & 50 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::path::Path;
use std::process::Command;
use std::thread::available_parallelism;
Expand All @@ -9,7 +10,7 @@ fn main() {
build();
}

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

#[cfg(not(feature = "shared-tonlib"))]
Expand All @@ -19,7 +20,6 @@ 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");

// cleanup tonlib after previous build
if Path::new(TON_MONOREPO_DIR).exists() {
Expand All @@ -30,7 +30,7 @@ fn build() {
.args([
"clone",
"--branch",
"testnet",
"v2024.04",
"--depth",
"1", // get only the latest commit
"--recurse-submodules", // clone submodules as well
Expand Down Expand Up @@ -68,56 +68,34 @@ fn build() {
}

if cfg!(target_os = "macos") {
// OpenSSL
let openssl_installed = Command::new("brew")
.args(["--prefix", "openssl@3"])
.output()
.unwrap();
if !openssl_installed.status.success() {
panic!("OpenSSL is not installed. To install: `brew install openssl`");
}
let openssl = std::str::from_utf8(openssl_installed.stdout.as_slice())
.unwrap()
.trim();

// lz4
let lz4_installed = Command::new("brew").args(["list", "lz4"]).output().unwrap();
if !lz4_installed.status.success() {
panic!("liblz4 is not installed. To install: `brew install lz4`");
if Command::new("brew").args(["-h"]).output().is_err() {
panic!("brew is not available. Please install it to proceed");
}

// pkgconfig
let pkgconfig_installed = Command::new("brew")
.args(["list", "pkgconfig"])
.output()
.unwrap();
if !pkgconfig_installed.status.success() {
panic!("pkg-config is not installed. To install: `brew install pkgconfig`");
let mut dep_paths = HashMap::new();
for dep in &["openssl@3", "lz4", "pkgconfig", "libsodium", "secp256k1"] {
let dep_installed = Command::new("brew")
.args(["--prefix", dep])
.output()
.unwrap();
if !dep_installed.status.success() {
panic!(
"{} is not installed. To install: `brew install {}`",
dep, dep
);
} else {
dep_paths.insert(
dep.to_string(),
std::str::from_utf8(dep_installed.stdout.as_slice())
.unwrap()
.trim()
.to_string(),
);
}
}

// libsodium
let libsodium_installed = Command::new("brew")
.args(["--prefix", "libsodium"])
.output()
.unwrap();
if !libsodium_installed.status.success() {
panic!("libsodium is not installed. To install: `brew install libsodium`");
}
let libsodium = std::str::from_utf8(libsodium_installed.stdout.as_slice())
.unwrap()
.trim();

// secp256k1
let secp256k1_installed = Command::new("brew")
.args(["--prefix", "secp256k1"])
.output()
.unwrap();
if !secp256k1_installed.status.success() {
panic!("secp256k1 is not installed. To install: `brew install secp256k1`");
}
let secp256k1 = std::str::from_utf8(secp256k1_installed.stdout.as_slice())
.unwrap()
.trim();
let openssl = &dep_paths["openssl@3"];
let libsodium = &dep_paths["libsodium"];
let secp256k1 = &dep_paths["secp256k1"];

env::set_var("OPENSSL_ROOT_DIR", openssl);
env::set_var("OPENSSL_INCLUDE_DIR", format!("{openssl}/include"));
Expand Down
39 changes: 2 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
mod tonlibjson;
mod tvm_emulator;
mod tx_emulator;

pub use tonlibjson::*;
pub use tvm_emulator::*;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_creates_client() {
unsafe {
let client = tonlib_client_json_create();
tonlib_client_set_verbosity_level(4);
assert!(!client.is_null());
tonlib_client_json_send(client, "123\0".as_bytes().as_ptr() as *const i8);
tonlib_client_json_receive(client, 1.0);
tonlib_client_json_destroy(client);
}
}

#[test]
fn it_creates_emulator() {
let code = "te6cckECCwEAAe0AART/APSkE/S88sgLAQIBYgIDAgLMBAUCA3pgCQoD79mRDjgEit8GhpgYC42Eit8H0gGADpj+mf9qJofQB9IGpqGEAKqThdRxgamqiq44L5cCSA/SB9AGoYEGhAMGuQ/QAYEogaKCF4BFAqkGQoAn0BLGeLZmZk9qpwQQg97svvKThdcYEakuAB8YEYAmACcYEvgsIH+XhAYHCACT38FCIBuCoQCaoKAeQoAn0BLGeLAOeLZmSRZGWAiXoAegBlgGSQfIA4OmRlgWUD5f/k6DvADGRlgqxniygCfQEJ5bWJZmZkuP2AQA/jYD+gD6QPgoVBIIcFQgE1QUA8hQBPoCWM8WAc8WzMkiyMsBEvQA9ADLAMn5AHB0yMsCygfL/8nQUAjH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ghBzYtCcyMsfUjDLP1j6AlAHzxZQB88WyXGAGMjLBSTPFlAG+gIVy2oUzMlx+wAQJBAjAA4QSRA4N18EAHbCALCOIYIQ1TJ223CAEMjLBVAIzxZQBPoCFstqEssfEss/yXL7AJM1bCHiA8hQBPoCWM8WAc8WzMntVADbO1E0PoA+kD6QNQwB9M/+gD6QDBRUaFSSccF8uLBJ8L/8uLCggiYloCqABagFrzy4sOCEHvdl97Iyx8Vyz9QA/oCIs8WAc8WyXGAGMjLBSTPFnD6AstqzMmAQPsAQBPIUAT6AljPFgHPFszJ7VSAAgyAINch7UTQ+gD6QPpA1DAE0x+CEBeNRRlSILqCEHvdl94TuhKx8uLF0z8x+gAwE6BQI8hQBPoCWM8WAc8WzMntVIH++ZZY=\0";

let code_slice = code.as_bytes();
let data_slice = data.as_bytes();
let code_packed = code_slice.as_ptr();
let data_packed = data_slice.as_ptr();

unsafe {
let emulator =
tvm_emulator_create(code_packed as *const i8, data_packed as *const i8, 2);
tvm_emulator_run_get_method(emulator, 11111123, data_packed as *const i8);
assert!(!emulator.is_null());
tvm_emulator_destroy(emulator);
}
}
}
pub use tx_emulator::*;
32 changes: 22 additions & 10 deletions src/tonlibjson.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
extern "C" {
pub fn tonlib_client_json_create() -> *mut ::std::os::raw::c_void;
}
extern "C" {

pub fn tonlib_client_json_send(
client: *mut ::std::os::raw::c_void,
request: *const ::std::os::raw::c_char,
);
}
extern "C" {

pub fn tonlib_client_json_receive(
client: *mut ::std::os::raw::c_void,
timeout: f64,
) -> *const ::std::os::raw::c_char;
}
extern "C" {

pub fn tonlib_client_json_execute(
client: *mut ::std::os::raw::c_void,
request: *const ::std::os::raw::c_char,
) -> *const ::std::os::raw::c_char;
}
extern "C" {

pub fn tonlib_client_json_destroy(client: *mut ::std::os::raw::c_void);
}
extern "C" {

pub fn tonlib_client_set_verbosity_level(verbosity_level: u32);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_creates_client() {
unsafe {
let client = tonlib_client_json_create();
tonlib_client_set_verbosity_level(4);
assert!(!client.is_null());
tonlib_client_json_send(client, "123\0".as_bytes().as_ptr() as *const i8);
tonlib_client_json_receive(client, 1.0);
tonlib_client_json_destroy(client);
}
}
}
42 changes: 25 additions & 17 deletions src/tvm_emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ extern "C" {
data: *const ::std::os::raw::c_char,
vm_log_verbosity: u32,
) -> *mut ::std::os::raw::c_void;
}

extern "C" {
/**
* @brief Set libraries for TVM emulator
* @param libs_boc Base64 encoded BoC serialized libraries dictionary (HashmapE 256 ^Cell).
Expand All @@ -23,9 +21,7 @@ extern "C" {
tvm_emulator: *mut ::std::os::raw::c_void,
libs_boc: *const ::std::os::raw::c_char,
) -> bool;
}

extern "C" {
/**
* @brief Set c7 parameters
* @param tvm_emulator Pointer to TVM emulator
Expand All @@ -44,9 +40,7 @@ extern "C" {
rand_seed_hex: *const ::std::os::raw::c_char,
config: *const ::std::os::raw::c_char,
) -> bool;
}

extern "C" {
/**
* @brief Set TVM gas limit
* @param tvm_emulator Pointer to TVM emulator
Expand All @@ -57,9 +51,7 @@ extern "C" {
tvm_emulator: *mut ::std::os::raw::c_void,
gas_limit: u64,
) -> bool;
}

extern "C" {
/**
* @brief Enable or disable TVM debug primitives
* @param tvm_emulator Pointer to TVM emulator
Expand All @@ -71,9 +63,6 @@ extern "C" {
debug_enabled: ::std::os::raw::c_int,
) -> bool;

}

extern "C" {
/**
* @brief Run get method
* @param tvm_emulator Pointer to TVM emulator
Expand All @@ -99,9 +88,7 @@ extern "C" {
method_id: i32,
stack_boc: *const ::std::os::raw::c_char,
) -> *const ::std::os::raw::c_char;
}

extern "C" {
/**
* @brief Send external message
* @param tvm_emulator Pointer to TVM emulator
Expand All @@ -128,9 +115,7 @@ extern "C" {
tvm_emulator: *mut ::std::os::raw::c_void,
message_body_boc: *const ::std::os::raw::c_char,
) -> *const ::std::os::raw::c_char;
}

extern "C" {
/**
* @brief Send internal message
* @param tvm_emulator Pointer to TVM emulator
Expand Down Expand Up @@ -159,12 +144,35 @@ extern "C" {
message_body_boc: *const ::std::os::raw::c_char,
amount: u64,
) -> *const ::std::os::raw::c_char;
}

extern "C" {
/**
* @brief Destroy TVM emulator object
* @param tvm_emulator Pointer to TVM emulator object
*/
pub fn tvm_emulator_destroy(tvm_emulator: *mut ::std::os::raw::c_void);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_creates_tvm_emulator() {
let code = "te6cckECCwEAAe0AART/APSkE/S88sgLAQIBYgIDAgLMBAUCA3pgCQoD79mRDjgEit8GhpgYC42Eit8H0gGADpj+mf9qJofQB9IGpqGEAKqThdRxgamqiq44L5cCSA/SB9AGoYEGhAMGuQ/QAYEogaKCF4BFAqkGQoAn0BLGeLZmZk9qpwQQg97svvKThdcYEakuAB8YEYAmACcYEvgsIH+XhAYHCACT38FCIBuCoQCaoKAeQoAn0BLGeLAOeLZmSRZGWAiXoAegBlgGSQfIA4OmRlgWUD5f/k6DvADGRlgqxniygCfQEJ5bWJZmZkuP2AQA/jYD+gD6QPgoVBIIcFQgE1QUA8hQBPoCWM8WAc8WzMkiyMsBEvQA9ADLAMn5AHB0yMsCygfL/8nQUAjHBfLgShKhA1AkyFAE+gJYzxbMzMntVAH6QDAg1wsBwwCOH4IQ1TJ223CAEMjLBVADzxYi+gISy2rLH8s/yYBC+wCRW+IAMDUVxwXy4En6QDBZyFAE+gJYzxbMzMntVAAuUUPHBfLgSdQwAchQBPoCWM8WzMzJ7VQAfa289qJofQB9IGpqGDYY/BQAuCoQCaoKAeQoAn0BLGeLAOeLZmSRZGWAiXoAegBlgGT8gDg6ZGWBZQPl/+ToQAAfrxb2omh9AH0gamoYP6qQQFEAfwk=\0";

let data = "te6cckECFAEAA3wAAlFwOPUE4QoACAG/b+7lv/B/MjjfQ11sWK3b4LOpS7Bc7BSmJBVmyz5hdQECAEoBaHR0cHM6Ly90YXJhbnRpbmk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8WAc8WzMntVIH++ZZY=\0";

let code_slice = code.as_bytes();
let data_slice = data.as_bytes();
let code_packed = code_slice.as_ptr();
let data_packed = data_slice.as_ptr();

unsafe {
let emulator =
tvm_emulator_create(code_packed as *const i8, data_packed as *const i8, 2);
tvm_emulator_run_get_method(emulator, 11111123, data_packed as *const i8);
assert!(!emulator.is_null());
tvm_emulator_destroy(emulator);
}
}
}
Loading
Loading