Skip to content

Commit

Permalink
Support iOS, don't compile error if unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Jul 22, 2022
1 parent 7b3b806 commit 074afdc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ jobs:
- run: which cross || cargo install cross
- run: cross build --target ${{ matrix.target }} --examples

build-ios-cross:
strategy:
matrix:
target: [aarch64-apple-ios-sim, aarch64-apple-ios, x86_64-apple-ios]
runs-on: macos-12
name: "Build for ${{ matrix.target }}"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
id: actions-rs
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ matrix.target }}-${{ steps.actions-rs.outputs.rustc_hash }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-${{ steps.actions-rs.outputs.rustc_hash }}-
${{ runner.os }}-${{ matrix.target }}-
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/bin/
target/
- run: which cross || cargo install cross
- run: cross build --target ${{ matrix.target }} --examples

check:
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["date-and-time", "internationalization", "os"]
readme = "README.md"
edition = "2018"

[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation = "0.9"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#[cfg_attr(target_os = "linux", path = "tz_linux.rs")]
#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
#[cfg_attr(target_os = "macos", path = "tz_macos.rs")]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "tz_macos.rs")]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
path = "tz_wasm32.rs"
Expand All @@ -44,20 +44,22 @@ pub enum GetTimezoneError {
IoError(std::io::Error),
/// Platform-specific error from the operating system
OsError,
/// Unsupported target OS
Unsupported,
}

impl std::error::Error for GetTimezoneError {}

impl std::fmt::Display for GetTimezoneError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
use GetTimezoneError::*;
let descr = match self {
FailedParsingString => "GetTimezoneError::FailedParsingString",
IoError(_) => "GetTimezoneError::IoError(_)",
OsError => "OsError",
};

write!(f, "{}", descr)
f.write_str(match self {
Self::FailedParsingString => "GetTimezoneError::FailedParsingString",
Self::IoError(err) => return err.fmt(f),
Self::OsError => "OsError",
Self::Unsupported => {
"Unsupported operating system, please file a bug report to iana-time-zone"
}
})
}
}

Expand All @@ -71,6 +73,7 @@ impl std::convert::From<std::io::Error> for GetTimezoneError {
///
/// See the module-level documentatation for a usage example and more details
/// about this function.
#[inline]
pub fn get_timezone() -> std::result::Result<String, crate::GetTimezoneError> {
platform::get_timezone_inner()
}
Expand Down
7 changes: 1 addition & 6 deletions src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
pub fn get_timezone_inner() -> std::result::Result<String, crate::GetTimezoneError> {
Err(crate::GetTimezoneError::FailedParsingString)
Err(crate::GetTimezoneError::Unsupported)
}

compile_error!(
"iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \
OpenBSD, Dragonfly, and WebAssembly (browser).",
);

0 comments on commit 074afdc

Please sign in to comment.