Skip to content

Commit be6704d

Browse files
authored
Merge pull request #96 from KristofferC/kc/binbuilder
use BinaryBuilder for binaries
2 parents f3ee4e7 + 4f39fca commit be6704d

File tree

7 files changed

+82
-118
lines changed

7 files changed

+82
-118
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@ language: julia
22
os:
33
- linux
44
- osx
5+
addons:
6+
apt_packages:
7+
- gfortran
8+
before_install:
9+
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
10+
brew cask uninstall oclint;
11+
brew install gcc;
12+
fi
513
julia:
614
- 0.6
715
- nightly
16+
env:
17+
matrix:
18+
- JULIA_SPECIALFUNCTIONS_BUILD_SOURCE=true
19+
- JULIA_SPECIALFUNCTIONS_BUILD_SOURCE=false
820
notifications:
921
email: false
1022
#script: # the default script is equivalent to the following

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
julia 0.6
22
Compat 0.59.0
3+
BinaryProvider 0.3
34
BinDeps

deps/binaries.jl

Lines changed: 0 additions & 48 deletions
This file was deleted.

deps/build.jl

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
1-
using Compat
2-
using Compat.Sys: isapple, islinux, iswindows
1+
using BinaryProvider # requires BinaryProvider 0.3.0 or later
2+
if VERSION < v"0.7.0-DEV.1760"
3+
# No need to build or download anything; openspecfun is part of Julia
4+
else
5+
const forcecompile = get(ENV, "JULIA_SPECIALFUNCTIONS_BUILD_SOURCE", "false") == "true"
36

4-
if VERSION >= v"0.7.0-DEV.3382"
5-
using Libdl
6-
end
7+
# Parse some basic command-line arguments
8+
const verbose = "--verbose" in ARGS
9+
const prefix = Prefix(get([a for a in ARGS if a != "--verbos"], 1, joinpath(@__DIR__, "usr")))
10+
products = [
11+
LibraryProduct(prefix, String["libopenspecfun"], :openspecfun),
12+
]
713

8-
did_setup = false
14+
# Download binaries from hosted location
15+
bin_prefix = "https://github.com/JuliaMath/OpenspecfunBuilder/releases/download/v0.5.3-1"
916

