Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable compilation of Atomic64 code in metric.rs if there's no Atomic64 #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//! of these components can choose what metrics they’re interested in and also
//! can add their own custom metrics without the need to maintain forks.

#![cfg(target_has_atomic = "64")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would result in a compilation error when this condition is not true.

To implement this, it should be on https://github.com/rust-vmm/vmm-sys-util/blob/main/src/lib.rs#L21 like:

#[cfg(target_has_atomic = "64")]
pub mod metric;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it doesn't result in compilation error: see https://buildd.debian.org/status/package.php?p=rust-vmm-sys-util&suite=sid - it compiled fine on all platforms where previously this caused an error. I guess it will result in compilation error of crates which use this one, as there will be no implementation for the declared functionality.

But I must admit: I know nothing about rust. It's the 2nd day since I looked at what rust actually is, what I suggest is just something I've seen being used elsewhere. I've no idea if this is a correct solution or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing #![cfg(target_has_atomic = "64")] (notice the !) is equivalent to:

#[cfg(target_has_atomic = "64")] pub mod metric;

We can still have it as @JonathanWoollett-Light suggested even if they're equivalent because it is making it a bit more obvious that the whole module is excluded from compilation on targets that don't support atomic64.


use std::sync::atomic::{AtomicU64, Ordering};

/// Abstraction over the common metric operations.
Expand Down