diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-15 12:44:22 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-15 07:14:22 +0000 |
commit | 51649272bd388f14685a47cfe805bd9cdb602240 (patch) | |
tree | 86be1cd73d9c7a0d095d5ca82fc4fa756fe45b65 /cli | |
parent | 6f9c0a9b7a4afd0d73ab312347427e445c67f6c9 (diff) |
perf: do not depend on iana-time-zone (#18088)
Chrono's `clock` feature pulls in `iana-time-zone` which links to macOS
core_foundation. This PR itself is not enough to get rid of
CoreFoundation. Removal depends on getting rid of security framework,
see #18071
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 2 | ||||
-rw-r--r-- | cli/bench/main.rs | 5 | ||||
-rw-r--r-- | cli/tools/upgrade.rs | 5 | ||||
-rw-r--r-- | cli/util/mod.rs | 1 | ||||
-rw-r--r-- | cli/util/time.rs | 22 |
5 files changed, 30 insertions, 5 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e99596bcf..04642f828 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -58,7 +58,7 @@ atty.workspace = true base32 = "=0.4.0" base64.workspace = true cache_control.workspace = true -chrono = { version = "=0.4.22", default-features = false, features = ["clock"] } +chrono = { version = "=0.4.22", default-features = false, features = ["std"] } clap = "=3.1.12" clap_complete = "=3.1.2" clap_complete_fig = "=3.1.5" diff --git a/cli/bench/main.rs b/cli/bench/main.rs index 3bf73e78d..a16c65ed4 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -13,6 +13,8 @@ use std::process::Command; use std::process::Stdio; use std::time::SystemTime; +include!("../util/time.rs"); + mod http; mod lsp; @@ -436,8 +438,7 @@ async fn main() -> Result<()> { env::set_current_dir(test_util::root_path())?; let mut new_data = BenchResult { - created_at: chrono::Utc::now() - .to_rfc3339_opts(chrono::SecondsFormat::Secs, true), + created_at: utc_now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true), sha1: test_util::run_collect( &["git", "rev-parse", "HEAD"], None, diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index b56be5c57..039e00b00 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -9,6 +9,7 @@ use crate::http_util::HttpClient; use crate::proc_state::ProcState; use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; +use crate::util::time; use crate::version; use deno_core::anyhow::bail; @@ -60,7 +61,7 @@ impl RealUpdateCheckerEnvironment { http_client, cache_file_path, // cache the current time - current_time: chrono::Utc::now(), + current_time: time::utc_now(), } } } @@ -702,7 +703,7 @@ mod test { file_text: Default::default(), current_version: Default::default(), latest_version: Arc::new(Mutex::new(Ok("".to_string()))), - time: Arc::new(Mutex::new(chrono::Utc::now())), + time: Arc::new(Mutex::new(crate::util::time::utc_now())), } } diff --git a/cli/util/mod.rs b/cli/util/mod.rs index 515bc64e9..c3133cc10 100644 --- a/cli/util/mod.rs +++ b/cli/util/mod.rs @@ -12,6 +12,7 @@ pub mod logger; pub mod path; pub mod progress_bar; pub mod text_encoding; +pub mod time; pub mod unix; pub mod v8; pub mod windows; diff --git a/cli/util/time.rs b/cli/util/time.rs new file mode 100644 index 000000000..9c5b48b57 --- /dev/null +++ b/cli/util/time.rs @@ -0,0 +1,22 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +/// Identical to chrono::Utc::now() but without the system "clock" +/// feature flag. +/// +/// The "clock" feature flag pulls in the "iana-time-zone" crate +/// which links to macOS's "CoreFoundation" framework which increases +/// startup time for the CLI. +/// +/// You can simply include this file in your project using +/// `include!("path/to/cli/util/time.rs"))` and use it +/// as a drop-in replacement for chrono::Utc::now(). +pub fn utc_now() -> chrono::DateTime<chrono::Utc> { + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .expect("system time before Unix epoch"); + let naive = chrono::NaiveDateTime::from_timestamp( + now.as_secs() as i64, + now.subsec_nanos(), + ); + chrono::DateTime::from_utc(naive, chrono::Utc) +} |