10-
if VERSION < v"0.7.0-DEV.1760"
11-
# No need to build or download anything; openspecfun is part of Julia
12-
elseif get(ENV, "JULIA_SPECIALFUNCTIONS_BUILD_SOURCE", "false") == "true"
13-
# Allow a fast-path for building from source
14-
info("Building openspecfun from source by request")
15-
include("scratch.jl")
16-
elseif isapple() || iswindows()
17-
# Windows and macOS can always use our binaries, and we have no binaries
18-
# for other non-Linux systems (e.g. BSDs)
19-
include("binaries.jl")
20-
elseif !islinux()
21-
include("scratch.jl")
22-
else # linux
23-
# Determine the glibc version. If the check fails, we know we're on a non-glibc
24-
# system, which means we can't use the binaries and need to build from source.
25-
# The glibc version used by the binaries is 2.6, so we need at least that.
26-
libc_ptr = ccall(:jl_dlopen, Ptr{Cvoid}, (Ptr{Cvoid}, UInt32), C_NULL, 0)
27-
glibc_ptr = Libdl.dlsym_e(libc_ptr, :gnu_get_libc_version)
28-
if glibc_ptr == C_NULL
17+
# Listing of files generated by BinaryBuilder:
18+
download_info = Dict(
19+
Linux(:aarch64, :glibc) => ("$bin_prefix/libopenspecfun.aarch64-linux-gnu.tar.gz", "513cd981b1465b92942955369a41c8b65ce6e39ea15d39dda40aa0ecce348581"),
20+
Linux(:aarch64, :musl) => ("$bin_prefix/libopenspecfun.aarch64-linux-musl.tar.gz", "11928ed68eaa3a97d2f59be36d21cff5a8e83decfbbef7b6422775735684abf8"),
21+
Linux(:armv7l, :glibc, :eabihf) => ("$bin_prefix/libopenspecfun.arm-linux-gnueabihf.tar.gz", "5bc5f2f57b4faaed1124b59dd565f67164390ea668d0a35cc58e5dbb7256b883"),
22+
Linux(:armv7l, :musl, :eabihf) => ("$bin_prefix/libopenspecfun.arm-linux-musleabihf.tar.gz", "5d396b66de7200248ecb156e7926d2460b5e06800202a3e181d778665aa8c4cc"),
23+
Linux(:i686, :glibc) => ("$bin_prefix/libopenspecfun.i686-linux-gnu.tar.gz", "e407cab2ceac07680031a710b371e72d0f8ddb95a165969f78a1726e1aa3754e"),
24+
Linux(:i686, :musl) => ("$bin_prefix/libopenspecfun.i686-linux-musl.tar.gz", "87f7419160c299f74c8cd8ef01102adde151824cda569ce5abef3b651ea6fb8e"),
25+
Windows(:i686) => ("$bin_prefix/libopenspecfun.i686-w64-mingw32.tar.gz", "308efa58c6af46eba2ef3a0a93c029dad8f203b84de2f1fee463ea61ac505935"),
26+
Linux(:powerpc64le, :glibc) => ("$bin_prefix/libopenspecfun.powerpc64le-linux-gnu.tar.gz", "6360c407784151e469735018ad01959dba0ebfbb48537bc1ed3b078be1cd2b18"),
27+
MacOS(:x86_64) => ("$bin_prefix/libopenspecfun.x86_64-apple-darwin14.tar.gz", "88712e1a5faa31c633172716f0b27a749c018dc90eb012aa7f457e88a91a8838"),
28+
Linux(:x86_64, :glibc) => ("$bin_prefix/libopenspecfun.x86_64-linux-gnu.tar.gz", "e1e8c04b164de3cd39dde3ad0a20ee87b7ca393cf41345c5f0db270fd680bed0"),
29+
Linux(:x86_64, :musl) => ("$bin_prefix/libopenspecfun.x86_64-linux-musl.tar.gz", "9b9d12e36226689ced304cdbdbf0041982a9c9a4ddd4a62fdd3b43b39f541a47"),
30+
FreeBSD(:x86_64) => ("$bin_prefix/libopenspecfun.x86_64-unknown-freebsd11.1.tar.gz", "9e1c31bf28dee3ac42d9d1f045a4abfcbd98edee3dc645858f6a70b32896022b"),
31+
Windows(:x86_64) => ("$bin_prefix/libopenspecfun.x86_64-w64-mingw32.tar.gz", "05ff98c239f34efe514922301f9d15d1081c8e26851ace91731db468b15f5b40"),
32+
)
33+
34+
# Install unsatisfied or updated dependencies:
35+
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
36+
if haskey(download_info, platform_key()) && !forcecompile
37+
url, tarball_hash = download_info[platform_key()]
38+
if !isinstalled(url, tarball_hash; prefix=prefix)
39+
# Download and install binaries
40+
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
41+
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
42+
end
43+
end
44+
45+
if unsatisfied || forcecompile
2946
include("scratch.jl")
3047
else
31-
glibc_vers = unsafe_string(ccall(glibc_ptr, Ptr{UInt8}, ()))
32-
if isempty(glibc_vers) || VersionNumber(glibc_vers) < v"2.6.0"
33-
include("scratch.jl")
34-
else
35-
include("binaries.jl")
36-
end
48+
# Write out a deps.jl file that will contain mappings for our products
49+
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
3750
end
38-
end
51+
end

deps/scratch.jl

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
using BinDeps
44
using BinDeps: libdir, srcdir, includedir, depsdir, builddir
55
using Base.Math: libm
6+
import BinaryProvider
67

78
if VERSION >= v"0.7.0-DEV.3382"
89
using Libdl
910
end
1011

11-
# Don't call setup again if we're being included from binaries.jl
12-
if !did_setup
13-
BinDeps.@setup
14-
const OSF_VERS = v"0.5.3"
15-
openspecfun = library_dependency("libopenspecfun")
16-
end
12+
13+
BinDeps.@setup
14+
const OSF_VERS = v"0.5.3"
15+
openspecfun = library_dependency("libopenspecfun")
1716

1817
# If Julia is built with OpenLibm, we want to build OpenSpecFun with it as well.
1918
# Unfortunately this requires a fair bit more work, as we need to link to the .so
2019
# and to include the headers, which aren't readily available.
2120
if libm == "libopenlibm"
2221
const OLM_VERS = v"0.5.4"
22+
const OLM_HASH = "9a8ae1d17825a4a6a4c013d36a7f4348b27c47eedb6549c521ecc9c79d021c13"
23+
const OLM_URL = "https://github.com/JuliaLang/openlibm/archive/v$OLM_VERS.tar.gz"
2324
use_openlibm = true
2425

2526
if !isdir(libdir(openspecfun))
@@ -32,27 +33,15 @@ if libm == "libopenlibm"
3233
for lib in readdir(dirname(openlibm_so))
3334
startswith(lib, "libopenlibm") || continue
3435
cp(joinpath(dirname(openlibm_so), lib), joinpath(libdir(openspecfun), lib),
35-
remove_destination=true, follow_symlinks=false)
36+
force=true, follow_symlinks=false)
3637
end
3738

