Skip to content

Commit 9008214

Browse files
committed
Updates to make clippy happy
Since clippy runs with --all-features and the mshv2 and mshv3 features are mutually exclusive these changes ensure that clippy is able to run and we can still enforce mutually exclusivity Signed-off-by: Simon Davies <[email protected]>
1 parent 60f14bf commit 9008214

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

src/hyperlight_host/build.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ use anyhow::Result;
1818
use built::write_built_file;
1919

2020
fn main() -> Result<()> {
21-
// mshv2 and mshv3 features are mutually exclusive.
22-
#[cfg(all(feature = "mshv2", feature = "mshv3"))]
23-
panic!("mshv2 and mshv3 features are mutually exclusive");
24-
2521
// re-run the build if this script is changed (or deleted!),
2622
// even if the rust code is completely unchanged.
2723
println!("cargo:rerun-if-changed=build.rs");
@@ -98,9 +94,18 @@ fn main() -> Result<()> {
9894
// inprocess feature is aliased with debug_assertions to make it only available in debug-builds.
9995
// You should never use #[cfg(feature = "inprocess")] in the codebase. Use #[cfg(inprocess)] instead.
10096
inprocess: { all(feature = "inprocess", debug_assertions) },
97+
// the following is a bit of a hack to stop clippy failing wehn run with -all features as it enables both mshv2 and mshv3 at the same time causing errors
98+
mshv2: { all(feature = "mshv2", target_os = "linux", not(clippy)) },
99+
mshv3: { all(feature = "mshv3", target_os = "linux") },
101100
}
102101

103102
write_built_file()?;
104103

104+
// mshv2 and mshv3 features are mutually exclusive
105+
#[cfg(all(feature = "mshv2", feature = "mshv3", not(clippy)))]
106+
Err(anyhow::anyhow!(
107+
"mshv2 and mshv3 features are mutually exclusive"
108+
))?;
109+
105110
Ok(())
106111
}

src/hyperlight_host/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg(feature = "mshv2")]
17+
#[cfg(mshv2)]
1818
extern crate mshv_ioctls2 as mshv_ioctls;
1919

20-
#[cfg(feature = "mshv3")]
20+
#[cfg(mshv3)]
2121
extern crate mshv_ioctls3 as mshv_ioctls;
2222

2323
use std::array::TryFromSliceError;

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg(feature = "mshv2")]
17+
#[cfg(mshv2)]
1818
extern crate mshv_bindings2 as mshv_bindings;
19-
#[cfg(feature = "mshv2")]
19+
#[cfg(mshv2)]
2020
extern crate mshv_ioctls2 as mshv_ioctls;
2121

22-
#[cfg(feature = "mshv3")]
22+
#[cfg(mshv3)]
2323
extern crate mshv_bindings3 as mshv_bindings;
24-
#[cfg(feature = "mshv3")]
24+
#[cfg(mshv3)]
2525
extern crate mshv_ioctls3 as mshv_ioctls;
2626

2727
use std::fmt::{Debug, Formatter};
2828

2929
use log::error;
30-
#[cfg(feature = "mshv2")]
30+
#[cfg(mshv2)]
3131
use mshv_bindings::hv_message;
3232
use mshv_bindings::{
3333
hv_message_type, hv_message_type_HVMSG_GPA_INTERCEPT, hv_message_type_HVMSG_UNMAPPED_GPA,
3434
hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc,
3535
hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region,
3636
FloatingPointUnit, SegmentRegister, SpecialRegisters, StandardRegisters,
3737
};
38-
#[cfg(feature = "mshv3")]
38+
#[cfg(mshv3)]
3939
use mshv_bindings::{
4040
hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
4141
hv_partition_synthetic_processor_features,
@@ -105,9 +105,9 @@ impl HypervLinuxDriver {
105105
}
106106
let mshv = Mshv::new()?;
107107
let pr = Default::default();
108-
#[cfg(feature = "mshv2")]
108+
#[cfg(mshv2)]
109109
let vm_fd = mshv.create_vm_with_config(&pr)?;
110-
#[cfg(feature = "mshv3")]
110+
#[cfg(mshv3)]
111111
let vm_fd = {
112112
let vm_fd = mshv.create_vm_with_args(&pr)?;
113113
let features: hv_partition_synthetic_processor_features = Default::default();
@@ -311,12 +311,12 @@ impl Hypervisor for HypervLinuxDriver {
311311
const UNMAPPED_GPA_MESSAGE: hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
312312
const INVALID_GPA_ACCESS_MESSAGE: hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
313313

314-
#[cfg(feature = "mshv2")]
314+
#[cfg(mshv2)]
315315
let run_result = {
316316
let hv_message: hv_message = Default::default();
317317
&self.vcpu_fd.run(hv_message)
318318
};
319-
#[cfg(feature = "mshv3")]
319+
#[cfg(mshv3)]
320320
let run_result = &self.vcpu_fd.run();
321321

322322
let result = match run_result {

src/hyperlight_host/src/mem/memory_region.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg(feature = "mshv2")]
17+
#[cfg(mshv2)]
1818
extern crate mshv_bindings2 as mshv_bindings;
19-
#[cfg(feature = "mshv2")]
19+
#[cfg(mshv2)]
2020
extern crate mshv_ioctls2 as mshv_ioctls;
2121

22-
#[cfg(feature = "mshv3")]
22+
#[cfg(mshv3)]
2323
extern crate mshv_bindings3 as mshv_bindings;
24-
#[cfg(feature = "mshv3")]
24+
#[cfg(mshv3)]
2525
extern crate mshv_ioctls3 as mshv_ioctls;
2626

2727
use std::ops::Range;
@@ -32,11 +32,11 @@ use hyperlight_common::mem::PAGE_SHIFT;
3232
use hyperlight_common::mem::PAGE_SIZE_USIZE;
3333
#[cfg(mshv)]
3434
use mshv_bindings::{hv_x64_memory_intercept_message, mshv_user_mem_region};
35-
#[cfg(feature = "mshv2")]
35+
#[cfg(mshv2)]
3636
use mshv_bindings::{
3737
HV_MAP_GPA_EXECUTABLE, HV_MAP_GPA_PERMISSIONS_NONE, HV_MAP_GPA_READABLE, HV_MAP_GPA_WRITABLE,
3838
};
39-
#[cfg(feature = "mshv3")]
39+
#[cfg(mshv3)]
4040
use mshv_bindings::{
4141
MSHV_SET_MEM_BIT_EXECUTABLE, MSHV_SET_MEM_BIT_UNMAP, MSHV_SET_MEM_BIT_WRITABLE,
4242
};
@@ -242,7 +242,7 @@ impl From<MemoryRegion> for mshv_user_mem_region {
242242
let guest_pfn = region.guest_region.start as u64 >> PAGE_SHIFT;
243243
let userspace_addr = region.host_region.start as u64;
244244

245-
#[cfg(feature = "mshv2")]
245+
#[cfg(mshv2)]
246246
{
247247
let flags = region.flags.iter().fold(0, |acc, flag| {
248248
let flag_value = match flag {
@@ -261,7 +261,7 @@ impl From<MemoryRegion> for mshv_user_mem_region {
261261
flags,
262262
}
263263
}
264-
#[cfg(feature = "mshv3")]
264+
#[cfg(mshv3)]
265265
{
266266
let flags: u8 = region.flags.iter().fold(0, |acc, flag| {
267267
let flag_value = match flag {

0 commit comments

Comments
 (0)