|
1 | 1 | using BinaryProvider |
| 2 | +using Compat |
| 3 | +using Compat.Libdl |
2 | 4 |
|
3 | 5 | # Parse some basic command-line arguments |
4 | 6 | const verbose = "--verbose" in ARGS |
@@ -27,19 +29,70 @@ download_info = Dict( |
27 | 29 | BinaryProvider.Windows(:x86_64) => ("$bin_prefix/Zlib.x86_64-w64-mingw32.tar.gz", "4479f1b7559227767e305520efe077f575b3edc7cb59235dbdca33e09a756ed1"), |
28 | 30 | ) |
29 | 31 |
|
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 |
32 | 89 | if haskey(download_info, platform_key()) |
33 | 90 | # Download and install binaries |
34 | 91 | url, tarball_hash = download_info[platform_key()] |
35 | 92 | 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!") |
41 | 93 | end |
42 | 94 | end |
43 | 95 |
|
44 | 96 | # 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