1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use lazy_static::lazy_static; use std::sync::{
Mutex,
MutexGuard
};
pub mod interfaces;
pub mod client;
pub use client::{
new_vm_api_client,
ChainTester,
get_vm_api_client,
close_vm_api_client,
set_apply,
get_globals,
GetTableRowsPrams,
};
pub mod server;
pub struct DebuggerConfig {
pub debugger_server_address: String,
pub debugger_server_port: u16,
pub vm_api_server_address: String,
pub vm_api_server_port: u16,
pub apply_request_server_address: String,
pub apply_request_server_port: u16,
}
impl DebuggerConfig {
fn new() -> Self {
Self {
debugger_server_address: "127.0.0.1".into(),
debugger_server_port: 9090,
vm_api_server_address: "127.0.0.1".into(),
vm_api_server_port: 9092,
apply_request_server_address: "127.0.0.1".into(),
apply_request_server_port: 9091,
}
}
}
lazy_static! {
static ref DEBUGGER_CONFIG: Mutex<DebuggerConfig> = Mutex::new(DebuggerConfig::new());
}
pub fn get_debugger_config() -> MutexGuard<'static, DebuggerConfig> {
return DEBUGGER_CONFIG.lock().unwrap()
}
extern "Rust" {
pub fn __eosio_generate_abi() -> String;
}
lazy_static! {
static ref BUILD_CONTRACT_MUTEX: Mutex<std::collections::HashMap<String, String>> = Mutex::new(std::collections::HashMap::new());
}
pub fn build_contract(package_name: &str, project_dir: &str) {
println!("++++++building {package_name} at {project_dir}");
let mut build_contract = BUILD_CONTRACT_MUTEX.lock().unwrap();
if build_contract.get(package_name).is_some() {
return;
}
build_contract.insert(package_name.into(), project_dir.into());
std::env::set_var("RUSTFLAGS", "-C link-arg=-zstack-size=8192 -Clinker-plugin-lto");
let mut cmd = std::process::Command::new("cargo");
cmd
.args([
"+nightly",
"build",
"--target=wasm32-wasi",
&format!("--target-dir={project_dir}/target"),
"-Zbuild-std",
"--no-default-features",
"--release",
"-Zbuild-std-features=panic_immediate_abort"
]
);
let mut child = cmd
.stdout(std::process::Stdio::null())
.spawn()
.expect("command failed to start");
let output = child.wait().unwrap();
if !output.success() {
panic!("build failed");
}
let in_wasm_file = format!("{project_dir}/target/wasm32-wasi/release/{}.wasm", package_name);
let out_wasm_file = format!("{project_dir}/target/{}.wasm", package_name);
let wasm = std::fs::read(in_wasm_file).unwrap();
std::fs::write(out_wasm_file, wasm).unwrap();
}