Skip to content

Commit

Permalink
fixup! fix(lib): make the linter happier
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsastrix committed Jul 2, 2024
1 parent 2a18624 commit ddec074
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
57 changes: 25 additions & 32 deletions libcoap-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
};
use std::cell::RefCell;
use std::ffi::OsString;
use std::fmt::Debug;
use std::fmt::{Debug, Display};

use bindgen::{Builder, EnumVariation};
use bindgen::callbacks::{IntKind, ParseCallbacks};
Expand All @@ -34,6 +34,8 @@ impl ParseCallbacks for CoapConfigMacroParser {
}

fn str_macro(&self, name: &str, value: &[u8]) {
// Will allow this here, as we might want to add additional cfg flags later on.
#[allow(clippy::single_match)]
match name {
"PACKAGE_VERSION" => {
let version_str = String::from_utf8_lossy(value);
Expand All @@ -57,18 +59,34 @@ pub enum DtlsBackend {
MbedTls,
TinyDtls,
}
impl ToString for DtlsBackend {
fn to_string(&self) -> String {
match self {
impl Display for DtlsBackend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
DtlsBackend::GnuTls => "gnutls",
DtlsBackend::OpenSsl => "openssl",
DtlsBackend::MbedTls => "mbedtls",
DtlsBackend::TinyDtls => "tinydtls",
}
.to_string()
.to_string();
write!(f, "{}", str)
}
}

fn get_target_mcu() -> &'static str {
let cfg_flags = embuild::espidf::sysenv::cfg_args()
.ok_or("missing cfg flags from IDF")
.unwrap();
let mcus = [
"esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c2", "esp32h2", "esp32c5", "esp32c6", "esp32p4",
];
for mcu in mcus {
if cfg_flags.get(mcu).is_some() {
return mcu;
}
}
panic!("unknown ESP target MCU, please add target to libcoap-sys build.rs file!")
}

fn get_builder_espidf() -> bindgen::Builder {
embuild::espidf::sysenv::output();
let esp_idf_path = embuild::espidf::sysenv::idf_path().ok_or("missing IDF path").unwrap();
Expand All @@ -80,9 +98,6 @@ fn get_builder_espidf() -> bindgen::Builder {
.ok_or("missing IDF env path")
.unwrap();
let esp_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH is not set");
let cfg_flags = embuild::espidf::sysenv::cfg_args()
.ok_or("missing cfg flags from IDF")
.unwrap();

// Determine compiler path
unsafe { env::set_var("PATH", embuild_env) };

Check warning on line 103 in libcoap-sys/build.rs

View workflow job for this annotation

GitHub Actions / clippy (libcoap-sys)

[clippy (libcoap-sys)] libcoap-sys/build.rs#L103

warning: unnecessary `unsafe` block --> libcoap-sys/build.rs:103:5 | 103 | unsafe { env::set_var("PATH", embuild_env) }; | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default
Raw output
libcoap-sys/build.rs:103:5:w:warning: unnecessary `unsafe` block
   --> libcoap-sys/build.rs:103:5
    |
103 |     unsafe { env::set_var("PATH", embuild_env) };
    |     ^^^^^^ unnecessary `unsafe` block
    |
    = note: `#[warn(unused_unsafe)]` on by default


__END__

Check warning on line 103 in libcoap-sys/build.rs

View workflow job for this annotation

GitHub Actions / clippy (libcoap-rs)

[clippy (libcoap-rs)] libcoap-sys/build.rs#L103

warning: unnecessary `unsafe` block --> libcoap-sys/build.rs:103:5 | 103 | unsafe { env::set_var("PATH", embuild_env) }; | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default
Raw output
libcoap-sys/build.rs:103:5:w:warning: unnecessary `unsafe` block
   --> libcoap-sys/build.rs:103:5
    |
103 |     unsafe { env::set_var("PATH", embuild_env) };
    |     ^^^^^^ unnecessary `unsafe` block
    |
    = note: `#[warn(unused_unsafe)]` on by default


__END__
Expand Down Expand Up @@ -136,27 +151,7 @@ fn get_builder_espidf() -> bindgen::Builder {
} else {
esp_arch.as_str()
};
let target_mcu = if cfg_flags.get("esp32").is_some() {
"esp32"
} else if cfg_flags.get("esp32s2").is_some() {
"esp32s2"
} else if cfg_flags.get("esp32s3").is_some() {
"esp32s3"
} else if cfg_flags.get("esp32c3").is_some() {
"esp32c3"
} else if cfg_flags.get("esp32c2").is_some() {
"esp32c2"
} else if cfg_flags.get("esp32h2").is_some() {
"esp32h2"
} else if cfg_flags.get("esp32c5").is_some() {
"esp32c5"
} else if cfg_flags.get("esp32c6").is_some() {
"esp32c6"
} else if cfg_flags.get("esp32p4").is_some() {
"esp32p4"
} else {
panic!("unknown ESP target MCU, please add target to libcoap-sys build.rs file!")
};
let target_mcu = get_target_mcu();

bindgen_builder
.clang_args(&esp_clang_args)
Expand Down Expand Up @@ -233,7 +228,7 @@ fn build_vendored_library(out_dir: &OsString, dtls_backend: Option<&DtlsBackend>
.status()
.expect("unable to execute autogen.sh");
let mut build_config = autotools::Config::new(&libcoap_src_dir);
build_config.out_dir(&out_dir);
build_config.out_dir(out_dir);
if let Some(dtls_backend) = dtls_backend {
build_config
.enable("dtls", None)
Expand Down Expand Up @@ -357,8 +352,6 @@ fn build_vendored_library(out_dir: &OsString, dtls_backend: Option<&DtlsBackend>
build_config.disable("dtls", None);
}
build_config
// Set Makeflags
//.make_args(make_flags)
// Disable shared library compilation because the vendored library will always be
// statically linked
.disable("shared", None)
Expand Down
2 changes: 2 additions & 0 deletions libcoap/src/session/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use libcoap_sys::{
use crate::{context::CoapContext, error::SessionCreationError, types::CoapAddress};
#[cfg(feature = "dtls")]
use crate::crypto::{CoapClientCryptoProvider, CoapCryptoProviderResponse, CoapCryptoPskIdentity, CoapCryptoPskInfo};
#[cfg(not(feature = "dtls_mbedtls"))]
use crate::crypto::dtls_ih_callback;
use crate::event::event_handler_callback;
use crate::mem::{CoapFfiRcCell, DropInnerExclusively};

Expand Down

0 comments on commit ddec074

Please sign in to comment.