Skip to content

Commit

Permalink
Update to LoadFlint 2.0 and rehaul build system
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Jun 24, 2020
1 parent b271774 commit 5068410
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 291 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ julia:
- 1.0
- 1.2
- 1.3
- 1.4
- nightly

branches:
Expand Down
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
LoadFlint = "472f376f-f1cf-461b-9ac1-d103423be9b7"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Arb_jll = "d9960996-1013-53c9-9ba4-74a4155039c3"
Antic_jll = "e21ec000-9f72-519e-ba6d-10061e575a27"

[compat]
AbstractAlgebra = "^0.9.1"
BinaryProvider = "0.4, 0.5"
julia = "1"
LoadFlint = "0.1.3"
LoadFlint = "^0.2.1"
Arb_jll = "= 2.17.0"
Antic_jll = "^0.1.0"
285 changes: 20 additions & 265 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,275 +1,30 @@
using Libdl
@static if VERSION < v"1.3.0"

using BinaryProvider
using BinaryProvider # requires BinaryProvider 0.3.0 or later

# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS

issource_build = "NEMO_SOURCE_BUILD" in keys(ENV) && ENV["NEMO_SOURCE_BUILD"] == "1"

const prefixpath = joinpath(@__DIR__, "usr")
# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))

const wdir = joinpath(@__DIR__)
products = [ ]

if !issource_build
# Dependencies that must be installed before this package can be built
dependencies = [
# This has to be in sync with the corresponding commit in the source build below (for flint, arb, antic)
"https://github.com/JuliaPackaging/Yggdrasil/releases/download/GMP-v6.1.2-1/build_GMP.v6.1.2.jl",
"https://github.com/JuliaPackaging/Yggdrasil/releases/download/MPFR-v4.0.2-1/build_MPFR.v4.0.2.jl",
"https://github.com/thofma/Flint2Builder/releases/download/f46562/build_libflint.v0.0.0-f465622699d5c4c22bb3617596f8ae86e4570652.jl",
"https://github.com/thofma/ArbBuilder/releases/download/6c3738-v2/build_libarb.v0.0.0-6c3738555d00b8b8b24a1f5e0065ef787432513c.jl",
"https://github.com/thofma/AnticBuilder/releases/download/364f97-v2/build_libantic.v0.0.0-364f97edd9b6af537787113cf910f16d7bbc48a3.jl"
"build_GMP.v6.1.2.jl",
"build_MPFR.v4.0.2.jl",
"build_FLINT.v0.0.1.jl",
"build_Arb.v2.17.0.jl",
"build_Antic.v0.1.0.jl",
]

const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))

products = []

for url in dependencies
build_file = joinpath(@__DIR__, basename(url))
if !isfile(build_file)
download(url, build_file)
end
end

# Execute the build scripts for the dependencies in an isolated module to avoid overwriting
# any variables/constants here
for url in dependencies
build_file = joinpath(@__DIR__, basename(url))
m = @eval module $(gensym()); include($build_file); end
append!(products, m.products)
end

filenames = ["libgmp.la", "libgmpxx.la", "libmpfr.la"]
for filename in filenames
fpath = joinpath(prefixpath, "lib", filename)
txt = read(fpath, String)
open(fpath, "w") do f
write(f, replace(txt, "/workspace/destdir" => prefixpath))
end
end

else
println("Doing a source build for C dependencies...")
if "NEMO_BUILD_THREADS" in keys(ENV)
build_threads = ENV["NEMO_BUILD_THREADS"]
println("Using $build_threads threads for building as specified by NEMO_BUILD_THREADS.")
else
build_threads = Sys.CPU_THREADS
println("Using $build_threads threads (detected that many CPU threads).")
end

@show M4_VERSION = "1.4.17"
@show YASM_VERSION = "1.3.0"
@show MPIR_VERSION = "3.0.0-90740d8fdf03b941b55723b449831c52fd7f51ca"
@show MPFR_VERSION = "4.0.0"
@show FLINT_VERSION = "f465622699d5c4c22bb3617596f8ae86e4570652"
@show ARB_VERSION = "6c3738555d00b8b8b24a1f5e0065ef787432513c"
@show ANTIC_VERSION = "364f97edd9b6af537787113cf910f16d7bbc48a3"

