Skip to content

Commit a10b86c

Browse files
authored
Run clippy on guests in CI (#237)
* Clippy guests Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com> * Add matrix target to recipe Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com> * fix broken rebase Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com> --------- Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com>
1 parent 137457c commit a10b86c

File tree

7 files changed

+95
-87
lines changed

7 files changed

+95
-87
lines changed

.github/workflows/dep_rust.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ jobs:
5858
run: just fmt-check
5959

6060
- name: clippy
61-
run: just clippy ${{ matrix.config }}
61+
run: |
62+
just clippy ${{ matrix.config }}
63+
just clippy-guests ${{ matrix.config }}
6264
6365
# Does not check for updated Cargo.lock files for test rust guests as this causes an issue with this checkwhen deoendabot updates dependencies in common crates
6466
- name: Ensure up-to-date Cargo.lock

Justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ fmt-apply:
138138
clippy target=default-target:
139139
cargo clippy --all-targets --all-features --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
140140

141+
clippy-guests target=default-target:
142+
cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
143+
cd src/tests/rust_guests/callbackguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
144+
141145
clippy-apply-fix-unix:
142146
cargo clippy --fix --all
143147

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
5858

5959
let p_function = unsafe {
6060
let function_pointer = registered_function_definition.function_pointer;
61-
core::mem::transmute::<i64, GuestFunc>(function_pointer)
61+
core::mem::transmute::<usize, GuestFunc>(function_pointer)
6262
};
6363

6464
p_function(&function_call)

src/hyperlight_guest/src/guest_function_definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct GuestFunctionDefinition {
3333
/// The type of the return value from the host function call
3434
pub return_type: ReturnType,
3535
/// The function pointer to the guest function
36-
pub function_pointer: i64,
36+
pub function_pointer: usize,
3737
}
3838

3939
impl GuestFunctionDefinition {
@@ -42,7 +42,7 @@ impl GuestFunctionDefinition {
4242
function_name: String,
4343
parameter_types: Vec<ParameterType>,
4444
return_type: ReturnType,
45-
function_pointer: i64,
45+
function_pointer: usize,
4646
) -> Self {
4747
Self {
4848
function_name,

src/hyperlight_guest_capi/src/dispatch.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
3939
let ffi_func_call = FfiFunctionCall::from_function_call(function_call)?;
4040

4141
let guest_func =
42-
unsafe { mem::transmute::<i64, CGuestFunc>(registered_func.function_pointer) };
42+
unsafe { mem::transmute::<usize, CGuestFunc>(registered_func.function_pointer) };
4343
let function_result = guest_func(&ffi_func_call);
4444

4545
unsafe { Ok(FfiVec::into_vec(*function_result)) }
@@ -76,12 +76,8 @@ pub extern "C" fn hl_register_function_definition(
7676

7777
let func_params = unsafe { slice::from_raw_parts(params_type, param_no).to_vec() };
7878

79-
let func_def = GuestFunctionDefinition::new(
80-
func_name,
81-
func_params,
82-
return_type,
83-
func_ptr as usize as i64,
84-
);
79+
let func_def =
80+
GuestFunctionDefinition::new(func_name, func_params, return_type, func_ptr as usize);
8581

8682
#[allow(static_mut_refs)]
8783
unsafe { &mut REGISTERED_C_GUEST_FUNCTIONS }.register(func_def);

src/tests/rust_guests/callbackguest/src/main.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,47 +60,47 @@ fn guest_function(function_call: &FunctionCall) -> Result<Vec<u8>> {
6060
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
6161
send_message_to_host_method("HostMethod", "Hello from GuestFunction, ", message)
6262
} else {
63-
return Err(HyperlightGuestError::new(
63+
Err(HyperlightGuestError::new(
6464
ErrorCode::GuestFunctionParameterTypeMismatch,
6565
"Invalid parameters passed to guest_function".to_string(),
66-
));
66+
))
6767
}
6868
}
6969

7070
fn guest_function1(function_call: &FunctionCall) -> Result<Vec<u8>> {
7171
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
7272
send_message_to_host_method("HostMethod1", "Hello from GuestFunction1, ", message)
7373
} else {
74-
return Err(HyperlightGuestError::new(
74+
Err(HyperlightGuestError::new(
7575
ErrorCode::GuestFunctionParameterTypeMismatch,
7676
"Invalid parameters passed to guest_function1".to_string(),
77-
));
77+
))
7878
}
7979
}
8080

8181
fn guest_function2(function_call: &FunctionCall) -> Result<Vec<u8>> {
8282
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
8383
send_message_to_host_method("HostMethod1", "Hello from GuestFunction2, ", message)
8484
} else {
85-
return Err(HyperlightGuestError::new(
85+
Err(HyperlightGuestError::new(
8686
ErrorCode::GuestFunctionParameterTypeMismatch,
8787
"Invalid parameters passed to guest_function2".to_string(),
88-
));
88+
))
8989
}
9090
}
9191

9292
fn guest_function3(function_call: &FunctionCall) -> Result<Vec<u8>> {
9393
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
9494
send_message_to_host_method("HostMethod1", "Hello from GuestFunction3, ", message)
9595
} else {
96-
return Err(HyperlightGuestError::new(
96+
Err(HyperlightGuestError::new(
9797
ErrorCode::GuestFunctionParameterTypeMismatch,
9898
"Invalid parameters passed to guest_function3".to_string(),
99-
));
99+
))
100100
}
101101
}
102102

103-
fn guest_function4() -> Result<Vec<u8>> {
103+
fn guest_function4(_: &FunctionCall) -> Result<Vec<u8>> {
104104
call_host_function(
105105
"HostMethod4",
106106
Some(Vec::from(&[ParameterValue::String(
@@ -123,7 +123,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
123123
&function_call.parameters.as_ref().unwrap()[2],
124124
) {
125125
let mut log_level = *level;
126-
if log_level < 0 || log_level > 6 {
126+
if !(0..=6).contains(&log_level) {
127127
log_level = 0;
128128
}
129129

@@ -138,25 +138,25 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
138138

139139
Ok(get_flatbuffer_result(message.len() as i32))
140140
} else {
141-
return Err(HyperlightGuestError::new(
141+
Err(HyperlightGuestError::new(
142142
ErrorCode::GuestFunctionParameterTypeMismatch,
143143
"Invalid parameters passed to guest_log_message".to_string(),
144-
));
144+
))
145145
}
146146
}
147147

148148
fn call_error_method(function_call: &FunctionCall) -> Result<Vec<u8>> {
149149
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
150150
send_message_to_host_method("ErrorMethod", "Error From Host: ", message)
151151
} else {
152-
return Err(HyperlightGuestError::new(
152+
Err(HyperlightGuestError::new(
153153
ErrorCode::GuestFunctionParameterTypeMismatch,
154154
"Invalid parameters passed to call_error_method".to_string(),
155-
));
155+
))
156156
}
157157
}
158158

159-
fn call_host_spin() -> Result<Vec<u8>> {
159+
fn call_host_spin(_: &FunctionCall) -> Result<Vec<u8>> {
160160
call_host_function("Spin", None, ReturnType::Void)?;
161161
Ok(get_flatbuffer_result(()))
162162
}
@@ -167,47 +167,47 @@ pub extern "C" fn hyperlight_main() {
167167
"PrintOutput".to_string(),
168168
Vec::from(&[ParameterType::String]),
169169
ReturnType::Int,
170-
print_output_as_guest_function as i64,
170+
print_output_as_guest_function as usize,
171171
);
172172
register_function(print_output_def);
173173

174174
let guest_function_def = GuestFunctionDefinition::new(
175175
"GuestMethod".to_string(),
176176
Vec::from(&[ParameterType::String]),
177177
ReturnType::Int,
178-
guest_function as i64,
178+
guest_function as usize,
179179
);
180180
register_function(guest_function_def);
181181

182182
let guest_function1_def = GuestFunctionDefinition::new(
183183
"GuestMethod1".to_string(),
184184
Vec::from(&[ParameterType::String]),
185185
ReturnType::Int,
186-
guest_function1 as i64,
186+
guest_function1 as usize,
187187
);
188188
register_function(guest_function1_def);
189189

190190
let guest_function2_def = GuestFunctionDefinition::new(
191191
"GuestMethod2".to_string(),
192192
Vec::from(&[ParameterType::String]),
193193
ReturnType::Int,
194-
guest_function2 as i64,
194+
guest_function2 as usize,
195195
);
196196
register_function(guest_function2_def);
197197

198198
let guest_function3_def = GuestFunctionDefinition::new(
199199
"GuestMethod3".to_string(),
200200
Vec::from(&[ParameterType::String]),
201201
ReturnType::Int,
202-
guest_function3 as i64,
202+
guest_function3 as usize,
203203
);
204204
register_function(guest_function3_def);
205205

206206
let guest_function4_def = GuestFunctionDefinition::new(
207207
"GuestMethod4".to_string(),
208208
Vec::new(),
209209
ReturnType::Int,
210-
guest_function4 as i64,
210+
guest_function4 as usize,
211211
);
212212
register_function(guest_function4_def);
213213

@@ -219,23 +219,23 @@ pub extern "C" fn hyperlight_main() {
219219
ParameterType::Int,
220220
]),
221221
ReturnType::Int,
222-
guest_log_message as i64,
222+
guest_log_message as usize,
223223
);
224224
register_function(guest_log_message_def);
225225

226226
let call_error_method_def = GuestFunctionDefinition::new(
227227
"CallErrorMethod".to_string(),
228228
Vec::from(&[ParameterType::String]),
229229
ReturnType::Int,
230-
call_error_method as i64,
230+
call_error_method as usize,
231231
);
232232
register_function(call_error_method_def);
233233

234234
let call_host_spin_def = GuestFunctionDefinition::new(
235235
"CallHostSpin".to_string(),
236236
Vec::new(),
237237
ReturnType::Int,
238-
call_host_spin as i64,
238+
call_host_spin as usize,
239239
);
240240
register_function(call_host_spin_def);
241241
}

0 commit comments

Comments
 (0)