chrono-tz icon indicating copy to clipboard operation
chrono-tz copied to clipboard

Pre-generate timezone data instead of using `build.rs`

Open BStenfors9119 opened this issue 3 years ago • 4 comments

To Whom This May Concern:

I am still a pretty newbie Rust dev and trying to implement this to convert a UTC time to PST.

I am following the examples but the timezone modules do not show for me. I am apparently doing something wrong.

Here is my Cargo.toml entries:

chrono = { version = "0.4.19", default-features = false }
chrono-tz = { version = "0.5.3", default-features = false }

I am "externing" the crates chrono and chrono_tz in my main and also implementing:

use chrono::{TimeZone, UTC};

And when I try to implement chrono_tz::US::Pacific all I get is the ability to do the following:

use chrono_tz::{OffsetComponents, OffsetName};

What the heck am I missing?

TIA, B

BStenfors9119 avatar Apr 01 '21 19:04 BStenfors9119

When you say that they do not show for you, do you mean in terms of IDE support showing you all of the information? If so, rest assured that they are all there, but that the IDE may just be having some difficulty understanding how to interpret the build script and macro that generates a lot of the information.

Which IDE are you using?

neoeinstein avatar Apr 12 '21 03:04 neoeinstein

When you say that they do not show for you, do you mean in terms of IDE support showing you all of the information? If so, rest assured that they are all there, but that the IDE may just be having some difficulty understanding how to interpret the build script and macro that generates a lot of the information.

Which IDE are you using?

Ahhhhhh, didn't even think about that!

I am using Jetbrains CLion

BStenfors9119 avatar Apr 12 '21 16:04 BStenfors9119

I also hit this and wasted a lot of time on it.

The root cause is that CLion and the intellij-rust plugin do not run build scripts by default. There are instructions for turning it on in intellij-rust issue #1908. Turning it on has some downsides.

chrono-tz's build.rs loads the timezone data from the local system and generates Rust code. The library uses an include! statement in directory.rs to load the generated code. This takes data from the build machine and includes it in the binary. This is contrary to the standard software engineering practice of using a source code repository to store all inputs of the build process. If chrono_tz was published with the file already generated, then building it will no longer use data from the build host. I want this behavior. It will also speed up builds and work around the editor visibility problem.

Would the maintainers be amenable to changing chrono_tz to include a pre-generated directory.rs file?

mleonhard avatar Jul 01 '21 11:07 mleonhard

I mis-read the code. chrono-tz's build.rs does not use timezone data from the local system. At chrono-tz-build/src/lib.rs#L426, it reads files from the tz/ source dir.

I still hope that chrono-tz can include the file pre-generated so builds will be faster and users will not waste time trouble-shooting editor visibility problems.

Maybe we can include the change in #22 ?

mleonhard avatar Jul 01 '21 11:07 mleonhard