Skip to content

Commit

Permalink
Special configs for Clippy (#542)
Browse files Browse the repository at this point in the history
* Special configs for Clippy

* Add comment on clippy/nightly
  • Loading branch information
justsmth authored Sep 30, 2024
1 parent 1a44d74 commit 8c39b68
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
48 changes: 29 additions & 19 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

// Clippy can only be run on nightly toolchain
#![cfg_attr(clippy, feature(custom_inner_attributes))]
#![cfg_attr(clippy, clippy::msrv = "1.77")]

use core::fmt;
use core::fmt::Debug;
use std::env;
Expand Down Expand Up @@ -68,21 +72,28 @@ fn option_env<N: AsRef<str>>(name: N) -> Option<String> {
fn env_var_to_bool(name: &str) -> Option<bool> {
let build_type_result = option_env(name);
if let Some(env_var_value) = build_type_result {
eprintln!("{name}={env_var_value}");
// If the environment variable is set, we ignore every other factor.
eprintln!("Evaluating: {name}='{env_var_value}'");

let env_var_value = env_var_value.to_lowercase();
if env_var_value.starts_with('0')
|| env_var_value.starts_with('n')
|| env_var_value.starts_with("off")
|| env_var_value.starts_with('f')
{
Some(false)
} else {
// Otherwise, if the variable is set, assume true
Some(true)
eprintln!("Parsed: {name}=false");
return Some(false);
}
} else {
None
if env_var_value.starts_with(|c: char| c.is_ascii_digit())
|| env_var_value.starts_with('y')
|| env_var_value.starts_with("on")
|| env_var_value.starts_with('t')
{
eprintln!("Parsed: {name}=true");
return Some(true);
}
eprintln!("Parsed: {name}=unknown");
}
None
}

impl Default for OutputLibType {
Expand Down Expand Up @@ -349,17 +360,16 @@ fn has_pregenerated() -> bool {

fn prepare_cargo_cfg() {
// This is supported in Rust >= 1.77.0
// Also remove `#![allow(unexpected_cfgs)]` from src/lib.rs
/*
println!("cargo::rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_musl)");
println!("cargo::rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(use_bindgen_generated)");
println!("cargo::rustc-check-cfg=cfg(x86_64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
*/
if cfg!(clippy) {
println!("cargo:rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo:rustc-check-cfg=cfg(aarch64_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(aarch64_unknown_linux_musl)");
println!("cargo:rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(use_bindgen_generated)");
println!("cargo:rustc-check-cfg=cfg(x86_64_apple_darwin)");
println!("cargo:rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
}
}

fn main() {
Expand Down
3 changes: 2 additions & 1 deletion aws-lc-fips-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#![allow(unexpected_cfgs)]
#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
#![cfg_attr(not(clippy), allow(unknown_lints))]

use paste::paste;
use std::os::raw::{c_char, c_long, c_void};
Expand Down
3 changes: 2 additions & 1 deletion aws-lc-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: ISC
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
#![cfg_attr(not(clippy), allow(unknown_lints))]
#![allow(clippy::doc_markdown)]
//! A [*ring*](https://github.com/briansmith/ring)-compatible crypto library using the cryptographic
//! operations provided by [*AWS-LC*](https://github.com/aws/aws-lc). It uses either the
Expand Down
36 changes: 19 additions & 17 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

// Clippy can only be run on nightly toolchain
#![cfg_attr(clippy, feature(custom_inner_attributes))]
#![cfg_attr(clippy, clippy::msrv = "1.77")]

use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{fmt, fmt::Debug};
use std::{env, fmt, fmt::Debug};

use cc_builder::CcBuilder;
use cmake_builder::CmakeBuilder;
Expand Down Expand Up @@ -461,22 +465,20 @@ fn test_nasm_command() -> bool {
}

fn prepare_cargo_cfg() {
// This is supported in Rust >= 1.77.0
// Also remove `#![allow(unexpected_cfgs)]` from src/lib.rs
/*
println!("cargo::rustc-check-cfg=cfg(use_bindgen_generated)");
println!("cargo::rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(aarch64_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_musl)");
println!("cargo::rustc-check-cfg=cfg(i686_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(x86_64_pc-windows-gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
*/
if cfg!(clippy) {
println!("cargo:rustc-check-cfg=cfg(use_bindgen_generated)");
println!("cargo:rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo:rustc-check-cfg=cfg(aarch64_pc_windows_msvc)");
println!("cargo:rustc-check-cfg=cfg(aarch64_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(aarch64_unknown_linux_musl)");
println!("cargo:rustc-check-cfg=cfg(i686_pc_windows_msvc)");
println!("cargo:rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(x86_64_apple_darwin)");
println!("cargo:rustc-check-cfg=cfg(x86_64_pc_windows_gnu)");
println!("cargo:rustc-check-cfg=cfg(x86_64_pc_windows_msvc)");
println!("cargo:rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo:rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
}
}

fn is_crt_static() -> bool {
Expand Down
3 changes: 2 additions & 1 deletion aws-lc-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#![allow(unexpected_cfgs)]
#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
#![cfg_attr(not(clippy), allow(unknown_lints))]

use paste::paste;
use std::os::raw::{c_char, c_long, c_void};
Expand Down

0 comments on commit 8c39b68

Please sign in to comment.