Skip to content

Commit

Permalink
Merge pull request #123 from Kijewski/pr-no-features
Browse files Browse the repository at this point in the history
Simplify a lot by removing feature gates
  • Loading branch information
Kijewski authored Sep 14, 2022
2 parents 4c41910 + b246b99 commit 5c574a2
Show file tree
Hide file tree
Showing 16 changed files with 7,762 additions and 5,946 deletions.
47 changes: 7 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ on:
- v0.2.x
- v0.3.x
- v0.4.x
- v0.5.x
pull_request:
branches:
- main
- v0.1.x
- v0.2.x
- v0.3.x
- v0.4.x
- v0.5.x
schedule:
- cron: "58 7 * * 3"

Expand All @@ -38,7 +40,8 @@ jobs:
fail-fast: false
matrix:
toolchain:
- "1.60"
- "1.55"
- "1.56"
- stable
- nightly
platform:
Expand Down Expand Up @@ -67,7 +70,7 @@ jobs:

- run: cargo check --package tzdb --all-targets
- run: cargo clippy --package tzdb --all-targets -- -D warnings
- run: cargo test --package tzdb --all-targets -- --show-output
- run: cargo test --package tzdb --all-targets
- run: cargo run --package current-time

clippy-pedantic:
Expand Down Expand Up @@ -119,7 +122,7 @@ jobs:
components: miri

- name: Test
run: cargo miri test --package tzdb --all-targets -- --show-output
run: cargo miri test --package tzdb --all-targets

cross-miri:
strategy:
Expand Down Expand Up @@ -147,7 +150,7 @@ jobs:
target: ${{ matrix.target }}

- name: Test
run: cargo miri test --package tzdb --no-default-features --features by-name --target ${{ matrix.target }} -- --show-output
run: cargo miri test --package tzdb --target ${{ matrix.target }}

doc:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -191,42 +194,6 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

powerset:
strategy:
fail-fast: false
matrix:
toolchain:
- "1.60"
- stable
- nightly
platform:
- ubuntu-20.04
# - windows-2022
# - macos-12
versions:
- ""
- "-Zminimal-versions"

runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: ${{ matrix.toolchain }}

- name: Install hack
run: cargo hack --version || cargo +stable install cargo-hack --force

- run: cargo generate-lockfile ${{ matrix.versions }}
env:
RUSTC_BOOTSTRAP: 1

- name: Powerset
run: cargo hack test --feature-powerset --exclude-features default --ignore-private

build-cross:
strategy:
fail-fast: false
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changes between the versions

### 0.5.0-pre.1 (2022-09-14)

