From 0281caa780262c7d1d489989b10d501de36f250b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 4 Sep 2017 22:28:17 -0700 Subject: [PATCH 1/5] Build openspecfun using BinDeps --- REQUIRE | 1 + deps/build.jl | 47 ++++++++++++++++++ deps/scratch.jl | 107 ++++++++++++++++++++++++++++++++++++++++ src/SpecialFunctions.jl | 15 +++--- 4 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 deps/build.jl create mode 100644 deps/scratch.jl diff --git a/REQUIRE b/REQUIRE index f1081da9..b2cffb82 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.6 Compat 0.30 +BinDeps diff --git a/deps/build.jl b/deps/build.jl new file mode 100644 index 00000000..a59d5634 --- /dev/null +++ b/deps/build.jl @@ -0,0 +1,47 @@ +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 + +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( + "x86_64-pc-linux-gnu" => ("$URL-linux-x86_64.tar.gz", + "81a10717473138fea2c0cced61311cbe7d80cc8f1080868462278cb5f59a83e7"), + "i686-pc-linux-gnu" => ("$URL-linux-i686.tar.gz", + "fb32ab0d11d57b7d26c0bf7f57388b57dbfa84d5f9debd176c6fa1e636503910"), + "x86_64-apple-darwin" => ("$URL-osx-x86_64.tar.gz", + "e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"), + "x86_64-w64-mingw32" => ("$URL-win-x86_64.zip", + "7a5f7be4ed46d7f9d6d18a599157075512c50a372da2b2908079a3dcab9a0f25"), + "i686-w64-mingw32" => ("$URL-win-i686.zip", + "2f63a08d80e67964e2c368367f4caef7039080828e217d288669416cd46f4584"), +) + +const MACHINE = Compat.Sys.isapple() ? "x86_64-apple-darwin" : Sys.MACHINE + +if haskey(DOWNLOADS, MACHINE) + url, sha = DOWNLOADS[MACHINE] + 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 diff --git a/deps/scratch.jl b/deps/scratch.jl new file mode 100644 index 00000000..1e866072 --- /dev/null +++ b/deps/scratch.jl @@ -0,0 +1,107 @@ +# Building OpenSpecFun from scratch + +# 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. +if Base.Math.libm == "libopenlibm" + const OLM_VERS = v"0.5.4" + use_openlibm = true + + jl_libdir = joinpath(JULIA_HOME, "..", "lib", "julia") + + if !isdir(libdir(openspecfun)) + mkpath(libdir(openspecfun)) + end + + # Copy over the OpenLibm .so + cp(joinpath(jl_libdir, "libopenlibm." * Libdl.dlext), + joinpath(libdir(openspecfun), "libopenlibm." * Libdl.dlext), + remove_destination=true) + + # Grab and unpack the tarball so we can get the header files + openlibm_tarball = joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS.tar.gz") + run(``` + curl -fkL --connect-timeout 15 -y 15 + https://github.com/JuliaLang/openlibm/archive/v$OLM_VERS.tar.gz + -o $openlibm_tarball + ```) + openlibm_src = joinpath(srcdir(openspecfun), "openlibm") + if !isdir(openlibm_src) + mkpath(openlibm_src) + end + run(`tar -C $openlibm_src --strip-components 1 -xf $openlibm_tarball`) + + # Copy over all of the OpenLibm headers + openlibm_include = joinpath(includedir(openspecfun), "openlibm") + if !isdir(openlibm_include) + mkpath(openlibm_include) + end + for f in readdir(joinpath(openlibm_src, "include")) + cp(joinpath(openlibm_src, "include", f), joinpath(openlibm_include, f), + remove_destination=true) + end + for f in readdir(joinpath(openlibm_src, "src")) + if endswith(f, ".h") + cp(joinpath(openlibm_src, "src", f), joinpath(openlibm_include, f), + remove_destination=true) + end + end +else + use_openlibm = false +end + +fc = "gfortran" + +# macOS has precompiled binaries, so it's just FreeBSD that should default to Clang +if Sys.KERNEL === :FreeBSD + cc = "clang" + use_clang = true +else + cc = "gcc" + use_clang = false +end + +if Sys.ARCH in [:i386, :i387, :i486, :i586, :i686] + cc *= " -m32" + fc *= " -m32" +elseif Sys.ARCH === :x86_64 + cc *= " -m64" + fc *= " -m64" +end + +flags = [ + # OpenSpecFun build flags + "ARCH=\"$(Sys.ARCH)\"", + "CC=\"$cc\"", + "FC=\"$fc\"", + "USECLANG=$(Int(use_clang))", + "USEGCC=$(Int(!use_clang))", + "USE_OPENLIBM=$(Int(use_openlibm))", + "CFLAGS=\"-O3 -std=c99\"", + "FFLAGS=\"-O2 -fPIC\"", + "LDFLAGS=\"-L$(libdir(openspecfun)) -Wl,-rpath,'\$\$ORIGIN' -Wl,-z,origin\"", + # Make flags + "DESTDIR=\"\"", + "prefix=$(depsdir(openspecfun))", + "libdir=$(libdir(openspecfun))", + "shlibdir=$(libdir(openspecfun))", + "includedir=$(includedir(openspecfun))", + "O=" +] + +provides(Sources, URI("https://github.com/JuliaLang/openspecfun/archive/v$OSF_VERS.tar.gz"), + openspecfun) + +provides(BuildProcess, + (@build_steps begin + GetSources(openspecfun) + CreateDirectory(builddir(openspecfun)) + @build_steps begin + ChangeDirectory(builddir(openspecfun)) + FileRule(joinpath(libdir(openspecfun), "libopenspecfun." * Libdl.dlext), + @build_steps begin + CreateDirectory(libdir(openspecfun)) + `$MAKE_CMD install $flags` + end) + end + end), openspecfun) diff --git a/src/SpecialFunctions.jl b/src/SpecialFunctions.jl index ef5eca24..3a740d9c 100644 --- a/src/SpecialFunctions.jl +++ b/src/SpecialFunctions.jl @@ -4,6 +4,15 @@ module SpecialFunctions using Compat +let 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 +end + if isdefined(Base, :airyai) && VERSION < v"0.7.0-DEV.986" #22763 import Base: airyai, airyaix, airyaiprime, airyaiprimex, airybi, airybix, airybiprime, airybiprimex, @@ -60,12 +69,6 @@ end export sinint, cosint -if isdefined(Base.Math, :openspecfun) - const openspecfun = Base.Math.openspecfun -else - const openspecfun = "libopenspecfun" -end - include("bessel.jl") include("erf.jl") include("sincosint.jl") From 3204ae0403e0728f046347b450f244f4db01566f Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 5 Sep 2017 14:20:05 -0700 Subject: [PATCH 2/5] Correct Linux tarball checksums --- deps/build.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index a59d5634..5f3c79c0 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -18,9 +18,9 @@ const URL = "https://github.com/ararslan/openspecfun-builder/releases/download/v const DOWNLOADS = Dict( "x86_64-pc-linux-gnu" => ("$URL-linux-x86_64.tar.gz", - "81a10717473138fea2c0cced61311cbe7d80cc8f1080868462278cb5f59a83e7"), + "0c1e7dc521744b758c9871ad5c5d9a09488b55846c0035c0daa5f1af8a3900ca"), "i686-pc-linux-gnu" => ("$URL-linux-i686.tar.gz", - "fb32ab0d11d57b7d26c0bf7f57388b57dbfa84d5f9debd176c6fa1e636503910"), + "828e9fef2556fe50e7f4de5517565347825f475de8e5a3b0914e20f90adc8297"), "x86_64-apple-darwin" => ("$URL-osx-x86_64.tar.gz", "e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"), "x86_64-w64-mingw32" => ("$URL-win-x86_64.zip", From 6715ba22358069f1b33c758e9da0c871df4556b5 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 5 Sep 2017 15:59:28 -0700 Subject: [PATCH 3/5] Fixes and debugging --- .travis.yml | 9 ++++++--- deps/build.jl | 2 +- deps/scratch.jl | 15 ++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2288ff3e..08989129 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,12 @@ julia: - nightly notifications: email: false -#script: # the default script is equivalent to the following -# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi -# - julia -e 'Pkg.clone(pwd()); Pkg.build("SpecialFunctions"); Pkg.test("SpecialFunctions"; coverage=true)'; +script: # the default script is equivalent to the following + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi + - julia -e 'Pkg.clone(pwd()); Pkg.build("SpecialFunctions");' + - julia -e 'Pkg.checkout("BinDeps"); using BinDeps; BinDeps.debug("SpecialFunctions")' + - ls deps; ls deps/usr; ls deps/usr/lib + - julia -e 'Pkg.test("SpecialFunctions"; coverage=true)' after_success: - julia -e 'cd(Pkg.dir("SpecialFunctions")); Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))'; - julia -e 'cd(Pkg.dir("SpecialFunctions")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; diff --git a/deps/build.jl b/deps/build.jl index 5f3c79c0..a4a23c6a 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,5 +1,5 @@ using BinDeps, Compat -using BinDeps: libdir +using BinDeps: libdir, srcdir, includedir, depsdir, builddir modified_defaults = false if !in(BinDeps.Binaries, BinDeps.defaults) diff --git a/deps/scratch.jl b/deps/scratch.jl index 1e866072..e3211475 100644 --- a/deps/scratch.jl +++ b/deps/scratch.jl @@ -1,23 +1,28 @@ # Building OpenSpecFun from scratch +using Base.Math: libm + # 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. -if Base.Math.libm == "libopenlibm" +if libm == "libopenlibm" const OLM_VERS = v"0.5.4" use_openlibm = true - jl_libdir = joinpath(JULIA_HOME, "..", "lib", "julia") - if !isdir(libdir(openspecfun)) mkpath(libdir(openspecfun)) end + openlibm_so = Libdl.dlpath(libm) + # Copy over the OpenLibm .so - cp(joinpath(jl_libdir, "libopenlibm." * Libdl.dlext), - joinpath(libdir(openspecfun), "libopenlibm." * Libdl.dlext), + cp(openlibm_so, joinpath(libdir(openspecfun), basename(openlibm_so)), remove_destination=true) + if !isdir(srcdir(openspecfun)) + mkpath(srcdir(openspecfun)) + end + # Grab and unpack the tarball so we can get the header files openlibm_tarball = joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS.tar.gz") run(``` From f1542550253ab87e1c6179fda375e68eb842b6b0 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 5 Sep 2017 16:06:43 -0700 Subject: [PATCH 4/5] Debugging [av skip] --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08989129..34f84e21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,21 @@ language: julia os: - linux - - osx +# - osx julia: - 0.6 - nightly +addons: + apt: + packages: + - tree notifications: email: false script: # the default script is equivalent to the following - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - julia -e 'Pkg.clone(pwd()); Pkg.build("SpecialFunctions");' - julia -e 'Pkg.checkout("BinDeps"); using BinDeps; BinDeps.debug("SpecialFunctions")' - - ls deps; ls deps/usr; ls deps/usr/lib + - tree $TRAVIS_BUILD_DIR/deps - julia -e 'Pkg.test("SpecialFunctions"; coverage=true)' after_success: - julia -e 'cd(Pkg.dir("SpecialFunctions")); Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))'; From e21603f8b5fa2cb105fe6fa63cdf8a4d327a8275 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 7 Sep 2017 18:32:35 -0700 Subject: [PATCH 5/5] Update Linux SHAs for new binaries --- deps/build.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index a4a23c6a..f1a9891d 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -18,9 +18,9 @@ const URL = "https://github.com/ararslan/openspecfun-builder/releases/download/v const DOWNLOADS = Dict( "x86_64-pc-linux-gnu" => ("$URL-linux-x86_64.tar.gz", - "0c1e7dc521744b758c9871ad5c5d9a09488b55846c0035c0daa5f1af8a3900ca"), + "d70a2a391915f64f44da21915bf93ce08d054127028088addca36e16ac53bcb1"), "i686-pc-linux-gnu" => ("$URL-linux-i686.tar.gz", - "828e9fef2556fe50e7f4de5517565347825f475de8e5a3b0914e20f90adc8297"), + "e5418b170b537af2f7f1f1d06eee9be01555404f5d22a47e18bc06a540321478"), "x86_64-apple-darwin" => ("$URL-osx-x86_64.tar.gz", "e57f5f84439757a2fd1d3821a6e19a3fa69b5b1e181cc40fec0d1652fbb9efdc"), "x86_64-w64-mingw32" => ("$URL-win-x86_64.zip",