Skip to content

Commit e5b3c7e

Browse files
committed
[host/{build,lib,uninit}] added feature flag to remove logging build details
git2 uses deep C bindings to libgit2 that might not be available on every target, we should allow disabling logging build details. Signed-off-by: danbugs <[email protected]>
1 parent eaec02c commit e5b3c7e

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/hyperlight_host/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ proc-maps = "0.4.0"
113113
[build-dependencies]
114114
anyhow = { version = "1.0.98" }
115115
cfg_aliases = "0.2.1"
116-
built = { version = "0.8.0", features = ["chrono", "git2"] }
116+
built = { version = "0.8.0", optional = true, features = ["chrono", "git2"] }
117117

118118
[features]
119-
default = ["kvm", "mshv2", "seccomp"]
119+
default = ["kvm", "mshv2", "seccomp", "build-metadata"]
120120
seccomp = ["dep:seccompiler"]
121121
function_call_metrics = []
122122
executable_heap = []
@@ -130,6 +130,7 @@ inprocess = []
130130
# This enables easy debug in the guest
131131
gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
132132
fuzzing = ["hyperlight-common/fuzzing"]
133+
build-metadata = ["dep:built"]
133134

134135
[[bench]]
135136
name = "benchmarks"

src/hyperlight_host/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
use anyhow::Result;
18+
#[cfg(feature = "build-metadata")]
1819
use built::write_built_file;
1920

2021
fn main() -> Result<()> {
@@ -106,6 +107,7 @@ fn main() -> Result<()> {
106107
mshv3: { all(feature = "mshv3", target_os = "linux") },
107108
}
108109

110+
#[cfg(feature = "build-metadata")]
109111
write_built_file()?;
110112

111113
Ok(())

src/hyperlight_host/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ limitations under the License.
2222
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))]
2323
#![cfg_attr(any(test, debug_assertions), allow(clippy::disallowed_macros))]
2424

25+
#[cfg(feature = "build-metadata")]
2526
use std::sync::Once;
2627

27-
use log::info;
28+
#[cfg(feature = "build-metadata")]
2829
/// The `built` crate is used to generate a `built.rs` file that contains
2930
/// information about the build environment. This information is used to
3031
/// populate the `built_info` module, which is re-exported here.
@@ -149,9 +150,12 @@ macro_rules! debug {
149150
}
150151

151152
// LOG_ONCE is used to log information about the crate version once
153+
#[cfg(feature = "build-metadata")]
152154
static LOG_ONCE: Once = Once::new();
153155

156+
#[cfg(feature = "build-metadata")]
154157
pub(crate) fn log_build_details() {
158+
use log::info;
155159
LOG_ONCE.call_once(|| {
156160
info!("Package name: {}", built_info::PKG_NAME);
157161
info!("Package version: {}", built_info::PKG_VERSION);

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ use super::mem_mgr::MemMgrWrapper;
3030
use super::run_options::SandboxRunOptions;
3131
use super::uninitialized_evolve::evolve_impl_multi_use;
3232
use crate::func::host_functions::{HostFunction, IntoHostFunction};
33+
#[cfg(feature = "build-metadata")]
34+
use crate::log_build_details;
3335
use crate::mem::exe::ExeInfo;
3436
use crate::mem::mgr::{SandboxMemoryManager, STACK_COOKIE_LEN};
3537
use crate::mem::shared_mem::ExclusiveSharedMemory;
3638
use crate::sandbox::SandboxConfiguration;
3739
use crate::sandbox_state::sandbox::EvolvableSandbox;
3840
use crate::sandbox_state::transition::Noop;
39-
use crate::{log_build_details, log_then_return, new_error, MultiUseSandbox, Result};
41+
use crate::{log_then_return, new_error, MultiUseSandbox, Result};
4042

4143
/// A preliminary `Sandbox`, not yet ready to execute guest code.
4244
///
@@ -129,6 +131,7 @@ impl UninitializedSandbox {
129131
sandbox_run_options: Option<SandboxRunOptions>,
130132
host_print_writer: Option<&dyn HostFunction<i32, (String,)>>,
131133
) -> Result<Self> {
134+
#[cfg(feature = "build-metadata")]
132135
log_build_details();
133136

134137
// hyperlight is only supported on Windows 11 and Windows Server 2022 and later

0 commit comments

Comments
 (0)