Skip to content

Commit

Permalink
Make TimeZones.jl relocatable (#479)
Browse files Browse the repository at this point in the history
* Determine tree hash directly from Artifacts.toml

* Use `locate_package`

* Test for sysimage

---------

Co-authored-by: Curtis Vogt <[email protected]>
  • Loading branch information
lcontento and omus authored Dec 20, 2024
1 parent 041974d commit d6eff71
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 232 deletions.
55 changes: 54 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,65 @@ jobs:
with:
version: "1.6" # LTS / Oldest support version
- uses: julia-actions/cache@v2
- shell: julia --color=yes --project=docs {0}
- shell: julia --color=yes --project=weakdeps {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="TimeZones", rev=ENV["SHA"]))
using TimeZones
# TODO: Use shared project environments when the minimum version of Julia is 1.8 (e.g. `@sysimage`)
sysimage:
name: System Image - Julia ${{ matrix.version }} - TZJData ${{ matrix.tzjdata-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- "1.6" # LTS / Oldest supported version
- "1" # Latest release
os:
- ubuntu-latest
tzjdata-version:
- "1.3.0" # Version which does not support `artifact_dir`
- "1"
env:
JULIA_DEPOT_PATH: build-depot
TZJDATA_VERSION: ${{ matrix.tzjdata-version }}
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v2
- name: Add TimeZones
shell: julia --color=yes --project=sysimage {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="TZJData", version=ENV["TZJDATA_VERSION"]))
Pkg.add(PackageSpec(name="TimeZones", rev=ENV["SHA"]))
- name: Create sysimage
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="PackageCompiler", version="2"))
using PackageCompiler
create_sysimage(; project="sysimage", sysimage_path="sysimage.so")
# create_sysimage(; project=joinpath(first(DEPOT_PATH), "environments", "sysimage"), sysimage_path="sysimage.so")
- name: Validate sysimage works
shell: julia --color=yes --project=sysimage -Jsysimage.so {0}
run: |
using TimeZones
println(TimeZones._COMPILED_DIR[])
- name: Relocate Julia depot
run: mv build-depot sysimage-depot
- name: Validate sysimage works with relocated depot
shell: julia --color=yes --project=sysimage -Jsysimage.so {0}
run: |
using TimeZones
println(TimeZones._COMPILED_DIR[])
env:
JULIA_DEPOT_PATH: sysimage-depot

benchmarks:
name: Benchmarks
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Curtis Vogt <[email protected]>"]
version = "1.19.0"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
InlineStrings = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48"
Expand All @@ -22,6 +23,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
TimeZonesRecipesBaseExt = "RecipesBase"

[compat]
Artifacts = "1"
Aqua = "0.8"
Dates = "1"
Downloads = "1"
Expand Down
230 changes: 0 additions & 230 deletions docs/Manifest.toml

This file was deleted.

17 changes: 16 additions & 1 deletion src/TimeZones.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module TimeZones

using Artifacts: Artifacts
using Dates
using Printf
using Scratch: @get_scratch!
Expand Down Expand Up @@ -33,13 +34,27 @@ export TimeZone, @tz_str, istimezone, FixedTimeZone, VariableTimeZone, ZonedDate

_scratch_dir() = @get_scratch!("build")

const _COMPILED_DIR = Ref{String}(TZJData.ARTIFACT_DIR)
const _COMPILED_DIR = Ref{String}()

# TimeZone types used to disambiguate the context of a DateTime
# abstract type UTC <: TimeZone end # Already defined in the Dates stdlib
abstract type Local <: TimeZone end

function __init__()
# Set at runtime to ensure relocatability
_COMPILED_DIR[] = @static if isdefined(TZJData, :artifact_dir)
TZJData.artifact_dir()
else
# Backwards compatibility for TZJData versions below v1.3.1. The portion of the
# code which determines the `pkg_dir` could be replaced by `pkgdir(TZJData)` however
# the `pkgdir` function doesn't work well with relocated system images.
pkg = Base.identify_package(TZJData, "TZJData")
pkg_dir = dirname(dirname(Base.locate_package(pkg)))
artifact_dict = Artifacts.parse_toml(joinpath(pkg_dir, "Artifacts.toml"))
hash = Base.SHA1(artifact_dict["tzjdata"]["git-tree-sha1"])
Artifacts.artifact_path(hash)
end

# Dates extension needs to happen everytime the module is loaded (issue #24)
init_dates_extension()

Expand Down

0 comments on commit d6eff71

Please sign in to comment.