Skip to content

Commit

Permalink
change build system to bazel (#78)
Browse files Browse the repository at this point in the history
* change build system to bazel

Using bazel allows for using travis-docker infrastructure without
sudo privileges.

* adapt README file for the new changes

* remove sudo
  • Loading branch information
PatWie authored Mar 1, 2017
1 parent da314c6 commit d231eac
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 731 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,21 @@ CppNumericalSolvers.config
*.mexw32
*.mexmaci64
*.mexglx

# Ignore backup files.
*~
# Ignore Vim swap files.
.*.swp
# Ignore files generated by IDEs.
/.classpath
/.factorypath
/.idea/
/.project
/.settings
/WORKSPACE.user.bzl
/bazel.iml
# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
/bazel-*
# Ignore outputs generated during Bazel bootstrapping.
/output/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

78 changes: 24 additions & 54 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,35 @@
sudo: required
dist: precise
language: cpp
dist: trusty

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- wget
- pkg-config
- g++
- g++-4.9
- g++-5
- pkg-config
- zip
- zlib1g-dev
- unzip

matrix:
include:
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
env: COMPILER=g++-4.9
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
env: COMPILER=g++-5

before_install:
- sudo apt-get update -qq
- chmod u+x get_dependencies.sh
- ./get_dependencies.sh
- git submodule update --init --recursive
- wget https://github.com/bazelbuild/bazel/releases/download/0.4.4/bazel-0.4.4-installer-linux-x86_64.sh
- wget https://github.com/bazelbuild/bazel/releases/download/0.4.4/bazel-0.4.4-installer-linux-x86_64.sh.sha256
- sha256sum -c bazel-0.4.4-installer-linux-x86_64.sh.sha256
- chmod +x bazel-0.4.4-installer-linux-x86_64.sh
- ./bazel-0.4.4-installer-linux-x86_64.sh --user
- export PATH="$PATH:$HOME/bin"

install:
############################################################################
# Install a recent CMake
############################################################################
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
CMAKE_DIR="install_cmake"
CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz"
mkdir $CMAKE_DIR && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C $CMAKE_DIR
export PATH=${TRAVIS_BUILD_DIR}/${CMAKE_DIR}/bin:${PATH}
else
brew install cmake
fi

script:
- mkdir build
- cd build
- cmake -DEIGEN3_INCLUDE_DIR=eigen -DCMAKE_CXX_COMPILER=$COMPILER -DCMAKE_BUILD_TYPE=Release ..
- make all -j
- make lint
- ./bin/verify
- bazel run verify
- python lint.py

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8

notifications:
email: false

branches:
except:
-gtest
21 changes: 21 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])

load("//:generator.bzl", "build_example", "build_test")

build_example("linearregression")
build_example("logisticregression")
build_example("rosenbrock")
build_example("rosenbrock_float")
build_example("simple")
build_example("simple_withoptions")
build_example("neldermead")
build_example("neldermead-customized")

build_test("verify")


py_binary(
name = "lint",
args = ["src/test/verify.cpp"],
srcs = ["lint.py"],
)
68 changes: 0 additions & 68 deletions CMakeLists.txt

This file was deleted.

39 changes: 9 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ CppOptimizationLibrary
Get this Library
-----------

git clone --recursive https://github.com/PatWie/CppNumericalSolvers.git

or a complete copy and paste version
````bash
git clone --recursive https://github.com/PatWie/CppNumericalSolvers.git
git clone https://github.com/PatWie/CppNumericalSolvers.git
cd CppNumericalSolvers/
./get_dependencies.sh
mkdir build
cd build
cmake ..
make all
./bin/verify
bazel run verify
````

About
-----------
Have you ever googled for a c++ version of *fminsearch*, which is easy to use without adding tons of dependencies and without editing many setting-structs? This project exactly addresses this issue by providing a *header-only* library without dependencies. All solvers are written from scratch, which means they do not represent the current state-of-the-art implementation with all tricky optimizations (at least for now). But they are very easy to use. Want a full example?
Have you ever looked for a c++ version of MATLAB's *fminsearch*, which is easy to use without adding tons of dependencies and without editing many setting-structs? This project exactly addresses this issue by providing a *header-only* library without dependencies. All solvers are written from scratch, which means they do not represent the current state-of-the-art implementation with all tricky optimizations (at least for now). But they are very easy to use. Want a full example?

````cpp
class Rosenbrock : public Problem<double> {
Expand Down Expand Up @@ -62,24 +55,9 @@ For checking your gradient this library uses high-order central difference. Stud
Install
-----------
Before compiling you need to adjust one path to the [Eigen3][eigen3]-Library (header only), which can by downloaded by a single bashscript, if you haven't Eigen already.
````bash
# download Eigen
./get_dependencies.sh
````
To compile the examples and the unit test just do
````bash
# create a new directory
mkdir build && cd build
cmake ..
# build tests and demo
make all
# run all tests
./bin/verify
# run an example
./bin/examples/linearregression
````
For using the MATLAB-binding open Matlab and run `make.m` inside the MATLAB folder once.
Note, this library is header-only, so you just need to add `include/cppoptlib` to your project without compiling anything and without adding further dependencies. We ship some examples for demonstration purposes and use [bazel](https://bazel.build/) to compile these examples and unittests. The latest commit using CMake is da314c6581d076e0dbadacdd263aefe4d06a2397.
When using the MATLAB-binding, you need to compile the mex-file. Hereby, open Matlab and run `make.m` inside the MATLAB folder once.
Extensive Introduction
-----------
Expand Down Expand Up @@ -192,7 +170,8 @@ Currently, not all solvers are equally good at all objective functions. The file

# Contribute

Make sure that `make lint` does not display any errors and check if travis is happy. Do not forget to `chmod +x lint.py`. It would be great, if some of the Forks-Owner are willing to make pull-request.
Make sure that `python lint.py` does not display any errors and check if travis is happy. It would be great, if some of the Forks-Owner are willing to make pull-request.

[eigen3]: http://eigen.tuxfamily.org/
[bazel]: https://bazel.build/
[matlab]: http://www.mathworks.de/products/matlab/
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
new_http_archive(
name = "eigen_archive",
url = "https://bitbucket.org/eigen/eigen/get/3.2.10.tar.gz",
build_file = "eigen.BUILD",
strip_prefix = "eigen-eigen-b9cd8366d4e8",
)


new_http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.7.0.zip",
sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
build_file = "gtest.BUILD",
strip_prefix = "googletest-release-1.7.0",
)
19 changes: 19 additions & 0 deletions bazel.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is from Bazel's former travis setup, to avoid blowing up the RAM usage.
startup --host_jvm_args=-Xmx2500m
startup --host_jvm_args=-Xms2500m
startup --batch
test --ram_utilization_factor=10

# This is so we understand failures better
build --verbose_failures

# This is so we don't use sandboxed execution. Sandboxed execution
# runs stuff in a container, and since Travis already runs its script
# in a container (unless you require sudo in your .travis.yml) this
# fails to run tests.
build --spawn_strategy=standalone --genrule_strategy=standalone
test --test_strategy=standalone

# Below this line, .travis.yml will cat the default bazelrc.
# This is needed so Bazel starts with the base workspace in its
# package path.
83 changes: 0 additions & 83 deletions cmake/Modules/FindEigen3.cmake

This file was deleted.

Loading

0 comments on commit d231eac

Please sign in to comment.