if Sys.iswindows()
error("Source build not available on Windows")
end

println("Removing old binaries ...")

rm(prefixpath, force = true, recursive = true)
mkdir(prefixpath)
mkdir(joinpath(prefixpath, "lib"))

if Sys.isapple() && !("CC" in keys(ENV))
ENV["CC"] = "clang"
ENV["CXX"] = "clang++"
end

LDFLAGS = "-Wl,-rpath,$prefixpath/lib -Wl,-rpath,\$\$ORIGIN/../share/julia/site/v$(VERSION.major).$(VERSION.minor)/Nemo/local/lib"
DLCFLAGS = "-fPIC -fno-common"

cd(wdir)

try
run(`m4 --version`)
catch
println("Building m4 ... ")
M4_FILE = "m4-" * M4_VERSION * ".tar.bz2"
download("http://ftp.gnu.org/gnu/m4/$M4_FILE", joinpath(wdir, "$M4_FILE"))

run(`tar -xvf $M4_FILE`)
run(`rm $M4_FILE`)
cd(joinpath("$wdir", "m4-$M4_VERSION"))
run(`./configure --prefix=$prefixpath`)
run(`make`)
run(`make install`)
println("DONE")
end

cd(wdir)

# install yasm

if !ispath(joinpath(wdir, "yasm-$YASM_VERSION"))
println("Building yasm ... ")
YASM_FILE = "yasm-" * YASM_VERSION * ".tar.gz"
download("https://github.com/yasm/yasm/archive/v$(YASM_VERSION).tar.gz", YASM_FILE)
run(`tar -xvf $YASM_FILE`)
run(`rm $YASM_FILE`)
cd(joinpath("$wdir","yasm-$YASM_VERSION"))
run(`./autogen.sh`)
run(`./configure`)
run(`make`)
println("DONE")
end

cd(wdir)

# install GMP/MPIR

MPIR_FILE = "mpir-" * MPIR_VERSION * ".tar.bz2"

if !ispath(joinpath(wdir, "mpir-$MPIR_VERSION"))
println("Downloading MPIR sources ... ")
download("http://nemocas.org/binaries/$MPIR_FILE", joinpath(wdir, MPIR_FILE))
println("DONE")
end

println("Building MPIR ... ")
if isfile(joinpath(wdir, MPIR_FILE))
run(`tar -xvf $MPIR_FILE`)
run(`rm $MPIR_FILE`)
end
cd("$wdir/mpir-$MPIR_VERSION")
try
run(`m4 --version`)
run(`./configure --with-yasm=$wdir/yasm-$YASM_VERSION/yasm --prefix=$prefixpath --enable-gmpcompat --disable-static --enable-shared`)
catch
run(`./configure --with-yasm=$wdir/yasm-$YASM_VERSION/yasm --prefix=$prefixpath M4=$prefixpath/bin/m4 --enable-gmpcompat --disable-static --enable-shared`)
end
run(`make -j$build_threads`)
run(`make install`)
cd(wdir)
run(`rm -rf bin`)
println("DONE")

cd(wdir)

# install MPFR

MPFR_FILE = "mpfr-" * MPFR_VERSION * ".tar.bz2"

if !ispath(joinpath(wdir, "mpfr-$MPFR_VERSION"))
println("Downloading MPFR sources ... ")
download("http://ftp.vim.org/ftp/gnu/mpfr/$MPFR_FILE", joinpath(wdir, MPFR_FILE))

println("DONE")
end

println("Building MPFR ... ")
if isfile(joinpath(wdir, MPFR_FILE))
run(`tar -xvf $MPFR_FILE`)
run(`rm $MPFR_FILE`)
end
cd("$wdir/mpfr-$MPFR_VERSION")
withenv("LD_LIBRARY_PATH"=>"$prefixpath/lib", "LDFLAGS"=>LDFLAGS) do
run(`./configure --prefix=$prefixpath --with-gmp=$prefixpath --disable-static --enable-shared`)
run(`make -j$build_threads`)
run(`make install`)
end
println("DONE")

cd(wdir)

# INSTALL FLINT

