Skip to content

Commit

Permalink
BB try 2 (#107)
Browse files Browse the repository at this point in the history
* Update build.jl

* Update REQUIRE

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl

* Update REQUIRE

* Update SCS.jl

* Update SCS.jl

* Update REQUIRE

* Update SCS.jl

* Update SCS.jl

* Update build.jl

* Update .gitignore

* Update README.md

* Update SCS.jl

* Update REQUIRE

* Update SCS.jl

* Update SCS.jl

* Update REQUIRE

* Update SCS.jl

* Update REQUIRE

* Update SCS.jl

* Update build.jl

* Update .travis.yml

* Update build.jl

* Update build.jl

* Update .travis.yml

* Update build.jl

* Update .travis.yml

* Update .travis.yml

* Update build.jl

* Update .travis.yml

* Update appveyor.yml

* Update build.jl

* Update README.md

* Update README.md

* Update README.md

* Update build.jl

* Update build.jl

* Update build.jl

* Update build.jl
  • Loading branch information
juan-pablo-vielma authored and mlubin committed Sep 21, 2018
1 parent 8cf4a24 commit d80fa11
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 106 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
Expand Up @@ -4,15 +4,9 @@ os:
- osx
julia:
- 0.6
- nightly
matrix:
allow_failures:
- julia: nightly
- 0.7
- 1.0
notifications:
email: false
sudo: false
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("SCS"); Pkg.test("SCS"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("SCS")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
22 changes: 18 additions & 4 deletions README.md
Expand Up @@ -19,10 +19,24 @@ You can install SCS.jl through the Julia package manager:
julia> Pkg.add("SCS")
```

SCS.jl will automatically setup the SCS solver itself:
- On Linux it will build from source
- On OS X it will download a binary via [Homebrew.jl].
- On Windows it will download a binary.
SCS.jl will use [BinaryProvider.jl](https://github.com/JuliaPackaging/BinaryProvider.jl) to automatically install the SCS binaries. Note that if you are not using the official Julia binaries from `https://julialang.org/downloads/` you may need a custom install of the SCS binaries.

## Custom Installation

To install custom built SCS binaries set the environmental variable `JULIA_SCS_LIBRARY_PATH` and call `Pkg.build("SCS")`. For instance, if the libraries are installed in `/opt/lib` just call
```julia
ENV["JULIA_SCS_LIBRARY_PATH"]="/opt/lib"
Pkg.build("SCS")
```
Note that your custom build binaries need to be compiled with the option `DLONG=1`. For instance, a minimal compilation script would be
```bash
make DLONG=1
```
on SCS's source directory.

If you do not want BinaryProvider to download the default binaries on install set `JULIA_SCS_LIBRARY_PATH` before calling `Pkg.add("SCS")`.

To switch back to the default binaries clear `JULIA_SCS_LIBRARY_PATH` and call `Pkg.build("SCS")`.

## Usage

Expand Down
7 changes: 3 additions & 4 deletions REQUIRE
@@ -1,6 +1,5 @@
julia 0.6
julia 0.6.2
MathProgBase 0.5 0.8
MathOptInterface 0.6 0.7
BinDeps
@osx Homebrew
Compat 0.47 # SparseArrays
BinaryProvider 0.3
Compat 0.47
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- julia_version: 0.6
- julia_version: 0.7
- julia_version: 1.0

platform:
- x86 # 32-bit
Expand Down
6 changes: 1 addition & 5 deletions deps/.gitignore
@@ -1,6 +1,2 @@
deps.jl
downloads/
src/
usr/
bin32/
bin64/
usr
128 changes: 50 additions & 78 deletions deps/build.jl
@@ -1,83 +1,55 @@
using BinDeps

@BinDeps.setup

using Compat.Libdl
using Compat.LinearAlgebra.BLAS
using Compat.Sys: isapple

blasvendor = BLAS.vendor()

direct = library_dependency("libscsdir", aliases=["libscsdir64"])
indirect = library_dependency("libscsindir", aliases=["libscsindir64"])

# TODO: Provide both libs in the "scs" Homebrew package.
# if Sys.isapple()
# using Homebrew
# provides(Homebrew.HB, "scs", [direct, indirect], os = :Darwin)
# end

version = "2.0.2"
win_version = "2.0.2" # The windows binaries are not consistent with this version yet.

provides(Sources, URI("https://github.com/cvxgrp/scs/archive/v$version.tar.gz"),
[direct, indirect], os=:Unix, unpacked_dir="scs-$version")

# Windows binaries built in Cygwin as follows:
# CFLAGS="-DDLONG -DCOPYAMATRIX -DUSE_LAPACK -DCTRLC=1 -DBLAS64 -DBLASSUFFIX=_64_" LDFLAGS="-L$HOME/julia/usr/bin -lopenblas64_" make CC=x86_64-w64-mingw32-gcc out/libscsdir.dll
# mv out bin64
# make clean
# CFLAGS="-DDLONG -DCOPYAMATRIX -DUSE_LAPACK -DCTRLC=1" LDFLAGS="-L$HOME/julia32/usr/bin -lopenblas" make CC=i686-w64-mingw32-gcc out/libscsdir.dll
# mv out bin32

# TODO: Provide binaries for windows
# provides(Binaries, URI("https://cache.julialang.org/https://bintray.com/artifact/download/tkelman/generic/scs-$win_version-r2.7z"),
# [direct, indirect], unpacked_dir="bin$(Sys.WORD_SIZE)", os = :Windows,
# SHA="62bb4feeb7d2cd3db595f05b86a20fc93cfdef23311e2e898e18168189072d02")

prefix = joinpath(BinDeps.depsdir(direct), "usr")
srcdir = joinpath(BinDeps.depsdir(direct), "src", "scs-$version/")

ldflags = ""
if isapple()
ldflags = "$ldflags -undefined suppress -flat_namespace"
end
cflags = "-DCOPYAMATRIX -DDLONG -DUSE_LAPACK -DCTRLC=1"
if blasvendor == :openblas64
cflags = "$cflags -DBLAS64 -DBLASSUFFIX=_64_"
end
if blasvendor == :mkl
if Base.USE_BLAS64
cflags = "$cflags -DMKL_ILP64 -DBLAS64"
ldflags = "$ldflags -lmkl_intel_ilp64"
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, ["libscsindir"], :indirect),
LibraryProduct(prefix, ["libscsdir"], :direct),
]

