Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to manually build Cuba #22

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ task:
env:
matrix:
- JULIA_VERSION: 1.0
env: JULIA_CUBA_BUILD_SOURCE=false
- JULIA_VERSION: 1.0
env: JULIA_CUBA_BUILD_SOURCE=true
- JULIA_VERSION: 1.1
env: JULIA_CUBA_BUILD_SOURCE=false
- JULIA_VERSION: 1.1
env: JULIA_CUBA_BUILD_SOURCE=true
- JULIA_VERSION: nightly
env: JULIA_CUBA_BUILD_SOURCE=false
- JULIA_VERSION: nightly
env: JULIA_CUBA_BUILD_SOURCE=true
install_script:
- sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)"
build_script:
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ julia:
- 1.0
- 1.1
- nightly
env:
matrix:
- JULIA_CUBA_BUILD_SOURCE=true
- JULIA_CUBA_BUILD_SOURCE=false
notifications:
email: false
git:
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
History of Cuba.jl
==================

v2.1.0 (2019-0?-??)
-------------------

### New Features

* You can now build the Cuba library locally, instead of using a pre-built
package, by setting the `JULIA_CUBA_BUILD_SOURCE` environment variable to
`"true"`.

v2.0.0 (2019-02-27)
-------------------

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ pkg> update
pkg> add Cuba
```

By default, on all systems a pre-built version of the Cuba library will be
installed. On UNIX systems, you can optionally compile Cuba locally by setting
the `JULIA_CUBA_BUILD_SOURCE` environment variable to `"true"`:

```julia
julia> ENV["JULIA_CUBA_BUILD_SOURCE"] = "true"
"true"

pkg> build Cuba
```

Older versions are also available for Julia 0.4-0.7.

Usage
Expand Down
31 changes: 18 additions & 13 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using BinaryProvider # requires BinaryProvider 0.3.0 or later

const forcecompile = get(ENV, "JULIA_CUBA_BUILD_SOURCE", "false") == "true"

# 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")))
Expand Down Expand Up @@ -29,18 +31,21 @@ download_info = Dict(

# Install unsatisfied or updated dependencies:
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
if 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)
if forcecompile
include("build_from_source.jl")
else
if 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_abi())) is not supported by this package!")
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!")
# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
end

# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
66 changes: 66 additions & 0 deletions deps/build_from_source.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
### build.jl --- Build script for Cuba.jl.

# Copyright (C) 2016-2019 Mosè Giordano

# Maintainer: Mosè Giordano <mose AT gnu DOT org>

# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

### Code:

using Libdl, BinaryProvider

tagfile = "installed_version"

@static if Sys.isunix()
# SHA hash of the revision to be downloaded from
# https://github.com/giordano/cuba/tree/julia
sha="11bfbf509088f168622b8268f49c0a59ee81758b"
if !isfile(tagfile) || readchomp(tagfile) != sha
local_dir = "cuba-$(sha)"
local_file = "$(local_dir).tar.gz"
if Sys.isapple()
object="libcuba.dylib"
else
object="libcuba.so"
end

# Clean already existing tag file, shared object, and build directory in
# order to perform a new clean build. Leave the archive, to avoid
# downloading it again.
run(`rm -rf $tagfile $object $local_dir`)

if !isfile(local_file)
@info("Downloading Cuba source...")
download("https://github.com/giordano/cuba/archive/$(sha).tar.gz",
local_file)
end
run(`tar xzf $local_file`)
@info("Building libcuba...")
cd(local_dir) do
run(`./configure`)
run(`make shared`)
run(`mv $object ..`)
end
open(tagfile, "w") do file
println(file, sha)
end
end
else
error("Cannot build CUBA from source for your platform $(triplet(platform_key_abi())).
Try setting ENV[\"JULIA_CUBA_BUILD_SOURCE\"]=\"false\" and building again the package")
end

products = [LibraryProduct(@__DIR__, String["libcuba"], :libcuba)]
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
11 changes: 11 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ pkg> update
pkg> add Cuba
```

By default, on all systems a pre-built version of the Cuba library will be
installed. On UNIX systems, you can optionally compile Cuba locally by setting
the `JULIA_CUBA_BUILD_SOURCE` environment variable to `"true"`:

```julia
julia> ENV["JULIA_CUBA_BUILD_SOURCE"] = "true"
"true"

pkg> build Cuba
```

Older versions are also available for Julia 0.4-0.7.

Usage
Expand Down
1 change: 1 addition & 0 deletions src/Cuba.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ integrand_ptr_nvec(integrand::T) where {T} = @cfunction(generic_integrand!, Cint
abstract type Integrand{T} end

function __init__()
check_deps()
Cuba.cores(0, 10000)
end

Expand Down
6 changes: 3 additions & 3 deletions test/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### benchmark.jl --- Benchmark Cuba.jl and Cuba C Library

# Copyright (C) 2016 Mosè Giordano
# Copyright (C) 2016-2019 Mosè Giordano

# Maintainer: Mosè Giordano <mose AT gnu DOT org>
# Keywords: numeric integration
Expand Down Expand Up @@ -72,14 +72,14 @@ end

cd(dirname(@__FILE__)) do
if mtime("benchmark.c") > mtime("benchmark-c")
run(`gcc -O3 -I ../deps/usr/include -o benchmark-c benchmark.c ../deps/usr/lib/libcuba.a -lm`)
run(`gcc -O3 -I ../deps/usr/include -o benchmark-c benchmark.c $(Cuba.libcuba) -lm`)
end
@info "Performance of Cuba Library in C:"
run(`./benchmark-c`)

if success(`which gfortran`)
if mtime("benchmark.f") > mtime("benchmark-fortran")
run(`gfortran -O3 -fcheck=no-bounds -cpp -o benchmark-fortran benchmark.f ../deps/usr/lib/libcuba.a -lm`)
run(`gfortran -O3 -fcheck=no-bounds -cpp -o benchmark-fortran benchmark.f $(Cuba.libcuba) -lm`)
end
@info "Performance of Cuba Library in Fortran:"
run(`./benchmark-fortran`)
Expand Down