try
println("Cloning flint2 ... ")
run(`git clone https://github.com/wbhart/flint2.git`)
cd(joinpath("$wdir", "flint2"))
run(`git checkout $FLINT_VERSION`)
cd(wdir)
catch
if ispath(joinpath("$wdir", "flint2"))
open(`patch -R --forward -d flint2 -r -`, "r", open("../deps-PIE-ftbfs.patch"))
cd(joinpath("$wdir", "flint2"))
run(`git fetch`)
run(`git checkout $FLINT_VERSION`)
cd(wdir)
end
end
open(`patch --forward -d flint2 -r -`, "r", open("../deps-PIE-ftbfs.patch"))
println("DONE")

println("Building flint ... ")
cd(joinpath("$wdir", "flint2"))
withenv("LD_LIBRARY_PATH"=>"$prefixpath/lib", "LDFLAGS"=>LDFLAGS) do
run(`./configure --prefix=$prefixpath --disable-static --enable-shared --with-mpir=$prefixpath --with-mpfr=$prefixpath`)
run(`make -j$build_threads`)
run(`make install`)
end

println("DONE")

cd(wdir)

# INSTALL ARB

println("Cloning arb ... ")
try
run(`git clone https://github.com/fredrik-johansson/arb.git`)
cd(joinpath("$wdir", "arb"))
run(`git checkout $ARB_VERSION`)
cd(wdir)
catch
if ispath(joinpath("$wdir", "arb"))
#open(`patch -R --forward -d arb -r -`, "r", open("../deps-PIE-ftbfs.patch"))
cd(joinpath("$wdir", "arb"))
run(`git fetch`)
run(`git checkout $ARB_VERSION`)
cd(wdir)
end
end
println("DONE")

println("Building arb ... ")
cd(joinpath("$wdir", "arb"))
withenv("LD_LIBRARY_PATH"=>"$prefixpath/lib", "LDFLAGS"=>LDFLAGS) do
run(`./configure --prefix=$prefixpath --disable-static --enable-shared --with-mpir=$prefixpath --with-mpfr=$prefixpath --with-flint=$prefixpath`)
run(`make -j$build_threads`)
run(`make install`)
end
println("DONE")

cd(wdir)

# INSTALL ANTIC

println("Cloning antic ... ")
try
run(`git clone https://github.com/wbhart/antic.git`)
cd(joinpath("$wdir", "antic"))
run(`git checkout $ANTIC_VERSION`)
cd(wdir)
catch
if ispath(joinpath("$wdir", "antic"))
#open(`patch -R --forward -d antic -r -`, "r", open("../deps-PIE-ftbfs.patch"))
cd(joinpath("$wdir", "antic"))
run(`git fetch`)
run(`git checkout $ANTIC_VERSION`)
cd(wdir)
end
end
println("DONE")

println("Building antic ... ")
cd(joinpath("$wdir", "antic"))
withenv("LD_LIBRARY_PATH"=>"$prefixpath/lib", "LDFLAGS"=>LDFLAGS) do
run(`./configure --prefix=$prefixpath --disable-static --enable-shared --with-mpir=$prefixpath --with-mpfr=$prefixpath --with-flint=$prefixpath`)
run(`make -j$build_threads`)
run(`make install`)
for file in dependencies
build_file = joinpath(@__DIR__, file)
m = @eval module $(gensym()); include($build_file); end
if !occursin("FLINT", file) && !occursin("GMP", file) && !occursin("MPFR", file)
append!(products, m.products)
end
end
println("DONE")
cd(wdir)
end

push!(Libdl.DL_LOAD_PATH, joinpath(prefixpath, "lib"), joinpath(prefixpath, "bin"))
# Finally, write out a deps.jl file
write_deps_file(joinpath(@__DIR__, "deps.jl"), Array{Product,1}(products), verbose=verbose)

end # VERSION
48 changes: 48 additions & 0 deletions deps/build_Antic.v0.1.0.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using BinaryProvider # requires BinaryProvider 0.3.0 or later

# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
products = [
LibraryProduct(prefix, ["libantic"], :libantic),
]

# Download binaries from hosted location
bin_prefix = "https://github.com/JuliaBinaryWrappers/Antic_jll.jl/releases/download/Antic-v0.1.0+0"

