Skip to content

Commit

Permalink
Improve build logic to identify when to build from source
Browse files Browse the repository at this point in the history
This ensures that:
* We don't build or download anything unnecessarily on 0.6
* We can build from source upon request
* We don't use binaries for non-glibc Linux
* We don't use binaries for Linux with prehistoric glibc
  • Loading branch information
ararslan committed Oct 3, 2017
1 parent 380b617 commit 539b2c7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 44 deletions.
48 changes: 48 additions & 0 deletions deps/binaries.jl
@@ -0,0 +1,48 @@
using BinDeps, Compat
using BinDeps: libdir

modified_defaults = false
if !in(BinDeps.Binaries, BinDeps.defaults)
unshift!(BinDeps.defaults, BinDeps.Binaries)
modified_defaults = true
end

BinDeps.@setup
did_setup = true

const OSF_VERS = v"0.5.3"

openspecfun = library_dependency("libopenspecfun")

const URL = "https://github.com/ararslan/openspecfun-builder/releases/download/v$OSF_VERS" *
"/libopenspecfun-$OSF_VERS"

const DOWNLOADS = Dict(
"Linux-x86_64" => ("$URL-linux-x86_64.tar.gz",
"d70a2a391915f64f44da21915bf93ce08d054127028088addca36e16ac53bcb1"),
"Linux-i686" => ("$URL-linux-i686.tar.gz",
"e5418b170b537af2f7f1f1d06eee9be01555404f5d22a47e18bc06a540321478"),
"Darwin-x86_64" => ("$URL-osx-x86_64.tar.gz",
"e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"),
"Windows-x86_64" => ("$URL-win-x86_64.zip",
"7a5f7be4ed46d7f9d6d18a599157075512c50a372da2b2908079a3dcab9a0f25"),
"Windows-i686" => ("$URL-win-i686.zip",
"2f63a08d80e67964e2c368367f4caef7039080828e217d288669416cd46f4584"),
)

const SYSTEM = string(BinDeps.OSNAME, '-', Sys.ARCH)

if haskey(DOWNLOADS, SYSTEM)
url, sha = DOWNLOADS[SYSTEM]
provides(Binaries, URI(url), openspecfun, SHA=sha, os=BinDeps.OSNAME,
unpacked_dir=joinpath("usr", "lib"), installed_libpath=libdir(openspecfun))
else
info("No precompiled binaries found for your system. Building from scratch...")
include("scratch.jl")
end

BinDeps.@install Dict(:libopenspecfun => :openspecfun)

if modified_defaults
shift!(BinDeps.defaults)
end
72 changes: 29 additions & 43 deletions deps/build.jl
@@ -1,47 +1,33 @@
using BinDeps, Compat
using BinDeps: libdir, srcdir, includedir, depsdir, builddir
using Compat
using Compat.Sys: isapple, islinux, iswindows
using Base.Libdl: dlopen_e, dlsym_e

modified_defaults = false
if !in(BinDeps.Binaries, BinDeps.defaults)
unshift!(BinDeps.defaults, BinDeps.Binaries)
modified_defaults = true
end

BinDeps.@setup

const OSF_VERS = v"0.5.3"

openspecfun = library_dependency("libopenspecfun")

const URL = "https://github.com/ararslan/openspecfun-builder/releases/download/v$OSF_VERS" *
"/libopenspecfun-$OSF_VERS"

const DOWNLOADS = Dict(
"Linux-x86_64" => ("$URL-linux-x86_64.tar.gz",
"d70a2a391915f64f44da21915bf93ce08d054127028088addca36e16ac53bcb1"),
"Linux-i686" => ("$URL-linux-i686.tar.gz",
"e5418b170b537af2f7f1f1d06eee9be01555404f5d22a47e18bc06a540321478"),
"Darwin-x86_64" => ("$URL-osx-x86_64.tar.gz",
"e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"),
"Windows-x86_64" => ("$URL-win-x86_64.zip",
"7a5f7be4ed46d7f9d6d18a599157075512c50a372da2b2908079a3dcab9a0f25"),
"Windows-i686" => ("$URL-win-i686.zip",
"2f63a08d80e67964e2c368367f4caef7039080828e217d288669416cd46f4584"),
)
did_setup = false

const SYSTEM = string(BinDeps.OSNAME, '-', Sys.ARCH)

if haskey(DOWNLOADS, SYSTEM)
url, sha = DOWNLOADS[SYSTEM]
provides(Binaries, URI(url), openspecfun, SHA=sha, os=BinDeps.OSNAME,
unpacked_dir=joinpath("usr", "lib"), installed_libpath=libdir(openspecfun))
else
info("No precompiled binaries found for your system. Building from scratch...")
if VERSION < v"0.7.0-DEV.1760"
# No need to build or download anything; openspecfun is part of Julia
elseif get(ENV, "JULIA_SPECIALFUNCTIONS_BUILD_SOURCE", "false") == "true"
# Allow a fast-path for building from source
info("Building openspecfun from source by request")
include("scratch.jl")
end

BinDeps.@install Dict(:libopenspecfun => :openspecfun)

if modified_defaults
shift!(BinDeps.defaults)
elseif isapple() || iswindows()
# Windows and macOS can always use our binaries, and we have no binaries
# for other non-Linux systems (e.g. BSDs)
include("binaries.jl")
elseif !islinux()
include("scratch.jl")
else # linux
# Determine the glibc version. If the check fails, we know we're on a non-glibc
# system, which means we can't use the binaries and need to build from source.
# The glibc version used by the binaries is 2.6, so we need at least that.
if dlsym_e(dlopen_e("libc"), :gnu_get_libc_version) == C_NULL
include("scratch.jl")
else
libc_vers = unsafe_string(ccall(:gnu_get_libc_version, Ptr{UInt8}, ()))
if isempty(libc_vers) || VersionNumber(libc_vers) < v"2.6.0"
include("scratch.jl")
else
include("binaries.jl")
end
end
end
15 changes: 15 additions & 0 deletions deps/scratch.jl
@@ -1,7 +1,16 @@
# Building OpenSpecFun from scratch

using BinDeps
using BinDeps: libdir, srcdir, includedir, depsdir, builddir
using Base.Math: libm

# Don't call setup again if we're being included from binaries.jl
if !did_setup
BinDeps.@setup
const OSF_VERS = v"0.5.3"
openspecfun = library_dependency("libopenspecfun")
end

# If Julia is built with OpenLibm, we want to build OpenSpecFun with it as well.
# Unfortunately this requires a fair bit more work, as we need to link to the .so
# and to include the headers, which aren't readily available.
Expand Down Expand Up @@ -110,3 +119,9 @@ provides(BuildProcess,
end)
end
end), openspecfun)

# If we're being included, the installation step happens once we return back
# to binaries.jl
if !did_setup
BinDeps.@install Dict(:libopenspecfun => :openspecfun)
end
5 changes: 4 additions & 1 deletion src/SpecialFunctions.jl
Expand Up @@ -4,13 +4,16 @@ module SpecialFunctions

using Compat

let depsfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if VERSION >= v"0.7.0-DEV.1760"
depsfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("SpecialFunctions is not properly installed. Please run " *
"Pkg.build(\"SpecialFunctions\") and restart Julia.")
end
else
using Base.Math: openspecfun
end

if isdefined(Base, :airyai) && VERSION < v"0.7.0-DEV.986" #22763
Expand Down

0 comments on commit 539b2c7

Please sign in to comment.