mirror of
https://github.com/LemmyNet/lemmy.git
synced 2026-05-06 08:30:33 -05:00
Update to Rust 1.95, use cfg_select! (#6455)
* Update to Rust 1.95, use cfg_select! * clippy
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ variables:
|
||||
# features. In particular the ARM builder image needs to be updated manually in the repo below:
|
||||
# https://github.com/raskyld/lemmy-cross-toolchains
|
||||
# Also be sure to change the version in `rust-toolchain.toml`
|
||||
- &rust_image "rust:1.94"
|
||||
- &rust_image "rust:1.95"
|
||||
- &rust_nightly_image "rustlang/rust:nightly"
|
||||
- &install_pnpm "npm install -g corepack@latest && corepack enable pnpm"
|
||||
- &install_binstall "wget -q -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
|
||||
|
||||
Generated
-1
@@ -4287,7 +4287,6 @@ dependencies = [
|
||||
"actix-extensible-rate-limit",
|
||||
"actix-web",
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
"chrono",
|
||||
"clearurls",
|
||||
"dashmap",
|
||||
|
||||
@@ -227,7 +227,6 @@ extism = { version = "1.20.0", default-features = false, features = [
|
||||
extism-convert = "1.20.0"
|
||||
unified-diff = "0.2.1"
|
||||
diesel-uplete = { version = "0.2.0" }
|
||||
cfg-if = "1"
|
||||
|
||||
# Speedup RSA key generation
|
||||
# https://github.com/RustCrypto/RSA/blob/master/README.md#example
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Collection for ApubCommunityOutbox {
|
||||
|
||||
// Outbox must be sorted reverse chronological (newest items first). This is already done
|
||||
// via SQL, but featured posts are always at the top so we need to manually sort it here.
|
||||
post_views.sort_unstable_by(|p1, p2| p2.post.published_at.cmp(&p1.post.published_at));
|
||||
post_views.sort_unstable_by_key(|p2| std::cmp::Reverse(p2.post.published_at));
|
||||
|
||||
let mut ordered_items = vec![];
|
||||
for post_view in post_views {
|
||||
|
||||
@@ -119,19 +119,14 @@ pub async fn check_apub_id_valid_with_strictness(
|
||||
if is_strict && !local_site_data.allowed_instances.is_empty() {
|
||||
// need to allow this explicitly because apub receive might contain objects from our local
|
||||
// instance.
|
||||
let mut allowed_and_local = local_site_data
|
||||
let is_allowed_or_local = local_site_data
|
||||
.allowed_instances
|
||||
.iter()
|
||||
.map(|i| i.domain.clone())
|
||||
.collect::<Vec<String>>();
|
||||
let local_instance = context.settings().get_hostname_without_port()?;
|
||||
allowed_and_local.push(local_instance);
|
||||
.chain([local_instance])
|
||||
.any(|x| x == domain);
|
||||
|
||||
let domain = apub_id
|
||||
.domain()
|
||||
.ok_or(UntranslatedError::UrlWithoutDomain)?
|
||||
.to_string();
|
||||
if !allowed_and_local.contains(&domain) {
|
||||
if !is_allowed_or_local {
|
||||
return Err(UntranslatedError::FederationDisabledByStrictAllowList.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ mod tests {
|
||||
|
||||
// Languages are returned in order of popularity, so to make this test work we need to
|
||||
// manually sort them by id.
|
||||
all.sort_by(|a, b| a.id.0.cmp(&b.id.0));
|
||||
all.sort_by_key(|a| a.id.0);
|
||||
|
||||
assert_eq!(184, all.len());
|
||||
assert_eq!("ak", all[5].code);
|
||||
|
||||
@@ -73,7 +73,6 @@ markdown-it = { version = "0.6.1", optional = true }
|
||||
ts-rs = { workspace = true, optional = true }
|
||||
enum-map = { version = "2.7", optional = true }
|
||||
chrono = { workspace = true }
|
||||
cfg-if = { workspace = true }
|
||||
clearurls = { version = "0.0.4", features = ["linkify"] }
|
||||
markdown-it-block-spoiler = "1.0.3"
|
||||
markdown-it-sub = "1.0.2"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use cfg_if::cfg_if;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fmt::Debug, panic::Location};
|
||||
use strum::{Display, EnumIter};
|
||||
@@ -160,8 +159,8 @@ pub enum UntranslatedError {
|
||||
CommunityHasNoFollowers(String),
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "full")] {
|
||||
cfg_select! {
|
||||
feature = "full" => {
|
||||
|
||||
use std::fmt;
|
||||
use serde_with::serde_as;
|
||||
@@ -348,4 +347,5 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
+44
-45
@@ -1,15 +1,15 @@
|
||||
use cfg_if::cfg_if;
|
||||
use chrono::Utc;
|
||||
use std::{cmp::min, sync::LazyLock};
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "full")] {
|
||||
cfg_select! {
|
||||
feature = "full" => {
|
||||
pub mod cache_header;
|
||||
pub mod rate_limit;
|
||||
pub mod response;
|
||||
pub mod settings;
|
||||
pub mod utils;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
pub mod error;
|
||||
@@ -73,54 +73,53 @@ macro_rules! location_info {
|
||||
};
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "full")] {
|
||||
use moka::future::Cache;use std::fmt::Debug;use std::hash::Hash;
|
||||
use serde_json::Value;
|
||||
cfg_select! {
|
||||
feature = "full" => {
|
||||
use moka::future::Cache;use std::fmt::Debug;use std::hash::Hash;
|
||||
use serde_json::Value;
|
||||
|
||||
/// Only include a basic context to save space and bandwidth. The main context is hosted statically
|
||||
/// on join-lemmy.org. Include activitystreams explicitly for better compat, but this could
|
||||
/// theoretically also be moved.
|
||||
pub static FEDERATION_CONTEXT: LazyLock<Value> = LazyLock::new(|| {
|
||||
Value::Array(vec![
|
||||
Value::String("https://join-lemmy.org/context.json".to_string()),
|
||||
Value::String("https://www.w3.org/ns/activitystreams".to_string()),
|
||||
])
|
||||
});
|
||||
/// Only include a basic context to save space and bandwidth. The main context is hosted statically
|
||||
/// on join-lemmy.org. Include activitystreams explicitly for better compat, but this could
|
||||
/// theoretically also be moved.
|
||||
pub static FEDERATION_CONTEXT: LazyLock<Value> = LazyLock::new(|| {
|
||||
Value::Array(vec![
|
||||
Value::String("https://join-lemmy.org/context.json".to_string()),
|
||||
Value::String("https://www.w3.org/ns/activitystreams".to_string()),
|
||||
])
|
||||
});
|
||||
|
||||
/// tokio::spawn, but accepts a future that may fail and also
|
||||
/// * logs errors
|
||||
/// * attaches the spawned task to the tracing span of the caller for better logging
|
||||
pub fn spawn_try_task(
|
||||
task: impl futures::Future<Output = Result<(), error::LemmyError>> + Send + 'static,
|
||||
) {
|
||||
use tracing::Instrument;
|
||||
tokio::spawn(
|
||||
async {
|
||||
if let Err(e) = task.await {
|
||||
tracing::warn!("error in spawn: {e}");
|
||||
}
|
||||
/// tokio::spawn, but accepts a future that may fail and also
|
||||
/// * logs errors
|
||||
/// * attaches the spawned task to the tracing span of the caller for better logging
|
||||
pub fn spawn_try_task(
|
||||
task: impl futures::Future<Output = Result<(), error::LemmyError>> + Send + 'static,
|
||||
) {
|
||||
use tracing::Instrument;
|
||||
tokio::spawn(
|
||||
async {
|
||||
if let Err(e) = task.await {
|
||||
tracing::warn!("error in spawn: {e}");
|
||||
}
|
||||
}
|
||||
.in_current_span(), /* this makes sure the inner tracing gets the same context as where
|
||||
* spawn was called */
|
||||
);
|
||||
}
|
||||
.in_current_span(), /* this makes sure the inner tracing gets the same context as where
|
||||
* spawn was called */
|
||||
);
|
||||
}
|
||||
|
||||
pub fn build_cache<K, V>() -> Cache<K, V>
|
||||
where
|
||||
K: Debug + Eq + Hash + Send + Sync + 'static,
|
||||
V: Debug + Clone + Send + Sync + 'static,
|
||||
{
|
||||
Cache::<K, V>::builder()
|
||||
.max_capacity(1)
|
||||
.time_to_live(CACHE_DURATION_API)
|
||||
.build()
|
||||
}
|
||||
|
||||
#[cfg(feature = "full")]
|
||||
pub type CacheLock<T> = std::sync::LazyLock<Cache<(), T>>;
|
||||
pub fn build_cache<K, V>() -> Cache<K, V>
|
||||
where
|
||||
K: Debug + Eq + Hash + Send + Sync + 'static,
|
||||
V: Debug + Clone + Send + Sync + 'static,
|
||||
{
|
||||
Cache::<K, V>::builder()
|
||||
.max_capacity(1)
|
||||
.time_to_live(CACHE_DURATION_API)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub type CacheLock<T> = std::sync::LazyLock<Cache<(), T>>;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
/// Calculate how long to sleep until next federation send based on how many
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
fn main() {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "full")] {
|
||||
println!("{}", config_to_string())
|
||||
} else {
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "full")]
|
||||
println!("{}", config_to_string())
|
||||
}
|
||||
|
||||
#[cfg(feature = "full")]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
# syntax=docker/dockerfile:1.20
|
||||
ARG RUST_VERSION=1.94
|
||||
ARG RUST_VERSION=1.95
|
||||
ARG CARGO_BUILD_FEATURES=default
|
||||
ARG RUST_RELEASE_MODE=debug
|
||||
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "1.94"
|
||||
channel = "1.95"
|
||||
|
||||
Reference in New Issue
Block a user