# Download binaries from hosted location
bin_prefix = "https://github.com/JuliaOpt/SCSBuilder/releases/download/v2.0.2-NOGOMP"

# Listing of files generated by BinaryBuilder:
download_info = Dict(
Linux(:aarch64, :glibc) => ("$bin_prefix/SCSBuilder.v2.0.2.aarch64-linux-gnu.tar.gz", "9ac63df8629d95588d84f0c8219d7c15cb229eab8fb78d528a4e75fbd2f5c136"),
Linux(:armv7l, :glibc, :eabihf) => ("$bin_prefix/SCSBuilder.v2.0.2.arm-linux-gnueabihf.tar.gz", "1c1241faa174ff47c2c290793b6fec1a9f0db290fda57c7826f9b8942b41943b"),
Linux(:i686, :glibc) => ("$bin_prefix/SCSBuilder.v2.0.2.i686-linux-gnu.tar.gz", "7731d8a2e644bf1e070e013eb100d66e49f17796b8903c3350a806946f7ba752"),
Windows(:i686) => ("$bin_prefix/SCSBuilder.v2.0.2.i686-w64-mingw32.tar.gz", "354cce228b102e9a09a727d44c1f437ad49e97077ba4abff96b22d6d129c751f"),
Linux(:powerpc64le, :glibc) => ("$bin_prefix/SCSBuilder.v2.0.2.powerpc64le-linux-gnu.tar.gz", "7a2847ad3f8621a6927e4281d8ee7f2704a3339cfed41eb1b227a997a59cadf5"),
MacOS(:x86_64) => ("$bin_prefix/SCSBuilder.v2.0.2.x86_64-apple-darwin14.tar.gz", "dc7f0d7bb3f2ee0072cb81653729ac2f5123abfa0735898cd44bc39a2952d248"),
Linux(:x86_64, :glibc) => ("$bin_prefix/SCSBuilder.v2.0.2.x86_64-linux-gnu.tar.gz", "d5503f18e7d504e4a496ae4ea79ef326fab78983cf42ebd2a691e0a682790d96"),
FreeBSD(:x86_64) => ("$bin_prefix/SCSBuilder.v2.0.2.x86_64-unknown-freebsd11.1.tar.gz", "3ef5005d53ca7dee21842856ca5628e0efc244083e125e939304a14092d54858"),
Windows(:x86_64) => ("$bin_prefix/SCSBuilder.v2.0.2.x86_64-w64-mingw32.tar.gz", "289504d5df960c3434e5877f16cc42949e32280eb0ec684020bf6f9336c9316f"),
)

