Skip to content

Commit

Permalink
move root crate implmentation into its own directoty
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-dupre committed Dec 29, 2024
1 parent 26f460a commit d3bf769
Show file tree
Hide file tree
Showing 53 changed files with 88 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data/osm_examples.txt
opening-hours/data/osm_examples.txt
docs
fuzz/artifacts
fuzz/corpus
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ homepage = "https://github.com/remi-dupre/opening-hours-rs"
description = "A parser and evaluation tool for the opening_hours fields in OpenStreetMap."
edition = "2021"
exclude = ["dist/"] # generated by maturin
build = "opening-hours/build.rs"

[workspace]
members = ["compact-calendar", "fuzz", "opening-hours-syntax", "python"]
members = ["compact-calendar", "opening-hours-syntax", "opening-hours-py", "fuzz"]

[lib]
path = "opening-hours/src/lib.rs"

[features]
# Disable timeout behavior for performance tests. This is useful when tests
Expand Down Expand Up @@ -44,6 +48,7 @@ criterion = "0.5"
[[bench]]
name = "benchmarks"
harness = false
path = "opening-hours/benches/benchmarks.rs"

[profile.dev.package.flate2]
opt-level = 3 # build script will run substantially faster for dev
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 10 additions & 2 deletions build.rs → opening-hours/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ use country_boundaries::BOUNDARIES_ODBL_60X30;

fn generate_holiday_database(out_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
const PATH_ENV_IN_OUT: [[&str; 3]; 2] = [
["PUBLIC", "data/holidays_public.txt", "holidays_public.bin"],
["SCHOOL", "data/holidays_school.txt", "holidays_school.bin"],
[
"PUBLIC",
"opening-hours/data/holidays_public.txt",
"holidays_public.bin",
],
[
"SCHOOL",
"opening-hours/data/holidays_school.txt",
"holidays_school.bin",
],
];

for [env, in_path, out_path] in &PATH_ENV_IN_OUT {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions opening-hours/src/bin/fuzz_target.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#![no_main]
use arbitrary::Arbitrary;
use chrono::DateTime;
use libfuzzer_sys::{fuzz_target, Corpus};
use opening_hours::country::Country;

use std::fmt::Debug;

use opening_hours::{Context, OpeningHours};

#[derive(Arbitrary, Clone)]
pub struct Data {
date_secs: i64,
date_nsecs: u32,
oh: String,
region: String,
}

impl Debug for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut debug = f.debug_struct("Data");

if let Some(date) = DateTime::from_timestamp(self.date_secs, self.date_nsecs) {
debug.field("date", &date.naive_utc());
}

debug.field("oh", &self.oh);
debug.field("region", &self.region);
debug.finish()
}
}

fuzz_target!(|data: Data| -> Corpus {
if data.oh.contains('=') {
// The fuzzer spends way too much time building comments.
return Corpus::Reject;
}

let Some(date) = DateTime::from_timestamp(data.date_secs, data.date_nsecs) else {
return Corpus::Reject;
};

let date = date.naive_utc();

let Ok(mut oh_1) = data.oh.parse::<OpeningHours>() else {
return Corpus::Reject;
};

let mut oh_2: OpeningHours = oh_1.to_string().parse().unwrap_or_else(|err| {
eprintln!("[ERR] Initial Expression: {}", data.oh);
eprintln!("[ERR] Invalid stringified Expression: {oh_1}");
panic!("{err}")
});

if data.region.is_empty() {
let Ok(country) = data.region.parse::<Country>() else {
return Corpus::Reject;
};

let ctx = Context::default().with_holidays(country.holidays());
oh_1 = oh_1.with_context(ctx.clone());
oh_2 = oh_2.with_context(ctx);
}

assert_eq!(oh_1.is_open(date), oh_2.is_open(date));
assert_eq!(oh_1.next_change(date), oh_2.next_change(date));
Corpus::Keep
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib.rs → opening-hours/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc = include_str!("../README.md")]
#![doc = include_str!("../../README.md")]

pub mod date_filter;
pub mod error;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ requires = ["poetry>=0.12", "maturin>=1,<2"]
build-backend = "maturin"

[tool.maturin]
manifest-path = "python/Cargo.toml"
manifest-path = "opening-hours-py/Cargo.toml"
features = [
# This feature must only be enabled during builds as it would break tests, see
# https://pyo3.rs/v0.23.3/faq.html#i-cant-run-cargo-test-or-i-cant-build-in-a-cargo-workspace-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def main():
rs_version = toml.load(rt / "Cargo.toml")["package"]["version"]
sy_version = toml.load(rt / "opening-hours-syntax/Cargo.toml")["package"]["version"]
cc_version = toml.load(rt / "compact-calendar/Cargo.toml")["package"]["version"]
py_version = toml.load(rt / "python/Cargo.toml")["package"]["version"]
py_version = toml.load(rt / "opening-hours-py/Cargo.toml")["package"]["version"]
pt_version = toml.load(rt / "pyproject.toml")["tool"]["poetry"]["version"]

print("Checking local packages:")
Expand Down

0 comments on commit d3bf769

Please sign in to comment.