From 2ce778f5b15a8a0b769752ad425078708957a2ab Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Wed, 1 Sep 2021 16:51:54 +0800 Subject: [PATCH] chore: support ckb2021 --- Cargo.toml | 6 +++--- Makefile | 2 +- build.rs | 4 ++-- rust-toolchain | 2 +- src/dynamic_loading_c_impl.rs | 39 +++++++++++++++++++++++------------ test/Cargo.toml | 3 +-- test/contract/Cargo.toml | 2 +- test/src/contract.rs | 2 +- 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 402456a..9663b69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-std" -version = "0.7.4" +version = "0.8.0" authors = ["Nervos network"] edition = "2018" license = "MIT" @@ -19,6 +19,6 @@ simulator = [ "ckb-x64-simulator" ] cc = "1.0" [dependencies] -ckb-types = { package = "ckb-standalone-types", version = "0.0.1-pre.1", default-features = false, optional = true } +ckb-types = { package = "ckb-standalone-types", version = "0.1.1", default-features = false, optional = true } buddy-alloc = { version = "0.4.1", optional = true } -ckb-x64-simulator = { version = "0.4.0", optional = true } +ckb-x64-simulator = { version = "0.5.0", optional = true } diff --git a/Makefile b/Makefile index 21ec270..ac2b86c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ TARGET := riscv64imac-unknown-none-elf -DOCKER_IMAGE := jjy0/ckb-capsule-recipe-rust:2020-9-28 +DOCKER_IMAGE := thewawar/ckb-capsule:2021-08-16 CC := riscv64-unknown-elf-gcc default: integration-in-docker diff --git a/build.rs b/build.rs index e0b8a94..68485e9 100644 --- a/build.rs +++ b/build.rs @@ -28,8 +28,8 @@ fn main() { cc::Build::new() .file("src/asm/syscall.S") .compile("ckb-syscall"); - build. - flag("-Wno-nonnull-compare") + build + .flag("-Wno-nonnull-compare") .flag("-nostartfiles") .compile("dl-c-impl"); } else { diff --git a/rust-toolchain b/rust-toolchain index 35312fc..ba2833d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-09-28 +nightly-2021-08-16 diff --git a/src/dynamic_loading_c_impl.rs b/src/dynamic_loading_c_impl.rs index b7fe89e..286f3e2 100644 --- a/src/dynamic_loading_c_impl.rs +++ b/src/dynamic_loading_c_impl.rs @@ -1,15 +1,20 @@ -use crate::error::SysError; use crate::debug; +use crate::error::SysError; +use core::ffi::c_void; use core::marker::PhantomData; use core::mem::{size_of, zeroed}; -use core::ffi::c_void; use core::ptr::null; -#[link(name = "dl-c-impl", kind="static")] +#[link(name = "dl-c-impl", kind = "static")] extern "C" { - fn ckb_dlopen2(dep_cell_hash: *const u8, hash_type: u8, - aligned_addr: *mut u8, aligned_size: usize, handle: *mut *const c_void, - consumed_size: *mut usize) -> isize; + fn ckb_dlopen2( + dep_cell_hash: *const u8, + hash_type: u8, + aligned_addr: *mut u8, + aligned_size: usize, + handle: *mut *const c_void, + consumed_size: *mut usize, + ) -> isize; fn ckb_dlsym(handle: *const c_void, symbol: *const u8) -> usize; } @@ -91,7 +96,10 @@ impl Library { } let ptr = ckb_dlsym(self.handle, s.as_ptr()); if ptr == 0 { - debug!("warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}", self.handle, symbol); + debug!( + "warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}", + self.handle, symbol + ); None } else { Some(Symbol::new(ptr)) @@ -102,7 +110,6 @@ impl Library { const RISCV_PGSIZE_SHIFT: usize = 12; const RISCV_PGSIZE: usize = 1 << RISCV_PGSIZE_SHIFT; // 4096 - #[repr(C)] #[repr(align(4096))] pub struct CKBDLContext(T); @@ -126,14 +133,20 @@ impl CKBDLContext { } unsafe { - let mut handle : *const c_void = null(); - let mut consumed_size : usize = 0; - let hash_type : u8 = 0; + let mut handle: *const c_void = null(); + let mut consumed_size: usize = 0; + let hash_type: u8 = 0; let mut library = Library::new(); let aligned_size = size; let aligned_addr = (&mut self.0 as *mut T).cast::().add(offset); - let code = ckb_dlopen2(dep_cell_data_hash.as_ptr(), hash_type, aligned_addr, - aligned_size, &mut handle as *mut *const c_void, &mut consumed_size as *mut usize); + let code = ckb_dlopen2( + dep_cell_data_hash.as_ptr(), + hash_type, + aligned_addr, + aligned_size, + &mut handle as *mut *const c_void, + &mut consumed_size as *mut usize, + ); if code != 0 { debug!("warning, ckb_dlopen2 return {:?}", code); return Err(Error::OpenFailed(code)); diff --git a/test/Cargo.toml b/test/Cargo.toml index 562ee9d..c1fe822 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -7,5 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ckb-tool = "0.3" -ckb-testtool = "0.3" +ckb-testtool = "0.5" diff --git a/test/contract/Cargo.toml b/test/contract/Cargo.toml index 901fc49..9caed09 100644 --- a/test/contract/Cargo.toml +++ b/test/contract/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] ckb-std = { path = "../.." } -blake2b-ref = { version = "0.1", default-features = false } +blake2b-ref = { version = "0.3", default-features = false } [build-dependencies] blake2b-rs = "0.1.5" diff --git a/test/src/contract.rs b/test/src/contract.rs index a988328..a04e18c 100644 --- a/test/src/contract.rs +++ b/test/src/contract.rs @@ -1,5 +1,5 @@ use ckb_testtool::context::Context; -use ckb_tool::ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::*, prelude::*}; +use ckb_testtool::ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::*, prelude::*}; use std::fs::File; use std::io::Read;