38-
if !isdir(srcdir(openspecfun))
39-
mkpath(srcdir(openspecfun))
40-
end
41-
42-
# Grab and unpack the tarball so we can get the header files
43-
openlibm_tarball = joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS.tar.gz")
44-
run(```
45-
curl -fkL --connect-timeout 15 -y 15
46-
https://github.com/JuliaLang/openlibm/archive/v$OLM_VERS.tar.gz
47-
-o $openlibm_tarball
48-
```)
49-
openlibm_src = joinpath(srcdir(openspecfun), "openlibm")
50-
if !isdir(openlibm_src)
51-
mkpath(openlibm_src)
52-
end
53-
run(`tar -C $openlibm_src --strip-components 1 -xf $openlibm_tarball`)
39+
# Grab and unpack the tarball so we can get the header filesa
40+
BinaryProvider.download_verify_unpack(OLM_URL, OLM_HASH, srcdir(openspecfun); verbose = true)
5441

5542
# Copy over all of the OpenLibm headers
43+
cp(joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS"), joinpath(srcdir(openspecfun), "openlibm"); force=true)
44+
openlibm_src = joinpath(srcdir(openspecfun), "openlibm")
5645
openlibm_include = joinpath(includedir(openspecfun), "openlibm")
5746
if !isdir(openlibm_include)
5847
mkpath(openlibm_include)
@@ -74,7 +63,7 @@ end
7463
fc = "gfortran"
7564

7665
# macOS has precompiled binaries, so it's just FreeBSD that should default to Clang
77-
if Sys.KERNEL === :FreeBSD
66+
if Sys.KERNEL === :FreeBSD || Sys.KERNEL == :Darwin
7867
cc = "clang"
7968
use_clang = true
8069
else
@@ -90,6 +79,8 @@ elseif Sys.ARCH === :x86_64
9079
fc *= " -m64"
9180
end
9281

82+
extra_ld = Sys.is_apple() ? "" : "-Wl,-rpath,'\$\$ORIGIN' -Wl,-z,origin"
83+
9384
provides(Sources, URI("https://github.com/JuliaLang/openspecfun/archive/v$OSF_VERS.tar.gz"),
9485
openspecfun, unpacked_dir="openspecfun-$OSF_VERS")
9586

@@ -112,7 +103,7 @@ provides(BuildProcess,
112103
USE_OPENLIBM=$(Int(use_openlibm))
113104
CFLAGS="-O3 -std=c99"
114105
FFLAGS="-O2 -fPIC"
115-
LDFLAGS="-L$(libdir(openspecfun)) -Wl,-rpath,'\$\$ORIGIN' -Wl,-z,origin"
106+
LDFLAGS="-L$(libdir(openspecfun)) $extra_ld"
116107
DESTDIR=""
117108
prefix=""
118109
libdir="$(libdir(openspecfun))"
@@ -123,8 +114,4 @@ provides(BuildProcess,
123114
end
124115
end), openspecfun)
125116

126-
# If we're being included, the installation step happens once we return back
127-
# to binaries.jl
128-
if !did_setup
129-
BinDeps.@install Dict(:libopenspecfun => :openspecfun)
130-
end
117+
BinDeps.@install Dict(:libopenspecfun => :openspecfun)

src/SpecialFunctions.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ module SpecialFunctions
44
using Compat
55

66
if VERSION >= v"0.7.0-DEV.1760"
7-
depsfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
8-
if isfile(depsfile)
9-
include(depsfile)
10-
else
11-
error("SpecialFunctions is not properly installed. Please run " *
12-
"Pkg.build(\"SpecialFunctions\") and restart Julia.")
7+
# Load openspecfun libraries from our deps.jl
8+
const depsjl_path = joinpath(@__DIR__, "..", "deps", "deps.jl")
9+
if !isfile(depsjl_path)
10+
error("SpecialFunctions not installed properly, run Pkg.build(\"SpecialFunctions\"), restart Julia and try again")
1311
end
12+
include(depsjl_path)
1413
else
1514
using Base.Math: openspecfun
1615
end

src/bessel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ end
192192
function _besseli(nu::Float64, z::Complex{Float64}, kode::Int32)
193193
ai1, ai2 = Ref{Float64}(), Ref{Float64}()
194194
ae1, ae2 = Ref{Int32}(), Ref{Int32}()
195-
195+
196196
ccall((:zbesi_,openspecfun), Cvoid,
197197
(Ref{Float64}, Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32},
198198
Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32}),
@@ -215,7 +215,7 @@ function _besselj(nu::Float64, z::Complex{Float64}, kode::Int32)
215215
Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32}),
216216
real(z), imag(z), nu, kode, 1,
217217
ai1, ai2, ae1, ae2)
218-
218+
219219
if ae2[] == 0 || ae2[] == 3
220220
return complex(ai1[], ai2[])
221221
else

0 commit comments

Comments
 (0)