Skip to content

Commit 3c73a38

Browse files
ararslanbicycle1885
authored andcommitted
Provide a simple source build fallback (#15)
As of this writing, BinaryBuilder does not support all of the platforms supported by Julia, which means that CodecZlib is not usable on those systems. This provides a simple fallback for building from source, using the same version of zlib used by ZlibBuilder.
1 parent 93c1749 commit 3c73a38

2 files changed

Lines changed: 64 additions & 8 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
deps/deps.jl
5+
deps/src
6+
deps/lib

deps/build.jl

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using BinaryProvider
2+
using Compat
3+
using Compat.Libdl
24

35
# Parse some basic command-line arguments
46
const verbose = "--verbose" in ARGS
@@ -27,19 +29,70 @@ download_info = Dict(
2729
BinaryProvider.Windows(:x86_64) => ("$bin_prefix/Zlib.x86_64-w64-mingw32.tar.gz", "4479f1b7559227767e305520efe077f575b3edc7cb59235dbdca33e09a756ed1"),
2830
)
2931

30-
# First, check to see if we're all satisfied
31-
if any(!satisfied(p; verbose=verbose) for p in products)
32+
# A simple source build fallback for platforms not supported by BinaryBuilder
33+
# Assumes that tar, GNU make, and a C compiler are available
34+
function sourcebuild()
35+
srcdir = joinpath(@__DIR__, "src")
36+
libdir = joinpath(@__DIR__, "lib")
37+
z = "zlib-1.2.11"
38+
for d = [srcdir, libdir]
39+
isdir(d) && rm(d, force=true, recursive=true)
40+
mkpath(d)
41+
end
42+
download("https://zlib.net/$(z).tar.gz", joinpath(srcdir, "$(z).tar.gz"))
43+
cd(srcdir) do
44+
run(`tar xzf $(z).tar.gz`)
45+
end
46+
cd(joinpath(srcdir, z)) do
47+
run(`./configure --prefix=.`)
48+
make = Compat.Sys.isbsd() ? `gmake` : `make`
49+
run(`$make -j$(Sys.CPU_CORES)`)
50+
end
51+
found = false
52+
for f in readdir(joinpath(srcdir, z))
53+
if startswith(f, "libz." * Libdl.dlext)
54+
found = true
55+
Compat.cp(joinpath(srcdir, z, f), joinpath(libdir, f), force=true)
56+
end
57+
end
58+
found || error("zlib was unable to build properly")
59+
libz = joinpath(libdir, "libz." * Libdl.dlext)
60+
open(joinpath(@__DIR__, "deps.jl"), "w") do io
61+
println(io, """
62+
using Compat
63+
using Compat.Libdl
64+
function check_deps()
65+
ptr = Libdl.dlopen_e("$libz")
66+
loaded = ptr != C_NULL
67+
Libdl.dlclose(ptr)
68+
if !loaded
69+
error("Unable to load zlib from $libz. Please rerun " *
70+
"`Pkg.build(\\"CodecZlib\\")` and restart Julia.")
71+
end
72+
end
73+
const libz = "$libz"
74+
""")
75+
end
76+
end
77+
78+
dobuild = try
79+
key = platform_key() # This can error on older BinaryProvider versions (<=0.2.5)
80+
isdefined(BinaryProvider, :UnknownPlatform) && key == UnknownPlatform()
81+
catch
82+
true
83+
end
84+
85+
if dobuild
86+
sourcebuild()
87+
elseif any(!satisfied(p; verbose=verbose) for p in products)
88+
# Check to see if we're all satisfied
3289
if haskey(download_info, platform_key())
3390
# Download and install binaries
3491
url, tarball_hash = download_info[platform_key()]
3592
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
36-
else
37-
# If we don't have a BinaryProvider-compatible .tar.gz to download, complain.
38-
# Alternatively, you could attempt to install from a separate provider,
39-
# build from source or something more even more ambitious here.
40-
error("Your platform $(triplet(platform_key())) is not supported by this package!")
4193
end
4294
end
4395

4496
# Write out a deps.jl file that will contain mappings for our products
45-
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
97+
# This is already done if we've built from source
98+
dobuild || write_deps_file(joinpath(@__DIR__, "deps.jl"), products)

0 commit comments

Comments
 (0)