Skip to content

Commit

Permalink
[cli] Support windows compile (#2927)
Browse files Browse the repository at this point in the history
* [rooch] minalloc for windows

* fix compile on windows

* [rocksdb] Fix rocksdb compile on windows

* fmt

* remove libc

* fixup

* fixup

* use 127.0.0.1 to replace 0.0.0.0 in client

* fixup

* fixup
  • Loading branch information
jolestar authored Nov 20, 2024
1 parent 392e883 commit 2260029
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 57 deletions.
14 changes: 13 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ rustflags = [
"-C",
"force-unwind-tables=yes",
"-C",
"link-arg=/STACK:8000000" # Set stack to 8 MB
"link-arg=/STACK:8000000", # Set stack to 8 MB
# force static linking for the rocksdb and bitcoinconsensus crates
"-Ctarget-feature=+crt-static",
"-Clink-args=/DEFAULTLIB:libcmt.lib",
"-Clink-args=/DEFAULTLIB:libvcruntime.lib",
"-Clink-args=/DEFAULTLIB:libucrt.lib",
"-Clink-args=/DEFAULTLIB:oldnames.lib",
"-Clink-args=/DEFAULTLIB:legacy_stdio_definitions.lib",
"-Clink-args=/NODEFAULTLIB:msvcrt.lib",
"-Clink-args=/NODEFAULTLIB:msvcrtd.lib",
"-Clink-args=/NODEFAULTLIB:libcmtd.lib",
"-Clink-args=/NODEFAULTLIB:vcruntime.lib",
"-Clink-args=/NODEFAULTLIB:vcruntimed.lib"
]

[alias]
Expand Down
34 changes: 20 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ scopeguard = "1.1"
uuid = { version = "1.11.0", features = ["v4", "fast-rng"] }
protobuf = { version = "2.28", features = ["with-bytes"] }
redb = { version = "2.1.1" }
rocksdb = { git = "https://github.com/rooch-network/rust-rocksdb.git", rev = "41d102327ba3cf9a2335d1192e8312c92bc3d6f9", features = ["lz4"] }
rocksdb = { git = "https://github.com/rooch-network/rust-rocksdb.git", rev = "41d102327ba3cf9a2335d1192e8312c92bc3d6f9", features = ["lz4","mt_static"] }
lz4 = { version = "1.28.0" }
ripemd = { version = "0.1.3" }
fastcrypto-zkp = { version = "0.1.3" }
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-client/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Default for Env {
fn default() -> Self {
Env {
alias: BuiltinChainID::Local.chain_name(),
rpc: ServerConfig::default().url(false),
rpc: format!("http://127.0.0.1:{}", ServerConfig::default().port),
ws: None,
}
}
Expand Down
27 changes: 6 additions & 21 deletions crates/rooch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,29 @@ fastcrypto = { workspace = true }
log = { workspace = true }
csv = { workspace = true }
tempfile = { workspace = true }
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { version = "0.5.4", features = ["unprefixed_malloc_on_supported_platforms", "profiling"] }
rustc-hash = { workspace = true }
rand = { workspace = true }
tabled = { workspace = true }
xorf = { workspace = true }
xxhash-rust = { workspace = true, features = ["xxh3"] }
vergen-pretty = { workspace = true }
prometheus = { workspace = true }
lazy_static = { workspace = true }
schemars = { workspace = true }
bitcoin = { workspace = true }
bitcoincore-rpc = { workspace = true }
ciborium = { workspace = true }
wasmer = { workspace = true }
tiny-keccak = { workspace = true }
serenity = { features = [
"client",
"gateway",
"rustls_backend",
"cache",
"model",
], workspace = true }
futures = { workspace = true }

move-bytecode-utils = { workspace = true }
move-binary-format = { workspace = true }
move-bytecode-verifier = { workspace = true }
move-cli = { workspace = true }
move-command-line-common = { workspace = true }
move-compiler = { workspace = true }
move-core-types = { workspace = true }
move-coverage = { workspace = true }
move-disassembler = { workspace = true }
move-errmapgen = { workspace = true }
move-package = { workspace = true }
move-unit-test = { workspace = true }
move-vm-runtime = { workspace = true, features = ["stacktrace", "debugging", "testing"] }
move-vm-test-utils = { workspace = true }
move-model = { workspace = true }
move-stdlib = { workspace = true }
move-vm-types = { workspace = true }

Expand All @@ -92,15 +75,12 @@ moveos-verifier = { workspace = true }
moveos-object-runtime = { workspace = true }
moveos-compiler = { workspace = true }
moveos-config = { workspace = true }
accumulator = { workspace = true }
metrics = { workspace = true }
moveos-gas-profiling = { workspace = true }

framework-builder = { workspace = true }
framework-types = { workspace = true }
raw-store = { workspace = true }
smt = { workspace = true }
bitcoin-move = { workspace = true }

rooch-key = { workspace = true }
rooch-types = { workspace = true }
Expand All @@ -115,12 +95,17 @@ rooch-indexer = { workspace = true }
rooch-db = { workspace = true }
rooch-common = { workspace = true }
rooch-store = { workspace = true }
rooch-sequencer = { workspace = true }
rooch-faucet = { workspace = true }
rooch-oracle = { workspace = true }

framework-release = { workspace = true }

#We should keep the allocator in the last of the dependencies
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { version = "0.5.4", features = ["unprefixed_malloc_on_supported_platforms", "profiling"] }
[target.'cfg(target_env = "msvc")'.dependencies]
mimalloc = { version = "0.1.39" }

[build-dependencies]
anyhow = { workspace = true }
vergen-git2 = { workspace = true }
2 changes: 1 addition & 1 deletion crates/rooch/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl CommandAction<()> for Init {
if address_and_port_regex.is_match(&url) {
url
} else {
return Err(RoochError::CommandArgumentError("Invalid input format. Please provide a valid URL (e.g., http://0.0.0.0:6767).".to_owned()));
return Err(RoochError::CommandArgumentError("Invalid input format. Please provide a valid URL (e.g., http://127.0.0.1:6767).".to_owned()));
}
};
Some(if url.trim().is_empty() {
Expand Down
24 changes: 21 additions & 3 deletions crates/rooch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ use rooch::RoochCli;
use std::process::exit;

#[cfg(not(target_env = "msvc"))]
use jemallocator::Jemalloc;
mod allocator {
use jemallocator::Jemalloc;

pub type Allocator = Jemalloc;

pub const fn allocator() -> Allocator {
Jemalloc
}
}

#[cfg(target_env = "msvc")]
mod allocator {
use mimalloc::MiMalloc;

pub type Allocator = MiMalloc;

pub const fn allocator() -> Allocator {
MiMalloc
}
}

#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
static GLOBAL: allocator::Allocator = allocator::allocator();

/// rooch is a command line tools for Rooch Network
#[tokio::main]
Expand Down
1 change: 0 additions & 1 deletion frameworks/rooch-nursery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ log = { workspace = true }
serde_json = { workspace = true }
ciborium = { workspace = true }
wasmer = { workspace = true }
libc = { workspace = true }
cosmwasm-vm = { workspace = true }
cosmwasm-std = { workspace = true }
once_cell = { workspace = true }
Expand Down
26 changes: 13 additions & 13 deletions frameworks/rooch-nursery/src/natives/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,21 @@ fn execute_wasm_function_inner(

// TODO: check the length of arguments for the function calling

let trap_handler: Box<
dyn Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
+ Send
+ Sync
+ 'static,
> = Box::new(|signum, siginfo, ctx| {
warn!(
"Trap handler called, signum:{:?}, siginfo:{:?}, context:{:?}",
signum, siginfo, ctx
);
false
});
// let trap_handler: Box<
// dyn Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
// + Send
// + Sync
// + 'static,
// > = Box::new(|signum, siginfo, ctx| {
// warn!(
// "Trap handler called, signum:{:?}, siginfo:{:?}, context:{:?}",
// signum, siginfo, ctx
// );
// false
// });

// Set trap handler
instance.store.set_trap_handler(Some(trap_handler));
// instance.store.set_trap_handler(Some(trap_handler));

match calling_function.call(&mut instance.store, wasm_func_args.as_slice()) {
Ok(ret) => {
Expand Down
2 changes: 1 addition & 1 deletion moveos/raw-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ anyhow = { workspace = true }
serde = { workspace = true }
tap = { workspace = true }
tokio = { workspace = true }
rocksdb = { workspace = true, features = ["lz4"] }
rocksdb = { workspace = true }
parking_lot = { workspace = true }

prometheus = { workspace = true }
Expand Down
12 changes: 12 additions & 0 deletions moveos/raw-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,15 @@ where
KVStore::multiple_get(self.get_store(), encoded_keys)
}
}

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

#[test]
fn test_new_db() {
let tmpdir = moveos_config::temp_dir();
let _db = RocksDB::new(tmpdir.path(), vec![], RocksdbConfig::default()).unwrap();
}
}

0 comments on commit 2260029

Please sign in to comment.