Skip to content

Commit dcbf013

Browse files
authored
Build openspecfun using BinDeps (#47)
1 parent 16be5ad commit dcbf013

File tree

4 files changed

+169
-6
lines changed

4 files changed

+169
-6
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
julia 0.6
22
Compat 0.30
3+
BinDeps

deps/build.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using BinDeps, Compat
2+
using BinDeps: libdir, srcdir, includedir, depsdir, builddir
3+
4+
modified_defaults = false
5+
if !in(BinDeps.Binaries, BinDeps.defaults)
6+
unshift!(BinDeps.defaults, BinDeps.Binaries)
7+
modified_defaults = true
8+
end
9+
10+
BinDeps.@setup
11+
12+
const OSF_VERS = v"0.5.3"
13+
14+
openspecfun = library_dependency("libopenspecfun")
15+
16+
const URL = "https://github.com/ararslan/openspecfun-builder/releases/download/v$OSF_VERS" *
17+
"/libopenspecfun-$OSF_VERS"
18+
19+
const DOWNLOADS = Dict(
20+
"x86_64-pc-linux-gnu" => ("$URL-linux-x86_64.tar.gz",
21+
"d70a2a391915f64f44da21915bf93ce08d054127028088addca36e16ac53bcb1"),
22+
"i686-pc-linux-gnu" => ("$URL-linux-i686.tar.gz",
23+
"e5418b170b537af2f7f1f1d06eee9be01555404f5d22a47e18bc06a540321478"),
24+
"x86_64-apple-darwin" => ("$URL-osx-x86_64.tar.gz",
25+
"e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"),
26+
"x86_64-w64-mingw32" => ("$URL-win-x86_64.zip",
27+
"7a5f7be4ed46d7f9d6d18a599157075512c50a372da2b2908079a3dcab9a0f25"),
28+
"i686-w64-mingw32" => ("$URL-win-i686.zip",
29+
"2f63a08d80e67964e2c368367f4caef7039080828e217d288669416cd46f4584"),
30+
)
31+
32+
const MACHINE = Compat.Sys.isapple() ? "x86_64-apple-darwin" : Sys.MACHINE
33+
34+
if haskey(DOWNLOADS, MACHINE)
35+
url, sha = DOWNLOADS[MACHINE]
36+
provides(Binaries, URI(url), openspecfun, SHA=sha, os=BinDeps.OSNAME,
37+
unpacked_dir=joinpath("usr", "lib"), installed_libpath=libdir(openspecfun))
38+
else
39+
info("No precompiled binaries found for your system. Building from scratch...")
40+
include("scratch.jl")
41+
end
42+
43+
BinDeps.@install Dict(:libopenspecfun => :openspecfun)
44+
45+
if modified_defaults
46+
shift!(BinDeps.defaults)
47+
end

deps/scratch.jl

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Building OpenSpecFun from scratch
2+
3+
using Base.Math: libm
4+
5+
# If Julia is built with OpenLibm, we want to build OpenSpecFun with it as well.
6+
# Unfortunately this requires a fair bit more work, as we need to link to the .so
7+
# and to include the headers, which aren't readily available.
8+
if libm == "libopenlibm"
9+
const OLM_VERS = v"0.5.4"
10+
use_openlibm = true
11+
12+
if !isdir(libdir(openspecfun))
13+
mkpath(libdir(openspecfun))
14+
end
15+
16+
openlibm_so = Libdl.dlpath(libm)
17+
18+
# Copy over the OpenLibm .so
19+
cp(openlibm_so, joinpath(libdir(openspecfun), basename(openlibm_so)),
20+
remove_destination=true)
21+
22+
if !isdir(srcdir(openspecfun))
23+
mkpath(srcdir(openspecfun))
24+
end
25+
26+
# Grab and unpack the tarball so we can get the header files
27+
openlibm_tarball = joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS.tar.gz")
28+
run(```
29+
curl -fkL --connect-timeout 15 -y 15
30+
https://github.com/JuliaLang/openlibm/archive/v$OLM_VERS.tar.gz
31+
-o $openlibm_tarball
32+
```)
33+
openlibm_src = joinpath(srcdir(openspecfun), "openlibm")
34+
if !isdir(openlibm_src)
35+
mkpath(openlibm_src)
36+
end
37+
run(`tar -C $openlibm_src --strip-components 1 -xf $openlibm_tarball`)
38+
39+
# Copy over all of the OpenLibm headers
40+
openlibm_include = joinpath(includedir(openspecfun), "openlibm")
41+
if !isdir(openlibm_include)
42+
mkpath(openlibm_include)
43+
end
44+
for f in readdir(joinpath(openlibm_src, "include"))
45+
cp(joinpath(openlibm_src, "include", f), joinpath(openlibm_include, f),
46+
remove_destination=true)
47+
end
48+
for f in readdir(joinpath(openlibm_src, "src"))
49+
if endswith(f, ".h")
50+
cp(joinpath(openlibm_src, "src", f), joinpath(openlibm_include, f),
51+
remove_destination=true)
52+
end
53+
end
54+
else
55+
use_openlibm = false
56+
end
57+
58+
fc = "gfortran"
59+
60+
# macOS has precompiled binaries, so it's just FreeBSD that should default to Clang
61+
if Sys.KERNEL === :FreeBSD
62+
cc = "clang"
63+
use_clang = true
64+
else
65+
cc = "gcc"
66+
use_clang = false
67+
end
68+
69+
if Sys.ARCH in [:i386, :i387, :i486, :i586, :i686]
70+
cc *= " -m32"
71+
fc *= " -m32"
72+
elseif Sys.ARCH === :x86_64
73+
cc *= " -m64"
74+
fc *= " -m64"
75+
end
76+
77+
flags = [
78+
# OpenSpecFun build flags
79+
"ARCH=\"$(Sys.ARCH)\"",
80+
"CC=\"$cc\"",
81+
"FC=\"$fc\"",
82+
"USECLANG=$(Int(use_clang))",
83+
"USEGCC=$(Int(!use_clang))",
84+
"USE_OPENLIBM=$(Int(use_openlibm))",
85+
"CFLAGS=\"-O3 -std=c99\"",
86+
"FFLAGS=\"-O2 -fPIC\"",
87+
"LDFLAGS=\"-L$(libdir(openspecfun)) -Wl,-rpath,'\$\$ORIGIN' -Wl,-z,origin\"",
88+
# Make flags
89+
"DESTDIR=\"\"",
90+
"prefix=$(depsdir(openspecfun))",
91+
"libdir=$(libdir(openspecfun))",
92+
"shlibdir=$(libdir(openspecfun))",
93+
"includedir=$(includedir(openspecfun))",
94+
"O="
95+
]
96+
97+
provides(Sources, URI("https://github.com/JuliaLang/openspecfun/archive/v$OSF_VERS.tar.gz"),
98+
openspecfun)
99+
100+
provides(BuildProcess,
101+
(@build_steps begin
102+
GetSources(openspecfun)
103+
CreateDirectory(builddir(openspecfun))
104+
@build_steps begin
105+
ChangeDirectory(builddir(openspecfun))
106+
FileRule(joinpath(libdir(openspecfun), "libopenspecfun." * Libdl.dlext),
107+
@build_steps begin
108+
CreateDirectory(libdir(openspecfun))
109+
`$MAKE_CMD install $flags`
110+
end)
111+
end
112+
end), openspecfun)

src/SpecialFunctions.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ module SpecialFunctions
44

55
using Compat
66

7+
let 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.")
13+
end
14+
end
15+
716
if isdefined(Base, :airyai) && VERSION < v"0.7.0-DEV.986" #22763
817
import Base: airyai, airyaix, airyaiprime, airyaiprimex,
918
airybi, airybix, airybiprime, airybiprimex,
@@ -60,12 +69,6 @@ end
6069
export sinint,
6170
cosint
6271

63-
if isdefined(Base.Math, :openspecfun)
64-
const openspecfun = Base.Math.openspecfun
65-
else
66-
const openspecfun = "libopenspecfun"
67-
end
68-
6972
include("bessel.jl")
7073
include("erf.jl")
7174
include("sincosint.jl")

0 commit comments

Comments
 (0)