Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit f054442

Browse files
committed
Enable the uffd feature by default, but filter on OS
Notably, this should get us building and running uffd in Linux CI. It turns out to be a tremendous pain to enable a feature flag for just one crate within a workspace. The situation is [being addressed][1], but in the meantime I believe the best route forward is to just have uffd on by default for Linux. [1]: rust-lang/cargo#5364
1 parent ab7a76b commit f054442

File tree

14 files changed

+25
-16
lines changed

14 files changed

+25
-16
lines changed

lucet-runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ assets = [
4949
]
5050

5151
[features]
52-
default-features = []
52+
default = ["uffd"]
5353
uffd = ["lucet-runtime-internals/uffd"]
5454

5555
[package.metadata.docs.rs]

lucet-runtime/lucet-runtime-internals/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ num-traits = "0.2"
2727
raw-cpuid = "6.0.0"
2828
thiserror = "1.0.4"
2929
tracing = "0.1.12"
30+
31+
[target.'cfg(target_os = "linux")'.dependencies]
3032
userfaultfd = { version = "0.1.0", optional = true }
3133

3234
# This is only a dependency to ensure that other crates don't pick a newer version as a transitive
@@ -43,7 +45,7 @@ byteorder = "1.2"
4345
cc = "1.0"
4446

4547
[features]
46-
default-features = []
48+
default = ["uffd"]
4749
uffd = ["userfaultfd"]
4850

4951
[package.metadata.docs.rs]

lucet-runtime/lucet-runtime-internals/src/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod mmap;
22

3-
#[cfg(feature = "uffd")]
3+
#[cfg(all(target_os = "linux", feature = "uffd"))]
44
pub mod uffd;
55

66
use crate::alloc::{Alloc, Limits, Slot};

lucet-runtime/src/c_api.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "uffd")]
1+
#[cfg(all(target_os = "linux", feature = "uffd"))]
22
use crate::UffdRegion;
33
use crate::{DlModule, Instance, Limits, MmapRegion, Module, Region};
44
use libc::{c_char, c_int, c_void};
@@ -103,7 +103,7 @@ pub unsafe extern "C" fn lucet_uffd_region_create(
103103
region_out: *mut *mut lucet_region,
104104
) -> lucet_error {
105105
cfg_if::cfg_if! {
106-
if #[cfg(feature = "uffd")] {
106+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
107107
assert_nonnull!(region_out);
108108
let limits = limits
109109
.as_ref()

lucet-runtime/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,14 @@
386386
//! `Instance`, reducing startup time. Instance stack pages can also be lazily initialized, reducing
387387
//! the memory footprint of instances that only use a small portion of their available stack space.
388388
//!
389-
//! To use `UffdRegion`, enable the `uffd` Cargo feature, which is off by default.
389+
//! `UffdRegion` is enabled by default on Linux platforms, but can be disabled by disabling default
390+
//! features for this crate and `lucet-runtime-internals`:
391+
//!
392+
//! ```toml
393+
//! [dependencies]
394+
//! lucet-runtime = { version = "0.6.1", default-features = false }
395+
//! lucet-runtime-internals = { version = "0.6.1", default-features = false }
396+
//! ```
390397
391398
#![deny(bare_trait_objects)]
392399

@@ -410,7 +417,7 @@ pub use lucet_runtime_internals::instance::{
410417
pub use lucet_runtime_internals::lucet_hostcalls;
411418
pub use lucet_runtime_internals::module::{DlModule, Module};
412419
pub use lucet_runtime_internals::region::mmap::MmapRegion;
413-
#[cfg(feature = "uffd")]
420+
#[cfg(all(target_os = "linux", feature = "uffd"))]
414421
pub use lucet_runtime_internals::region::uffd::UffdRegion;
415422
pub use lucet_runtime_internals::region::{InstanceBuilder, Region, RegionCreate};
416423
pub use lucet_runtime_internals::val::{UntypedRetVal, Val};

lucet-runtime/tests/entrypoint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::entrypoint_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
entrypoint_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/globals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::globals_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
globals_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/guest_fault.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::guest_fault_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
guest_fault_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/host.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::host_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
host_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::memory_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
memory_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::stack_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
stack_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/start.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::start_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
start_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/strcmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::strcmp_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
strcmp_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

lucet-runtime/tests/timeout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lucet_runtime_tests::timeout_tests;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(feature = "uffd")] {
4+
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
55
timeout_tests!(
66
mmap => lucet_runtime::MmapRegion,
77
uffd => lucet_runtime::UffdRegion

0 commit comments

Comments
 (0)