Skip to content

Commit

Permalink
Add no_std feature and make it default for win_etw_provider (#35)
Browse files Browse the repository at this point in the history
* Basic no_std feature.

Not deeply tested but appears to compile and work when added to another project with a global allocator.

* Make no_std the default.

* Bump MSRV to 1.77 for core::net support.
  • Loading branch information
NateD-MSFT authored Jul 2, 2024
1 parent 06cfdaf commit bfd5192
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
strategy:
matrix:
rust: [1.68.0, stable]
rust: [1.77.0, stable]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"

[dependencies]
win_etw_macros = { path = "../../win_etw_macros" }
win_etw_provider = { path = "../../win_etw_provider" }
win_etw_provider = { path = "../../win_etw_provider", features = ["std"] }
widestring = "^1.0"
winapi = { version = "^0.3.8", features = ["ntstatus"] }

Expand Down
6 changes: 4 additions & 2 deletions win_etw_provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ description = "Enables apps to report events to Event Tracing for Windows (ETW).
license = "Apache-2.0 OR MIT"
homepage = "https://github.com/microsoft/rust_win_etw"
readme = "../README.md"
rust-version = "1.77"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
widestring = "^1.0"
widestring = {version = "^1.0", default-features = false, features = ["alloc"]}
zerocopy = { version = "0.7.32", features = ["derive"] }
win_etw_metadata = { version = "^0.1.2", path = "../win_etw_metadata" }
uuid = {version = "1", optional = true}
Expand All @@ -26,6 +27,7 @@ uuid = "1"

[features]
std = []
default = ["std"]
default = ["no_std"]
no_std = []
# dev is used only for development
dev = []
2 changes: 2 additions & 0 deletions win_etw_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![cfg_attr(not(windows), allow(unused))]

extern crate alloc;

mod guid;
mod provider;

Expand Down
1 change: 1 addition & 0 deletions win_etw_provider/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::guid::GUID;
use crate::Level;
use crate::{Error, EventDataDescriptor};
use alloc::boxed::Box;
use core::convert::TryFrom;
use core::pin::Pin;
use core::ptr::null;
Expand Down
10 changes: 4 additions & 6 deletions win_etw_provider/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ pub struct SocketAddrV4 {
pub zero: [u8; 8],
}

#[cfg(feature = "std")]
impl From<&std::net::SocketAddrV4> for SocketAddrV4 {
fn from(value: &std::net::SocketAddrV4) -> Self {
impl From<&core::net::SocketAddrV4> for SocketAddrV4 {
fn from(value: &core::net::SocketAddrV4) -> Self {
let port = value.port();
Self {
family: AF_INET,
Expand Down Expand Up @@ -65,9 +64,8 @@ pub struct SocketAddrV6 {
pub scope_id: [u8; 4],
}

#[cfg(feature = "std")]
impl From<&std::net::SocketAddrV6> for SocketAddrV6 {
fn from(value: &std::net::SocketAddrV6) -> Self {
impl From<&core::net::SocketAddrV6> for SocketAddrV6 {
fn from(value: &core::net::SocketAddrV6) -> Self {
Self {
family: AF_INET6,
port: value.port().to_be_bytes(),
Expand Down

0 comments on commit bfd5192

Please sign in to comment.