From 806a05bb6bcbf5d2643d4d9fb691e20fe0af4d5b Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Wed, 11 Jan 2023 20:04:05 +0000 Subject: [PATCH] Better detection of features necessary for USDT probes --- dropshot/build.rs | 16 +++++++++------- dropshot/src/lib.rs | 21 +++++++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/dropshot/build.rs b/dropshot/build.rs index db67d2159..4c95a1548 100644 --- a/dropshot/build.rs +++ b/dropshot/build.rs @@ -1,4 +1,4 @@ -// Copyright 2022 Oxide Computer Company +// Copyright 2023 Oxide Computer Company // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,12 +16,14 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); - if version_check::is_min_version("1.59").unwrap_or(false) { - println!("cargo:rustc-cfg=usdt_stable_asm"); + if !version_check::is_min_version("1.59").unwrap_or(false) { + println!("cargo:rustc-cfg=usdt_need_asm"); } - // Once asm_sym is stablilized, add an additional check so that those - // building on macos can use the stable toolchain with any hassle. - // - // A matching rust-cfg option named `usdt_stable_asm_sym` seems appropriate. + #[cfg(target_os = "macos")] + if version_check::supports_feature("asm_sym").unwrap_or(false) + && !version_check::is_min_version("1.67").unwrap_or(false) + { + println!("cargo:rustc-cfg=usdt_need_asm_sym"); + } } diff --git a/dropshot/src/lib.rs b/dropshot/src/lib.rs index 2a3803c16..984f39383 100644 --- a/dropshot/src/lib.rs +++ b/dropshot/src/lib.rs @@ -505,11 +505,12 @@ //! See the [`RequestInfo`] and [`ResponseInfo`] types for a complete listing //! of what's available. //! -//! These probes are implemented via the [`usdt`] crate. They require a nightly -//! toolchain if built on MacOS (which requires the unstable `asm_sym` feature). -//! Otherwise a stable compiler >= v1.59 is required in order to present the -//! necessary features. Given these constraints, usdt functionality is behind -//! the feature flag `"usdt-probes"`. +//! These probes are implemented via the [`usdt`] crate. They may require a +//! nightly toolchain if built on macOS prior to Rust version 1.66. Otherwise a +//! stable compiler >= v1.59 is required in order to present the necessary +//! features. Given these constraints, USDT functionality is behind the feature +//! flag `"usdt-probes"`, which may become a default feature of this crate in +//! future releases. //! //! > *Important:* The probes are internally registered with the DTrace kernel //! module, making them visible via `dtrace(1M)`. This is done when an `HttpServer` @@ -540,15 +541,11 @@ // Clippy's style advice is definitely valuable, but not worth the trouble for // automated enforcement. #![allow(clippy::style)] -// The `usdt` crate requires nightly, enabled if our consumer is enabling +// The `usdt` crate may requires nightly, enabled if our consumer is enabling // DTrace probes. -#![cfg_attr(all(feature = "usdt-probes", not(usdt_stable_asm)), feature(asm))] +#![cfg_attr(all(feature = "usdt-probes", usdt_need_asm), feature(asm))] #![cfg_attr( - all( - feature = "usdt-probes", - target_os = "macos", - not(usdt_stable_asm_sym) - ), + all(feature = "usdt-probes", target_os = "macos", usdt_need_asm_sym), feature(asm_sym) )]