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

Revert MSRV bump for patch release #565

Merged
merged 1 commit into from May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Expand Up @@ -127,11 +127,8 @@ jobs:
- uses: actions/checkout@master
- name: Install Rust
run: |
rustup update 1.60.0 --no-self-update
rustup default 1.60.0
- run: cargo build --verbose
- run: cargo build --verbose --features serde
- run: cargo build --verbose --features std
rustup update 1.31.0 --no-self-update
rustup default 1.31.0
- run: cargo test --verbose --manifest-path tests/Cargo.toml

embedded:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -13,7 +13,7 @@ A lightweight logging facade for Rust
categories = ["development-tools::debugging"]
keywords = ["logging"]
exclude = ["rfcs/**/*"]
rust-version = "1.60.0"
build = "build.rs"

[package.metadata.docs.rs]
features = ["std", "serde", "kv_unstable_std", "kv_unstable_sval", "kv_unstable_serde"]
Expand Down Expand Up @@ -56,12 +56,12 @@ kv_unstable_serde = ["kv_unstable_std", "value-bag/serde", "serde"]
serde = { version = "1.0", optional = true, default-features = false }
sval = { version = "2.1", optional = true, default-features = false }
sval_ref = { version = "2.1", optional = true, default-features = false }
value-bag = { version = "1.1", optional = true, default-features = false }
value-bag = { version = "1.4", optional = true, default-features = false }

[dev-dependencies]
rustversion = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_test = "1.0"
sval = { version = "2.1" }
sval_derive = { version = "2.1" }
value-bag = { version = "1.1", features = ["test"] }
value-bag = { version = "1.4", features = ["test"] }
46 changes: 46 additions & 0 deletions build.rs
@@ -0,0 +1,46 @@
//! This build script detects target platforms that lack proper support for
//! atomics and sets `cfg` flags accordingly.

use std::env;
use std::str;

fn main() {
let target = match rustc_target() {
Some(target) => target,
None => return,
};

if target_has_atomic_cas(&target) {
println!("cargo:rustc-cfg=atomic_cas");
}

if target_has_atomics(&target) {
println!("cargo:rustc-cfg=has_atomics");
}

println!("cargo:rerun-if-changed=build.rs");
}

fn target_has_atomic_cas(target: &str) -> bool {
match target {
"thumbv6m-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => false,
_ => true,
}
}

fn target_has_atomics(target: &str) -> bool {
match target {
"thumbv4t-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => false,
_ => true,
}
}

fn rustc_target() -> Option<String> {
env::var("TARGET").ok()
}
21 changes: 10 additions & 11 deletions src/lib.rs
Expand Up @@ -344,20 +344,20 @@ mod serde;
#[cfg(feature = "kv_unstable")]
pub mod kv;

#[cfg(target_has_atomic = "ptr")]
#[cfg(has_atomics)]
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(not(target_has_atomic = "ptr"))]
#[cfg(not(has_atomics))]
use std::cell::Cell;
#[cfg(not(target_has_atomic = "ptr"))]
#[cfg(not(has_atomics))]
use std::sync::atomic::Ordering;

#[cfg(not(target_has_atomic = "ptr"))]
#[cfg(not(has_atomics))]
struct AtomicUsize {
v: Cell<usize>,
}

#[cfg(not(target_has_atomic = "ptr"))]
#[cfg(not(has_atomics))]
impl AtomicUsize {
const fn new(v: usize) -> AtomicUsize {
AtomicUsize { v: Cell::new(v) }
Expand All @@ -371,7 +371,7 @@ impl AtomicUsize {
self.v.set(val)
}

#[cfg(target_has_atomic = "ptr")]
#[cfg(atomic_cas)]
fn compare_exchange(
&self,
current: usize,
Expand All @@ -389,7 +389,7 @@ impl AtomicUsize {

// Any platform without atomics is unlikely to have multiple cores, so
// writing via Cell will not be a race condition.
#[cfg(not(target_has_atomic = "ptr"))]
#[cfg(not(has_atomics))]
unsafe impl Sync for AtomicUsize {}

// The LOGGER static holds a pointer to the global logger. It is protected by
Expand Down Expand Up @@ -1217,7 +1217,6 @@ where
///
/// Note that `Trace` is the maximum level, because it provides the maximum amount of detail in the emitted logs.
#[inline]
#[cfg(target_has_atomic = "ptr")]
pub fn set_max_level(level: LevelFilter) {
MAX_LOG_LEVEL_FILTER.store(level as usize, Ordering::Relaxed);
}
Expand Down Expand Up @@ -1286,7 +1285,7 @@ pub fn max_level() -> LevelFilter {
/// An error is returned if a logger has already been set.
///
/// [`set_logger`]: fn.set_logger.html
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
#[cfg(all(feature = "std", atomic_cas))]
pub fn set_boxed_logger(logger: Box<dyn Log>) -> Result<(), SetLoggerError> {
set_logger_inner(|| Box::leak(logger))
}
Expand Down Expand Up @@ -1344,12 +1343,12 @@ pub fn set_boxed_logger(logger: Box<dyn Log>) -> Result<(), SetLoggerError> {
/// ```
///
/// [`set_logger_racy`]: fn.set_logger_racy.html
#[cfg(target_has_atomic = "ptr")]
#[cfg(atomic_cas)]
pub fn set_logger(logger: &'static dyn Log) -> Result<(), SetLoggerError> {
set_logger_inner(|| logger)
}

#[cfg(target_has_atomic = "ptr")]
#[cfg(atomic_cas)]
fn set_logger_inner<F>(make_logger: F) -> Result<(), SetLoggerError>
where
F: FnOnce() -> &'static dyn Log,
Expand Down