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

Added tips about dynamic libraries #117

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 47 additions & 2 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contracts/ckb-std-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ edition = "2021"
ckb-std = { path = "../../", features = ["build-with-clang", "dlopen-c", "log"] }
blake2b-ref = { version = "0.3", default-features = false }
bytes = { version = "1.7", default-features = false }
lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] }
log = { version = "0.4", default-features = false }
spin = { version = "0.9" }
32 changes: 22 additions & 10 deletions contracts/ckb-std-tests/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use ckb_std::{dynamic_loading, dynamic_loading_c_impl};
use core::ffi::c_void;
#[cfg(target_arch = "riscv64")]
use core::mem::size_of_val;
#[cfg(target_arch = "riscv64")]
use lazy_static::lazy_static;
#[cfg(target_arch = "riscv64")]
use spin::Mutex;

fn new_blake2b() -> Blake2b {
const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash";
Expand Down Expand Up @@ -795,6 +799,19 @@ fn test_log() {
ckb_std::log::error!("this is error");
}

#[cfg(target_arch = "riscv64")]
lazy_static! {
// Context should not be dropped.
static ref old_context: Mutex<ContextTypeOld> = {
#[allow(deprecated)]
Mutex::new(unsafe { ContextTypeOld::new() })
};
// Context should not be dropped.
static ref new_context: Mutex<ContextType> = {
Mutex::new(unsafe { ContextType::new() })
};
}

pub fn main() -> Result<(), Error> {
test_basic();
test_load_data();
Expand All @@ -805,6 +822,11 @@ pub fn main() -> Result<(), Error> {
test_query();
test_calc_data_hash();

#[cfg(target_arch = "riscv64")]
test_dynamic_loading(&mut old_context.lock());
#[cfg(target_arch = "riscv64")]
test_dynamic_loading_c_impl(&mut new_context.lock());

test_vm_version();
test_current_cycles();
test_since();
Expand All @@ -815,15 +837,5 @@ pub fn main() -> Result<(), Error> {
test_log();
}

#[cfg(target_arch = "riscv64")]
unsafe {
let mut context = ContextType::new();
#[allow(deprecated)]
let mut old_context = ContextTypeOld::new();

test_dynamic_loading(&mut old_context);
test_dynamic_loading_c_impl(&mut context);
}

Ok(())
}
2 changes: 2 additions & 0 deletions test/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ path = "src/exec_callee.rs"
ckb-std = { path = "../..", default-features=false, features = ["allocator", "calc-hash", "ckb-types", "libc", "native-simulator"] }
blake2b-ref = { version = "0.3", default-features = false }
bytes = { version = "1.6.0", default-features = false }
lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] }
log = { version = "0.4.17", default-features = false }
spin = { version = "0.9" }

[dev-dependencies]
libloading = "0.8.4"