-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4905 from david-german-tri/static_ipopt
Add IPOPT to the Bazel build
- Loading branch information
Showing
8 changed files
with
323 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- python -*- | ||
# This file contains rules for Bazel; see drake/doc/bazel.rst. | ||
|
||
load("//tools:cpplint.bzl", "cpplint") | ||
load("//tools:drake.bzl", "cc_googletest") | ||
|
||
cc_library( | ||
name = "pendulum_state_vector", | ||
srcs = ["gen/pendulum_state_vector.cc"], | ||
hdrs = ["gen/pendulum_state_vector.h"], | ||
linkstatic = 1, | ||
deps = [ | ||
"//drake/systems/framework:vector", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "pendulum_plant", | ||
srcs = ["pendulum_plant.cc"], | ||
hdrs = ["pendulum_plant.h"], | ||
deps = [ | ||
":pendulum_state_vector", | ||
"//drake/systems/framework", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "pendulum_swing_up", | ||
srcs = ["pendulum_swing_up.cc"], | ||
hdrs = ["pendulum_swing_up.h"], | ||
deps = [ | ||
":pendulum_plant", | ||
"//drake/systems/trajectory_optimization:direct_collocation", | ||
], | ||
) | ||
|
||
# === test/ === | ||
|
||
cc_googletest( | ||
name = "pendulum_urdf_dynamics_test", | ||
data = ["Pendulum.urdf"], | ||
deps = [ | ||
":pendulum_plant", | ||
"//drake/common:eigen_matrix_compare", | ||
"//drake/multibody:rigid_body_tree", | ||
"//drake/multibody/parsers", | ||
"//drake/multibody/rigid_body_plant", | ||
], | ||
) | ||
|
||
cc_googletest( | ||
name = "pendulum_dynamic_constraint_test", | ||
deps = [ | ||
":pendulum_plant", | ||
"//drake/common:eigen_matrix_compare", | ||
"//drake/systems/trajectory_optimization:direct_collocation", | ||
], | ||
) | ||
|
||
cc_googletest( | ||
name = "pendulum_trajectory_optimization_test", | ||
deps = [ | ||
":pendulum_swing_up", | ||
"//drake/common:eigen_matrix_compare", | ||
], | ||
) | ||
|
||
cpplint() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# We build IPOPT by shelling out to autotools. | ||
|
||
# A prefix-string for genrule cmd attributes, which uses the Kythe cdexec tool, | ||
# in quiet mode, to execute in the genrule output directory. | ||
CDEXEC = "$(location @//tools/third_party/kythe/tools/cdexec:cdexec) -q $(@D)" | ||
|
||
# We run autotools in a genrule, and only files explicitly identified as outputs | ||
# of that genrule can be made available to other rules. Therefore, we need a | ||
# list of every file in the IPOPT install. | ||
# See https://github.com/bazelbuild/bazel/issues/281. | ||
|
||
# find include/coin -name "*.h" -o -name "*.hpp" -o -name "*.hdd" | sort | | ||
# sed 's/$/",/g'| sed 's/^/"/g' | ||
IPOPT_HDRS = [ | ||
"include/coin/AmplTNLP.hpp", | ||
"include/coin/HSLLoader.h", | ||
"include/coin/IpAlgTypes.hpp", | ||
"include/coin/IpBlas.hpp", | ||
"include/coin/IpCachedResults.hpp", | ||
"include/coin/IpCompoundVector.hpp", | ||
"include/coin/IpDebug.hpp", | ||
"include/coin/IpDenseVector.hpp", | ||
"include/coin/IpException.hpp", | ||
"include/coin/IpExpansionMatrix.hpp", | ||
"include/coin/IpIpoptApplication.hpp", | ||
"include/coin/IpIpoptCalculatedQuantities.hpp", | ||
"include/coin/IpIpoptData.hpp", | ||
"include/coin/IpIpoptNLP.hpp", | ||
"include/coin/IpIteratesVector.hpp", | ||
"include/coin/IpJournalist.hpp", | ||
"include/coin/IpLapack.hpp", | ||
"include/coin/IpMatrix.hpp", | ||
"include/coin/IpNLP.hpp", | ||
"include/coin/IpNLPScaling.hpp", | ||
"include/coin/IpObserver.hpp", | ||
"include/coin/IpoptConfig.h", | ||
"include/coin/IpOptionsList.hpp", | ||
"include/coin/IpOrigIpoptNLP.hpp", | ||
"include/coin/IpReferenced.hpp", | ||
"include/coin/IpRegOptions.hpp", | ||
"include/coin/IpReturnCodes.h", | ||
"include/coin/IpReturnCodes.hpp", | ||
"include/coin/IpReturnCodes_inc.h", | ||
"include/coin/IpSmartPtr.hpp", | ||
"include/coin/IpSolveStatistics.hpp", | ||
"include/coin/IpStdCInterface.h", | ||
"include/coin/IpSymMatrix.hpp", | ||
"include/coin/IpTaggedObject.hpp", | ||
"include/coin/IpTimedTask.hpp", | ||
"include/coin/IpTimingStatistics.hpp", | ||
"include/coin/IpTNLPAdapter.hpp", | ||
"include/coin/IpTNLP.hpp", | ||
"include/coin/IpTNLPReducer.hpp", | ||
"include/coin/IpTypes.hpp", | ||
"include/coin/IpUtils.hpp", | ||
"include/coin/IpVector.hpp", | ||
"include/coin/PardisoLoader.h", | ||
"include/coin/ThirdParty/arith.h", | ||
"include/coin/ThirdParty/asl.h", | ||
"include/coin/ThirdParty/asl_pfg.h", | ||
"include/coin/ThirdParty/asl_pfgh.h", | ||
"include/coin/ThirdParty/defs.h", | ||
"include/coin/ThirdParty/dmumps_c.h", | ||
"include/coin/ThirdParty/funcadd.h", | ||
"include/coin/ThirdParty/getstub.h", | ||
"include/coin/ThirdParty/macros.h", | ||
"include/coin/ThirdParty/metis.h", | ||
"include/coin/ThirdParty/mpi.h", | ||
"include/coin/ThirdParty/mumps_compat.h", | ||
"include/coin/ThirdParty/mumps_c_types.h", | ||
"include/coin/ThirdParty/nlp2.h", | ||
"include/coin/ThirdParty/nlp.h", | ||
"include/coin/ThirdParty/proto.h", | ||
"include/coin/ThirdParty/psinfo.h", | ||
"include/coin/ThirdParty/rename.h", | ||
"include/coin/ThirdParty/stdio1.h", | ||
"include/coin/ThirdParty/struct.h", | ||
] | ||
|
||
# ls lib | grep "\.a$" | sed 's/$/",/g'| sed 's/^/"lib\//g' | ||
# These are artisanally topo-sorted: demand before supply. | ||
# If you change the order, you may get undefined-reference linker errors. | ||
IPOPT_LIBS = [ | ||
"lib/libipopt.a", | ||
"lib/libipoptamplinterface.a", | ||
"lib/libcoinmumps.a", | ||
# TODO(#4913): Remove the dependency on METIS. | ||
"lib/libcoinmetis.a", | ||
"lib/libcoinasl.a", | ||
"lib/libcoinlapack.a", | ||
"lib/libcoinblas.a", | ||
] | ||
|
||
# Invokes ./configure, make, and make install to build IPOPT. We arbitrarily | ||
# use make -j 8 and hope for the best in terms of overall CPU consumption, since | ||
# Bazel has no way to tell a genrule how many cores it should use. | ||
# | ||
# We emit static libraries because dynamic libraries would have different names | ||
# on OS X and on Linux, and Bazel genrules don't allow platform-dependent outs. | ||
# https://github.com/bazelbuild/bazel/issues/281 | ||
BUILD_IPOPT_CMD = ( | ||
CDEXEC + " `pwd`/external/ipopt/configure --enable-shared=no 2> /dev/null" + | ||
" && " + CDEXEC + " make -j 32 2> /dev/null" + | ||
" && " + CDEXEC + " make install 2> /dev/null" | ||
) | ||
|
||
genrule( | ||
name = "build_with_autotools", | ||
srcs = glob(["**/*"]), | ||
outs = IPOPT_HDRS + IPOPT_LIBS, | ||
cmd = BUILD_IPOPT_CMD, | ||
tools = ["@//tools/third_party/kythe/tools/cdexec:cdexec"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
# Only Linux builds should depend on this target. gfortran is not available as | ||
# a system library on OS X. | ||
# TODO(david-german-tri): Ingest the fortran library path from the pkg-config | ||
# files generated during the IPOPT build. | ||
cc_library( | ||
name = "lib", | ||
srcs = IPOPT_LIBS, | ||
hdrs = IPOPT_HDRS, | ||
includes = ["include/coin"], | ||
linkopts = [ | ||
"-lgfortran", | ||
"-ldl", | ||
], | ||
linkstatic = 1, | ||
visibility = ["//visibility:public"], | ||
alwayslink = 1, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
exports_files(["cdexec.bzl"]) | ||
|
||
sh_binary( | ||
name = "cdexec", | ||
srcs = ["cdexec.sh"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Skylark module with utilities and macros for running actions with cdexec.""" | ||
|
||
def rootpath(path): | ||
"""Returns a string which cdexec will interpret as absolute. | ||
Specifically, if the path starts with '/', it is returned unmodified. | ||
Otherwise, the returns the path prefixed by the literal string '${PWD}/' | ||
which will be expanded by the `cdexec` script into the Bazel exec root. | ||
""" | ||
if path.startswith("/"): | ||
return path | ||
return "${PWD}/" + path |
Oops, something went wrong.