diff --git a/Project.toml b/Project.toml index 9c6ecbd17..eb765b899 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232" Blosc = "a74b3585-a348-5f62-a45c-50e91977d574" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Mmap = "a63ad114-7e13-5084-954f-fe012c677804" +CMakeWrapper = "d5fb7624-851a-54ee-a528-d3f3bac0b4a0" [compat] julia = "0.7, 1" diff --git a/deps/build.jl b/deps/build.jl index 30c53e862..5cd7cabaa 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,37 +1,65 @@ using BinaryProvider # requires BinaryProvider 0.3.0 or later +ENV["FORCE_COMPILE_HDF5"] = "yes" +verbose = true + +include("compile.jl") + +# env var to force compilation from source, for testing purposes +const force_compile = get(ENV, "FORCE_COMPILE_HDF5", "no") == "yes" + # Parse some basic command-line arguments -const verbose = "--verbose" in ARGS +# const verbose = "--verbose" in ARGS const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr"))) products = [ LibraryProduct(prefix, ["libhdf5"], :libhdf5), ] +verbose && force_compile && @info("Forcing compilation from source.") + # Download binaries from hosted location bin_prefix = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/HDF5-v1.10.5+1" # Listing of files generated by BinaryBuilder: download_info = Dict( - Linux(:i686, libc=:glibc) => ("$bin_prefix/HDF5.v1.10.5.i686-linux-gnu.tar.gz", "7fcb6949436a793796f4e548ef5f6a29b01a54c0929c9680b3d2bbb89a3d69b1"), - Windows(:i686) => ("$bin_prefix/HDF5.v1.10.5.i686-w64-mingw32.tar.gz", "cb88263a578cbfc4b5d5aba1a4fe1b8883e32a20858c4b1b291159c2574ffbb3"), MacOS(:x86_64) => ("$bin_prefix/HDF5.v1.10.5.x86_64-apple-darwin14.tar.gz", "c5f491933d353c8002be6cd5750f0ce74c6f6b9fd93a499dec9040f53366ea1c"), + + Linux(:i686, libc=:glibc) => ("$bin_prefix/HDF5.v1.10.5.i686-linux-gnu.tar.gz", "7fcb6949436a793796f4e548ef5f6a29b01a54c0929c9680b3d2bbb89a3d69b1"), Linux(:x86_64, libc=:glibc) => ("$bin_prefix/HDF5.v1.10.5.x86_64-linux-gnu.tar.gz", "481378199cd8a5d67fda5b175874b5c3119cc29c6e6fecd10f7ec824e57893a6"), + + Windows(:i686) => ("$bin_prefix/HDF5.v1.10.5.i686-w64-mingw32.tar.gz", "cb88263a578cbfc4b5d5aba1a4fe1b8883e32a20858c4b1b291159c2574ffbb3"), Windows(:x86_64) => ("$bin_prefix/HDF5.v1.10.5.x86_64-w64-mingw32.tar.gz", "e21b425551395a80e83ecc41026e440611cc498b545976db0e9e2c709d7dd3ac"), ) +# source code tarball and hash for fallback compilation +source_url = "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.5/src/hdf5-1.10.5.tar.gz" +source_hash = "6d4ce8bf902a97b050f6f491f4268634e252a63dadd6656a1a9be5b7b7726fa8" + # 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!") +if dl_info === nothing && unsatisfied || force_compile + # If we don't have a compatible .tar.gz to download + # fall back to building from source, giving the library a different name + # so that it is not overwritten by BinaryBuilder downloads or vice-versa. + verbose && @info "Building from source for your platform (\"$(Sys.MACHINE)\", parsed as \"$(triplet(platform_key_abi()))\")." + + libname = "libhdf5_from_src" + products = [ + LibraryProduct(prefix, [libname], :libhdf5) + ] + unsatisfied = any(!satisfied(p; verbose=verbose) for p in products) + + source_path = joinpath(prefix, "downloads", "src.tar.gz") + if !isfile(source_path) || !verify(source_path, source_hash; verbose=verbose) || unsatisfied + compile(libname, source_url, source_hash, prefix=prefix, verbose=verbose) + end + 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) +if unsatisfied || !isinstalled(dl_info...; prefix=prefix) && !force_compile # Download and install binaries install(dl_info...; prefix=prefix, force=true, verbose=verbose) end diff --git a/deps/compile.jl b/deps/compile.jl new file mode 100644 index 000000000..cb48b8cbc --- /dev/null +++ b/deps/compile.jl @@ -0,0 +1,36 @@ +using BinaryProvider +using CMakeWrapper: cmake_executable +using Libdl: dlext + +function compile(libname, tarball_url, hash; prefix=BinaryProvider.global_prefix, verbose=false) + # download to tarball_path + tarball_path = joinpath(prefix, "downloads", "src.tar.gz") + download_verify(tarball_url, hash, tarball_path; force=true, verbose=verbose) + + # unpack into source_path + tarball_dir = joinpath(prefix, "downloads", dirname(first(list_tarball_files(tarball_path)))) # e.g. "hdf5-1.10.5" + source_path = joinpath(prefix, "downloads", "src") + verbose && @info("Unpacking $tarball_path into $source_path") + rm(tarball_dir, force=true, recursive=true) + rm(source_path, force=true, recursive=true) + unpack(tarball_path, dirname(tarball_dir); verbose=verbose) + mv(tarball_dir, source_path) + + build_dir = joinpath(source_path, "build") + mkdir(build_dir) + verbose && @info("Compiling in $build_dir...") + cd(build_dir) do + run(`$cmake_executable -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON --DHDF_ENABLE_PARALLEL=ON -DHDF5_BUILD_CPP_LIB=OFF ..`) + run(`$cmake_executable --build . --config release`) + mkpath(libdir(prefix)) + if Sys.iswindows() + cp("bin/Release/hdf5.$dlext", joinpath(libdir(prefix), libname*"."*dlext), force=true, follow_symlinks=true) + cp("bin/Release/hdf5_hl.$dlext", joinpath(libdir(prefix), libname*"_hl."*dlext), force=true, follow_symlinks=true) + cp("bin/Release/hdf5_tools.$dlext", joinpath(libdir(prefix), libname*"_tools."*dlext), force=true, follow_symlinks=true) + else + cp("bin/libhdf5.$dlext", joinpath(libdir(prefix), libname*"."*dlext), force=true, follow_symlinks=true) + cp("bin/libhdf5_hl.$dlext", joinpath(libdir(prefix), libname*"_hl."*dlext), force=true, follow_symlinks=true) + cp("bin/libhdf5_tools.$dlext", joinpath(libdir(prefix), libname*"_tools."*dlext), force=true, follow_symlinks=true) + end + end +end