From d6eff71b37aedd7f07204af4ddc4d5ceeb3bbfc8 Mon Sep 17 00:00:00 2001 From: Lorenzo Contento <16554887+lcontento@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:56:13 +0100 Subject: [PATCH] Make `TimeZones.jl` relocatable (#479) * Determine tree hash directly from Artifacts.toml * Use `locate_package` * Test for sysimage --------- Co-authored-by: Curtis Vogt --- .github/workflows/CI.yml | 55 +++++++++- Project.toml | 2 + docs/Manifest.toml | 230 --------------------------------------- src/TimeZones.jl | 17 ++- 4 files changed, 72 insertions(+), 232 deletions(-) delete mode 100644 docs/Manifest.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f1eb7360..759345e8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/Project.toml b/Project.toml index 980b190b..73d6c9eb 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Curtis Vogt "] 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" @@ -22,6 +23,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" TimeZonesRecipesBaseExt = "RecipesBase" [compat] +Artifacts = "1" Aqua = "0.8" Dates = "1" Downloads = "1" diff --git a/docs/Manifest.toml b/docs/Manifest.toml deleted file mode 100644 index 4be30318..00000000 --- a/docs/Manifest.toml +++ /dev/null @@ -1,230 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.9.4" -manifest_format = "2.0" -project_hash = "b0e0fdd6d2084cf873bc7d6040a84520736d76d6" - -[[deps.ANSIColoredPrinters]] -git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" -uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9" -version = "0.0.1" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" -version = "1.1.1" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[deps.Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[deps.Compat]] -deps = ["TOML", "UUIDs"] -git-tree-sha1 = "c955881e3c981181362ae4088b35995446298b80" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.14.0" - - [deps.Compat.extensions] - CompatLinearAlgebraExt = "LinearAlgebra" - - [deps.Compat.weakdeps] - Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" - LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[deps.DocStringExtensions]] -deps = ["LibGit2"] -git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.9.3" - -[[deps.Documenter]] -deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "39fd748a73dce4c05a9655475e437170d8fb1b67" -uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.27.25" - -[[deps.Downloads]] -deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" -version = "1.6.0" - -[[deps.ExprTools]] -git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec" -uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" -version = "0.1.10" - -[[deps.FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - -[[deps.IOCapture]] -deps = ["Logging", "Random"] -git-tree-sha1 = "8b72179abc660bfab5e28472e019392b97d0985c" -uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" -version = "0.2.4" - -[[deps.InlineStrings]] -deps = ["Parsers"] -git-tree-sha1 = "9cc2baf75c6d09f9da536ddf58eb2f29dedaf461" -uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48" -version = "1.4.0" - -[[deps.InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[deps.JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.4" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.4" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "8.4.0+0" - -[[deps.LibGit2]] -deps = ["Base64", "NetworkOptions", "Printf", "SHA"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.11.0+1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[deps.Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[deps.Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.2+0" - -[[deps.Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[deps.Mocking]] -deps = ["Compat", "ExprTools"] -git-tree-sha1 = "4cc0c5a83933648b615c36c2b956d94fda70641e" -uuid = "78c3b35d-d492-501b-9361-3d52fe80e533" -version = "0.7.7" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2022.10.11" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.Parsers]] -deps = ["Dates", "PrecompileTools", "UUIDs"] -git-tree-sha1 = "8489905bcdbcfac64d1daa51ca07c0d8f0283821" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.8.1" - -[[deps.PrecompileTools]] -deps = ["Preferences"] -git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f" -uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -version = "1.2.1" - -[[deps.Preferences]] -deps = ["TOML"] -git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" -uuid = "21216c6a-2e73-6563-6e65-726566657250" -version = "1.4.3" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[deps.REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[deps.Random]] -deps = ["SHA", "Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.Scratch]] -deps = ["Dates"] -git-tree-sha1 = "3bac05bc7e74a75fd9cba4295cde4045d9fe2386" -uuid = "6c6a2e73-6563-6170-7368-637461726353" -version = "1.2.1" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[deps.Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.TZJData]] -deps = ["Artifacts"] -git-tree-sha1 = "1607ad46cf8d642aa779a1d45af1c8620dbf6915" -uuid = "dc5dba14-91b3-4cab-a142-028a31da12f7" -version = "1.2.0+2024a" - -[[deps.Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[deps.TimeZones]] -deps = ["Dates", "Downloads", "InlineStrings", "Mocking", "Printf", "Scratch", "TZJData", "Unicode", "p7zip_jll"] -path = ".." -uuid = "f269a46b-ccf7-5d73-abea-4c690281aa53" -version = "1.14.0" - - [deps.TimeZones.extensions] - TimeZonesRecipesBaseExt = "RecipesBase" - - [deps.TimeZones.weakdeps] - RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" - -[[deps.UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+0" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.52.0+1" - -[[deps.p7zip_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" -version = "17.4.0+0" diff --git a/src/TimeZones.jl b/src/TimeZones.jl index b8eb6c51..ce7032b8 100644 --- a/src/TimeZones.jl +++ b/src/TimeZones.jl @@ -1,5 +1,6 @@ module TimeZones +using Artifacts: Artifacts using Dates using Printf using Scratch: @get_scratch! @@ -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()