Skip to content

Commit 34b1a1a

Browse files
use Librsvg_jll pixbuf loader (fixes #604) (#605)
* use Librsvg_jll pixbuf loader * don't use join in readdir() for Julia 1.3 * use withenv() instead of addenv() to avoid error for Windows * set permissions on loaders_dir, add pause on Windows * remove the pause just added and try to help Windows find the SVG pixbuf loader * check if libpixbufloader_svg exists, for Windows x86 * Update src/Gtk.jl Use is_available() to check for Librsvg_jll Co-authored-by: Mosè Giordano <[email protected]> * attempt to get Windows x86 working * use old code if Librsvg_jll is not available * handle case when MutableArtifacts.toml doesn't have loader_dir_hash * remove a redundant comment, mainly to check if CI fails again Co-authored-by: Mosè Giordano <[email protected]>
1 parent c23b075 commit 34b1a1a

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
GTK3_jll = "77ec8976-b24b-556a-a1bf-49a033a670a6"
1010
Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d"
1111
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
12+
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
1213
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
14+
Librsvg_jll = "925c91fb-5dd6-59dd-8e8c-345e74382d89"
1315
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1416
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1517
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

src/Gtk.jl

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ end
77

88
# Import binary definitions
99
using GTK3_jll, Glib_jll, Xorg_xkeyboard_config_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, hicolor_icon_theme_jll
10+
using Librsvg_jll
11+
using JLLWrappers
1012
using Pkg.Artifacts
1113
const libgdk = libgdk3
1214
const libgtk = libgtk3
@@ -89,14 +91,41 @@ function __init__()
8991
mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml")
9092
loaders_cache_name = "gdk-pixbuf-loaders-cache"
9193
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
94+
loaders_dir_name = "gdk-pixbuf-loaders-dir"
95+
loaders_dir_hash = artifact_hash(loaders_dir_name, mutable_artifacts_toml)
96+
9297
if loaders_cache_hash === nothing
93-
# Run gdk-pixbuf-query-loaders, capture output,
94-
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
95-
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
96-
return String(read(`$gpql`))
98+
if Librsvg_jll.is_available()
99+
# Copy loaders into a directory
100+
loaders_dir_hash = create_artifact() do art_dir
101+
loaders_dir = mkdir(joinpath(art_dir,"loaders_dir"))
102+
pixbuf_loaders = joinpath.(gdk_pixbuf_loaders_dir, readdir(gdk_pixbuf_loaders_dir))
103+
push!(pixbuf_loaders, Librsvg_jll.libpixbufloader_svg)
104+
cp.(pixbuf_loaders, joinpath.(loaders_dir, basename.(pixbuf_loaders)))
105+
end
106+
107+
loaders_dir = joinpath(artifact_path(loaders_dir_hash), "loaders_dir")
108+
# Pkg removes "execute" permissions on Windows
109+
Sys.iswindows() && chmod(artifact_path(loaders_dir_hash), 0o755; recursive=true)
110+
# Run gdk-pixbuf-query-loaders, capture output
111+
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
112+
withenv("GDK_PIXBUF_MODULEDIR"=>loaders_dir, JLLWrappers.LIBPATH_env=>Librsvg_jll.LIBPATH[]) do
113+
return String(readchomp(`$gpql`))
114+
end
97115
end
98-
end
99116

117+
bind_artifact!(mutable_artifacts_toml,
118+
loaders_dir_name,
119+
loaders_dir_hash;
120+
force=true
121+
)
122+
else # just use the gdk_pixbuf directory
123+
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
124+
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
125+
return String(read(`$gpql`))
126+
end
127+
end
128+
end
100129
# Write cache out to file in new artifact
101130
loaders_cache_hash = create_artifact() do art_dir
102131
open(joinpath(art_dir, "loaders.cache"), "w") do io
@@ -112,7 +141,9 @@ function __init__()
112141

113142
# Point gdk to our cached loaders
114143
ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache")
115-
ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir
144+
ENV["GDK_PIXBUF_MODULEDIR"] = Librsvg_jll.is_available() && loaders_dir_hash !== nothing ?
145+
joinpath(artifact_path(loaders_dir_hash), "loaders_dir") :
146+
gdk_pixbuf_loaders_dir
116147

117148
if Sys.islinux() || Sys.isfreebsd()
118149
# Needed by xkbcommon:

0 commit comments

Comments
 (0)