-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
time/tzdata: consider switching to //go:embed #43350
Comments
IIRC go:embed can't embed files outside the package |
We can copy the files into the package, and then embed them. They'll be there in the source code, but that's OK: they're already in the source code anyhow. (I don't know for sure that this will be a win, but it certainly seems plausible.) |
@mengzhuo Do you mean module, rather than package? From https://go.googlesource.com/proposal/+/master/design/draft-embed.md:
The lib/time/zoneinfo.zip file is currently outside the std module. I don't know if there are any external constraints preventing it from being moved (instead of copied). |
@dmitshur Yes you are right. I can submit a CL that move zoneinfo.zip into tzdata. |
I' m trying to put zoneinfo.zip in tzdata and build with
|
Unfortunately according to the depsRules(go/build/deps_test.go) that embed's dependency makes it impossible to set tzdata "depends" on embed.
@dmitshur Maybe we could add some comment in the tzdata. |
This can be done once embed dependency resolved. |
Proposal #43217 was declined so it seems we can't use |
Maybe there's another approach that can be considered. When the "timetzdata" build constraint is satisfied, instead of having |
Could you be more specific ? |
I had the same idea without noticing this older issue and mailed https://go-review.googlesource.com/c/go/+/389834, which works, minus the same problem that @mengzhuo mentions: the import cycle. I filed #51463 with a couple of ideas to work around the problem at the toolchain level. In the meantime, I might try workarounds that don't require modifying the toolchain, just to unblock the CL. I realise that moving zoneinfo.zip from GOROOT/lib to GOROOT/src was rejected in the past, as "churn with no benefit", but I think it does have a significant benefit with |
Update: I don't think we can work around the toolchain issue by cleverly using internal packages to let the time package reach the embedded tzdata string. The build tag still needs to somehow make I'm now implementing the toolchain change as proposed in #51463; follow that issue for updates. |
Change https://go.dev/cl/389834 mentions this issue: |
Change https://go.dev/cl/404435 mentions this issue: |
I've closed #51463 in favor of this thread, as I no longer think my @rsc @ianlancetaylor do either of you have thoughts on #51463 (comment)? I'd love to agree on a route so we can implement it for 1.20. |
I'm fine with having cmd/dist generate the file at build time. |
Change https://go.dev/cl/455357 mentions this issue: |
Looks like this will be merged for 1.21 when the tree reopens; thanks @rsc! |
Change https://go.dev/cl/463155 mentions this issue: |
A generated file (src/time/tzdata/zzipdata.go) was added in CL 455357. Also add a test to catch any generated files added in the future. Updates golang/go#43350. Change-Id: I4965744c7023a68a68609506b9cdc99a6f27ea4a Reviewed-on: https://go-review.googlesource.com/c/build/+/463155 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
Go 1.16 adds the
//go:embed
directive. Can and shouldtzdata
implementation be modified to embed a binary file rather than the current approach of generating a zipdata.go file with aconst zipdata
?Doing so would slightly reduce the Go distribution size (#27151), because the zipdata.go file encodes 424 KB of data into a 1.4 MB byte .go file (so a saving of up to 1 MB). (If it can be arranged so the existing
lib/time/zoneinfo.zip
file is embedded directly, skipping a tzdata-specific copy, then the savings can be even larger.)Would there be other benefits?
CC @ianlancetaylor, @rsc.
The text was updated successfully, but these errors were encountered: