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

Allow crate users to opt out of some platform support #104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "iana-time-zone"
description = "get the IANA time zone for the current system"
version = "0.1.56"
version = "0.2.0"
authors = [
"Andrew Straw <[email protected]>",
"René Kijewski <[email protected]>",
Expand All @@ -15,27 +15,44 @@ readme = "README.md"
edition = "2018"

[features]
default = ["platform-all"]
# Allow users to opt out of platform support for platforms that require third
# party dependencies. Disabling any of these platforms (i.e. with
# `default-features = false`) will prevent the platform dependencies from
# appearing in downstream applications' `Cargo.lock`.
platform-all = [
"platform-android",
"platform-apple",
"platform-haiku",
"platform-wasm",
"platform-windows",
]
platform-android = ["android_system_properties"]
platform-apple = ["core-foundation-sys"]
platform-haiku = ["iana-time-zone-haiku"]
platform-wasm = ["js-sys", "wasm-bindgen"]
platform-windows = ["windows"]
# When enabled, the library will succeed to compile for unknown target platforms, and return an `Err(GetTimezoneError::OsError)` at runtime.
fallback = []

[target.'cfg(target_os = "android")'.dependencies]
android_system_properties = "0.1.5"
android_system_properties = { version = "0.1.5", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.3"
core-foundation-sys = { version = "0.8.3", optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.48.0", features = [ "Globalization" ] }
windows = { version = "0.48.0", features = [ "Globalization" ], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.50"
wasm-bindgen = "0.2.70"
js-sys = { version = "0.3.50", optional = true }
wasm-bindgen = { version = "0.2.70", optional = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3"

[target.'cfg(target_os = "haiku")'.dependencies]
iana-time-zone-haiku = { version = "0.1.1", path = "haiku" }
iana-time-zone-haiku = { version = "0.1.1", path = "haiku", optional = true }

[workspace]
members = [".", "haiku"]
Expand Down
29 changes: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@
mod ffi_utils;

#[cfg_attr(target_os = "linux", path = "tz_linux.rs")]
#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "tz_macos.rs")]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
all(feature = "platform-windows", target_os = "windows"),
path = "tz_windows.rs"
)]
#[cfg_attr(
all(
feature = "platform-apple",
any(target_os = "macos", target_os = "ios")
),
path = "tz_macos.rs"
)]
#[cfg_attr(
all(
feature = "platform-wasm",
target_arch = "wasm32",
not(target_os = "wasi")
),
path = "tz_wasm32.rs"
)]
#[cfg_attr(
Expand All @@ -52,8 +65,14 @@ mod ffi_utils;
any(target_os = "illumos", target_os = "solaris"),
path = "tz_illumos.rs"
)]
#[cfg_attr(target_os = "android", path = "tz_android.rs")]
#[cfg_attr(target_os = "haiku", path = "tz_haiku.rs")]
#[cfg_attr(
all(feature = "platform-android", target_os = "android"),
path = "tz_android.rs"
)]
#[cfg_attr(
all(feature = "platform-haiku", target_os = "haiku"),
path = "tz_haiku.rs"
)]
mod platform;

/// Error types
Expand Down
5 changes: 4 additions & 1 deletion src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ pub fn get_timezone_inner() -> std::result::Result<String, crate::GetTimezoneErr
#[cfg(not(feature = "fallback"))]
compile_error!(
"iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \
OpenBSD, Dragonfly, WebAssembly (browser), iOS, Illumos, Android, Solaris and Haiku.",
OpenBSD, Dragonfly, WebAssembly (browser), iOS, Illumos, Android, Solaris and Haiku. \
If you are seeing this error on a supported platform, ensure the platform support \
Cargo feature is enabled, e.g. platform-android, platform-apple, platform-haiku, \
platform-wasm, platform-windows, or platform-all.",
);