custom_library = false
if haskey(ENV,"JULIA_SCS_LIBRARY_PATH")
custom_products = [LibraryProduct(ENV["JULIA_SCS_LIBRARY_PATH"],product.libnames,product.variable_name) for product in products]
if all(satisfied(p; verbose=verbose) for p in custom_products)
products = custom_products
custom_library = true
else
ldflags = "$ldflags -lmkl_intel"
error("Could not install custom libraries from $(ENV["JULIA_SCS_LIBRARY_PATH"]).\nTo fall back to BinaryProvider call delete!(ENV,\"JULIA_SCS_LIBRARY_PATH\") and run build again.")
end
cflags = "$cflags -fopenmp"
ldflags = "$ldflags -lmkl_gnu_thread -lmkl_rt -lmkl_core -lgomp"
end

ENV2 = copy(ENV)
ENV2["LDFLAGS"] = ldflags
ENV2["CFLAGS"] = cflags

provides(SimpleBuild,
(@build_steps begin
GetSources(direct)
CreateDirectory(joinpath(prefix, "lib"))

FileRule(joinpath(prefix, "lib", "libscsdir.$(Libdl.dlext)"), @build_steps begin
ChangeDirectory(srcdir)
setenv(`make BLASLDFLAGS= out/libscsdir.$(Libdl.dlext)`, ENV2)
`mv out/libscsdir.$(Libdl.dlext) $prefix/lib`
end)

FileRule(joinpath(prefix, "lib", "libscsindir.$(Libdl.dlext)"), @build_steps begin
ChangeDirectory(srcdir)
setenv(`make BLASLDFLAGS= out/libscsindir.$(Libdl.dlext)`, ENV2)
`mv out/libscsindir.$(Libdl.dlext) $prefix/lib`
end)

end), [direct, indirect], os=:Unix)
# Install unsatisfied or updated dependencies:
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
if !custom_library && haskey(download_info, platform_key())
url, tarball_hash = download_info[platform_key()]
if unsatisfied || !isinstalled(url, tarball_hash; prefix=prefix)
# Download and install binaries
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
end
elseif unsatisfied
# If we don't have a BinaryProvider-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 $(triplet(platform_key())) is not supported by this package!")
end

@BinDeps.install Dict(:libscsdir => :direct, :libscsindir => :indirect)
# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products, verbose=verbose)
14 changes: 7 additions & 7 deletions src/SCS.jl
Expand Up @@ -2,25 +2,25 @@ __precompile__()

module SCS

# To make Pkg aware that this dependency
# will be injected by BinaryProvider.
if VERSION > v"0.7.0-"
using Libdl
end

if isfile(joinpath(dirname(@__FILE__), "..", "deps", "deps.jl"))
include("../deps/deps.jl")
else
error("SCS not properly installed. Please run Pkg.build(\"SCS\") and restart julia")
end

using Compat
using Compat.Libdl
using Compat.Sys: isunix

function __init__()
vnum = VersionNumber(SCS_version())
# default binaries need access to Julia's lapack symbols
if isunix()
dlopen(Base.liblapack_name, RTLD_LAZY|RTLD_DEEPBIND|RTLD_GLOBAL)
end
depsdir = realpath(joinpath(dirname(@__FILE__),"..","deps"))
if vnum.major == 1
error("Current SCS version installed is $(SCS_version()), but we require version 2.*. On Linux and Windows, delete the contents of the `$depsdir` directory except for the files `build.jl` and `.gitignore`, then rerun Pkg.build(\"SCS\"). On OS X, run `using Homebrew; Homebrew.update()` in Julia.")
error("Current SCS version installed is $(SCS_version()), but we require version 2.*.")
end
end

Expand Down

0 comments on commit d80fa11

Please sign in to comment.