diff options
author | Andrew Walbran <qwandor@google.com> | 2024-02-22 12:00:39 +0000 |
---|---|---|
committer | Andrew Walbran <qwandor@google.com> | 2024-03-21 18:01:36 +0000 |
commit | 52de7769ce165f6a14bf7ade09ac322ddb092a25 (patch) | |
tree | fc37be96d71bf8ac3f6dd0313047c4630b73ff98 | |
parent | c0dc6153e65acbd4b59926eaccf67cefa1bc6c5a (diff) | |
download | chrono-52de7769ce165f6a14bf7ade09ac322ddb092a25.tar.gz |
Avoid android-tzdata and iana-time-zone dependencies.
This is achieved by disabling the clock feature on device, and a local
patch to get the timezone on host.
Bug: 326256145
Test: atest libnetsim_common_inline_tests
Change-Id: Ie6ddadc653156708fc73f2fe78dd7e1782aac828
-rw-r--r-- | Android.bp | 31 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | cargo_embargo.json | 25 | ||||
-rw-r--r-- | patches/no-tzdata.patch | 51 | ||||
-rw-r--r-- | src/offset/local/unix.rs | 8 |
5 files changed, 97 insertions, 20 deletions
@@ -1,5 +1,6 @@ // This file is generated by cargo_embargo. -// Do not modify this file as changes will be overridden on upgrade. +// Do not modify this file as most changes will be overridden on upgrade. +// Content before the first "rust_*" or "genrule" module is preserved. package { default_applicable_licenses: ["external_rust_crates_chrono_license"], @@ -41,17 +42,11 @@ rust_library { edition: "2021", features: [ "alloc", - "android-tzdata", - "clock", - "iana-time-zone", "now", "serde", "std", - "winapi", - "windows-targets", ], rustlibs: [ - "libiana_time_zone", "libnum_traits", "libserde", ], @@ -62,3 +57,25 @@ rust_library { product_available: true, vendor_available: true, } + +rust_library_host { + name: "libchrono_clock", + crate_name: "chrono", + cargo_env_compat: true, + cargo_pkg_version: "0.4.34", + srcs: ["src/lib.rs"], + edition: "2021", + features: [ + "alloc", + "clock", + "now", + "serde", + "std", + "winapi", + "windows-targets", + ], + rustlibs: [ + "libnum_traits", + "libserde", + ], +} @@ -88,8 +88,6 @@ __internal_bench = [] alloc = [] clock = [ "winapi", - "iana-time-zone", - "android-tzdata", "now", ] default = [ diff --git a/cargo_embargo.json b/cargo_embargo.json index 64c53eb..736574c 100644 --- a/cargo_embargo.json +++ b/cargo_embargo.json @@ -1,12 +1,17 @@ { - "apex_available": [ - "//apex_available:platform", - "com.android.virt" - ], - "features": [ - "std", - "clock", - "serde" - ], - "run_cargo": false + "apex_available": ["//apex_available:platform", "com.android.virt"], + "features": ["now", "serde", "std"], + "run_cargo": false, + "variants": [ + {}, + { + "features": ["clock", "now", "serde", "std"], + "module_name_overrides": { "libchrono": "libchrono_clock" }, + "package": { + "chrono": { + "device_supported": false + } + } + } + ] } diff --git a/patches/no-tzdata.patch b/patches/no-tzdata.patch new file mode 100644 index 0000000..d4df88d --- /dev/null +++ b/patches/no-tzdata.patch @@ -0,0 +1,51 @@ +diff --git a/Cargo.toml b/Cargo.toml +index 9f0f82f..535a845 100644 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -88,8 +88,6 @@ __internal_bench = [] + alloc = [] + clock = [ + "winapi", +- "iana-time-zone", +- "android-tzdata", + "now", + ] + default = [ +diff --git a/patches/no-tzdata.patch b/patches/no-tzdata.patch +index 230cf9e..e69de29 100644 +--- a/patches/no-tzdata.patch ++++ b/patches/no-tzdata.patch +@@ -1,13 +0,0 @@ +-diff --git a/Cargo.toml b/Cargo.toml +-index 9f0f82f..535a845 100644 +---- a/Cargo.toml +-+++ b/Cargo.toml +-@@ -88,8 +88,6 @@ __internal_bench = [] +- alloc = [] +- clock = [ +- "winapi", +-- "iana-time-zone", +-- "android-tzdata", +- "now", +- ] +- default = [ +diff --git a/src/offset/local/unix.rs b/src/offset/local/unix.rs +index ce96a6e..ce844cc 100644 +--- a/src/offset/local/unix.rs ++++ b/src/offset/local/unix.rs +@@ -77,8 +77,14 @@ const TZDB_LOCATION: &str = "/usr/share/lib/zoneinfo"; + #[cfg(not(any(target_os = "android", target_os = "aix")))] + const TZDB_LOCATION: &str = "/usr/share/zoneinfo"; + ++// Android patch to avoid iana-time-zone dependency. ++fn get_timezone() -> Result<String, std::io::Error> { ++ let tz_name = std::fs::read_to_string("/etc/timezone")?; ++ Ok(tz_name.trim_end().to_string()) ++} ++ + fn fallback_timezone() -> Option<TimeZone> { +- let tz_name = iana_time_zone::get_timezone().ok()?; ++ let tz_name = get_timezone().ok()?; + #[cfg(not(target_os = "android"))] + let bytes = fs::read(format!("{}/{}", TZDB_LOCATION, tz_name)).ok()?; + #[cfg(target_os = "android")] diff --git a/src/offset/local/unix.rs b/src/offset/local/unix.rs index ce96a6e..ce844cc 100644 --- a/src/offset/local/unix.rs +++ b/src/offset/local/unix.rs @@ -77,8 +77,14 @@ const TZDB_LOCATION: &str = "/usr/share/lib/zoneinfo"; #[cfg(not(any(target_os = "android", target_os = "aix")))] const TZDB_LOCATION: &str = "/usr/share/zoneinfo"; +// Android patch to avoid iana-time-zone dependency. +fn get_timezone() -> Result<String, std::io::Error> { + let tz_name = std::fs::read_to_string("/etc/timezone")?; + Ok(tz_name.trim_end().to_string()) +} + fn fallback_timezone() -> Option<TimeZone> { - let tz_name = iana_time_zone::get_timezone().ok()?; + let tz_name = get_timezone().ok()?; #[cfg(not(target_os = "android"))] let bytes = fs::read(format!("{}/{}", TZDB_LOCATION, tz_name)).ok()?; #[cfg(target_os = "android")] |