# Listing of files generated by BinaryBuilder:
download_info = Dict(
Linux(:aarch64, libc=:glibc) => ("$bin_prefix/Antic.v0.1.0.aarch64-linux-gnu.tar.gz", "26820f90f0975f608caece27b421a4b71e5b1b2be49905ac89b96abae949ca83"),
Linux(:aarch64, libc=:musl) => ("$bin_prefix/Antic.v0.1.0.aarch64-linux-musl.tar.gz", "76f80631815f7873dd40c9c836731d78548fc13d62632c1f47c444e1b16c3678"),
Linux(:armv7l, libc=:glibc, call_abi=:eabihf) => ("$bin_prefix/Antic.v0.1.0.armv7l-linux-gnueabihf.tar.gz", "342708aade30213ebd6fdc70ecf5a62ab19e5d846d5af8003fcbc7f7cf62d215"),
Linux(:armv7l, libc=:musl, call_abi=:eabihf) => ("$bin_prefix/Antic.v0.1.0.armv7l-linux-musleabihf.tar.gz", "fc9737ce30f774e54eab9130aa173f706b88b289d7e6f188e2f68dc9546e71f3"),
Linux(:i686, libc=:glibc) => ("$bin_prefix/Antic.v0.1.0.i686-linux-gnu.tar.gz", "a01ea545a80a8d291ac8271e494fd5b6b4f5e98782018ad8eafcc3328a2dd82c"),
Linux(:i686, libc=:musl) => ("$bin_prefix/Antic.v0.1.0.i686-linux-musl.tar.gz", "5ae5a04317094810a00e48908ca4ec19d3ec9d694b899de817a7f56c69bec619"),
Windows(:i686) => ("$bin_prefix/Antic.v0.1.0.i686-w64-mingw32.tar.gz", "4e330d2ebbb1759cfb297cbb83b52046309a21fa41e041d4d4c7243a015770a7"),
Linux(:powerpc64le, libc=:glibc) => ("$bin_prefix/Antic.v0.1.0.powerpc64le-linux-gnu.tar.gz", "a2306cc34b092ff63b12361088f5fd7d88105e1c1f58a0be1b4319898a90f24a"),
MacOS(:x86_64) => ("$bin_prefix/Antic.v0.1.0.x86_64-apple-darwin14.tar.gz", "892f41a1184aa691e783ba864dc699104621a607f83dfaf6674248e914b3d2c4"),
Linux(:x86_64, libc=:glibc) => ("$bin_prefix/Antic.v0.1.0.x86_64-linux-gnu.tar.gz", "e2926aef3f1bb132d2fa276741ed4b11b7a3c4c02e854cb7825780ae74aaafc2"),
Linux(:x86_64, libc=:musl) => ("$bin_prefix/Antic.v0.1.0.x86_64-linux-musl.tar.gz", "881249c99a30b3a0437427936b8f3987e568121c38a1df072da5d78df9a81fe7"),
FreeBSD(:x86_64) => ("$bin_prefix/Antic.v0.1.0.x86_64-unknown-freebsd11.1.tar.gz", "894a1edce0cc1010aef9ee8e76218370d031a02e53fb026bafbe89fb74ecbd93"),
Windows(:x86_64) => ("$bin_prefix/Antic.v0.1.0.x86_64-w64-mingw32.tar.gz", "1c45fcc3ad0b4be155a6712f11e17e951572f88d13b380c8500d228123af710d"),
)

# Install unsatisfied or updated dependencies:
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
dl_info = choose_download(download_info, platform_key_abi())
if dl_info === nothing && unsatisfied
# If we don't have a compatible .tar.gz to download, complain.
# Alternatively, you could attempt to install from a separate provider,
# build from source or something even more ambitious here.
error("Your platform (\"$(Sys.MACHINE)\", parsed as \"$(triplet(platform_key_abi()))\") is not supported by this package!")
end

# If we have a download, and we are unsatisfied (or the version we're
# trying to install is not itself installed) then load it up!
if unsatisfied || !isinstalled(dl_info...; prefix=prefix)
# Download and install binaries
install(dl_info...; prefix=prefix, force=true, verbose=verbose)
end

# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products, verbose=verbose)
Loading

0 comments on commit 5068410

Please sign in to comment.