* Simplify a lot by removing feature gates [[#123](https://github.com/Kijewski/tzdb/pull/123)]

### 0.4.5 (2022-08-31)

* Remove [phf](https://crates.io/crates/phf) dependency
Expand Down
41 changes: 15 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,43 @@
[package]
name = "tzdb"
version = "0.4.5"
edition = "2021"
version = "0.5.0-pre.1"
edition = "2018"
authors = ["René Kijewski <[email protected]>"]
repository = "https://github.com/Kijewski/tzdb"
description = "Static time zone information for tz-rs"
license = "Apache-2.0"
keywords = ["date", "time", "timezone", "zone", "calendar"]
categories = ["date-and-time"]
readme = "README.md"
rust-version = "1.60"
rust-version = "1.55"

[dependencies]
tz-rs = { version = "^0.6.14", default-features = false, features = ["const"] }

# optional dependencies
iana-time-zone = { version = "^0.1.46", default-features = false, optional = true }
utcnow = { version = "^0.2.0", default-features = false, optional = true }
iana-time-zone = { version = "^0.1.48", default-features = false }
utcnow = { version = "^0.2.1", default-features = false }

[dev-dependencies]
criterion = "^0.3.6"
proptest = "=1"
test-strategy = "^0.2.0"
structmeta = "^0.1.5"
rand = { version = "^0.8.5", default-features = false, features = ["std", "small_rng"] }
test-strategy = "=0.1.2"
structmeta = "=0.1.4"

[features]
default = ["by-name", "list", "local", "std", "fallback", "now"]

# Enables [`tz_by_name()`] to get a time zone at runtime by name:
by-name = []

# Enables [`TZ_NAMES`] to get a list of all shipped time zones:
list = []

# Enables [`local_tz()`] to get the system time zone:
local = ["by-name", "iana-time-zone"]

# Make the unparsed, binary tzdata of a time zone available:
binary = []
default = ["std", "fallback"]

# Enable features that need the standard library `std`:
std = ["alloc", "tz-rs/std", "utcnow?/std"]
std = ["alloc", "tz-rs/std", "utcnow/std"]

# Enable features that need the standard library `alloc`:
alloc = ["tz-rs/alloc"]

# Do not fail to compile for unknown target platforms:
fallback = ["iana-time-zone?/fallback", "utcnow?/fallback"]
fallback = ["iana-time-zone/fallback", "utcnow/fallback"]

# Enables the module [`now`] to get the current time:
now = ["utcnow"]
[[bench]]
name = "by-name"
harness = false

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TZDB_VERSION := tzdb-2022c

src/generated/mod.rs: tmp/${TZDB_VERSION}/usr/share/zoneinfo/
cargo r --package make-tzdb --bin make-tzdb -- $(@D) $<
cargo +nightly fmt -- $(@D)/mod.rs $(@D)/by_name.rs $(@D)/raw_tzdata.rs
cargo +nightly fmt -- $(@D)/mod.rs $(@D)/by_name.rs $(@D)/raw_tzdata.rs $(@D)/test_all_names.rs

tmp/${TZDB_VERSION}/usr/share/zoneinfo/: tmp/${TZDB_VERSION}/
cd tmp/${TZDB_VERSION}/ && make PACKRATDATA=backzone PACKRATLIST=zone.tab TOPDIR="." install
Expand Down
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Kijewski/tzdb/CI?logo=github)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust)](https://crates.io/crates/tzdb)
![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.60+-important?logo=rust "Minimum Supported Rust Version")
![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.55+-important?logo=rust "Minimum Supported Rust Version")
[![License](https://img.shields.io/crates/l/tzdb?color=informational&logo=apache)](/LICENSES)

Static time zone information for [tz-rs](https://crates.io/crates/tz-rs).
Expand Down Expand Up @@ -38,16 +38,6 @@ let current_time = tzdb::now::in_named_or(tzdb::time_zone::GMT, "Some/City")?;

## Feature flags

* `by-name` <sup>(enabled by default, enabled by `local`)</sup> — enables `tz_by_name()` to get a time zone at runtime by name

* `list` <sup>(enabled by default)</sup> — enables `TZ_NAMES` to get a list of all shipped time zones

* `local` <sup>(enabled by default)</sup> — enables `local_tz()` to get the system time zone

* `now` <sup>(enabled by default)</sup> — enables the module `now` to get the current time

* `binary` – make the unparsed, binary tzdata of a time zone available

* `std` <sup>(enabled by default)</sup> – enable features that need the standard library `std`

* `alloc` <sup>(enabled by default, enabled by `std`)</sup> – enable features that need the standard library `alloc`
Expand Down
89 changes: 89 additions & 0 deletions benches/by-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use std::convert::TryInto;
use std::time::{Duration, Instant};

use rand::rngs::SmallRng;
use rand::seq::SliceRandom;
use rand::SeedableRng;
use tzdb::{raw_tz_by_name, TZ_NAMES};

fn benchmark_by_name(c: &mut criterion::Criterion) {
let mut names: Vec<(String, usize)> = TZ_NAMES
.iter()
.flat_map(|&name| {
let raw_len = raw_tz_by_name(name).unwrap().len();
let upper = name.to_uppercase();
let lower = name.to_lowercase();
let inverted = name
.chars()
.map(|c| match c {
'A'..='Z' => c.to_ascii_lowercase(),
'a'..='z' => c.to_ascii_uppercase(),
c => c,
})
.collect();
let spongebob1 = name
.chars()
.enumerate()
.map(|(i, c)| {
if i % 2 == 0 {
c.to_ascii_uppercase()
} else {
c.to_ascii_lowercase()
}
})
.collect();
let spongebob2 = name
.chars()
.enumerate()
.map(|(i, c)| {
if i % 2 == 1 {
c.to_ascii_uppercase()
} else {
c.to_ascii_lowercase()
}
})
.collect();
[
(name.to_owned(), raw_len),
(upper, raw_len),
(lower, raw_len),
(inverted, raw_len),
(spongebob1, raw_len),
(spongebob2, raw_len),
]
})
.collect();

c.bench_function("tzdb::raw_tz_by_name", |b| {
b.iter_custom(|iters| {
let mut nanos = 0;
for i in 0..iters {
names.shuffle(&mut SmallRng::seed_from_u64(i));

let start = Instant::now();
let names = criterion::black_box(&*names);
for &(ref name, raw_len) in names {
assert_eq!(raw_len, crate::raw_tz_by_name(name).unwrap().len());
}
nanos += start.elapsed().as_nanos();
}
Duration::from_nanos(
nanos
.try_into()
.expect("Did the test take 584 years to finish?"),
)
});
});
}

fn main() {
#[cfg(not(miri))]
{
criterion::criterion_group!(benches, benchmark_by_name);
benches();

criterion::Criterion::default()
.configure_from_args()
.final_summary();
}
}
2 changes: 1 addition & 1 deletion make-tzdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false

[dependencies]
anyhow = "=1"
convert_case = "=0.5"
convert_case = "=0.6"
indexmap = "=1"
itertools = "=0.10"
ron = "=0.8"
Expand Down
Loading

0 comments on commit 5c574a2

Please sign in to comment.