Skip to content

Commit

Permalink
Fix Bazel build and update instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrail committed Apr 15, 2020
1 parent 1041736 commit dbc9dac
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# apib: API Bench

This is a tool that makes it easy to run performance tests of HTTP API servers. It is built
using [Bazel](https://www.bazel.build/) and can be built on most Linux platforms, plus Mac OS X and FreeBSD.
This is a tool that makes it easy to run performance tests of HTTP API servers. It
can be built on most Linux platforms, plus Mac OS X and FreeBSD.

## Status

Expand All @@ -10,7 +10,7 @@ or pull requests if you find that you'd like it to do more within reason!

## Current Version

1.0.
1.2.1.

## Usage

Expand Down
8 changes: 0 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ http_archive(
urls = ["http://dist.schmorp.de/libev/Attic/libev-4.33.tar.gz"],
)

http_archive(
name = "httpparser",
build_file = "@//:httpparser.build",
sha256 = "467b9e30fd0979ee301065e70f637d525c28193449e1b13fbcb1b1fab3ad224f",
strip_prefix = "http-parser-2.9.4",
urls = ["https://github.com/nodejs/http-parser/archive/v2.9.4.tar.gz"],
)

# Take a commit from the "build-with-bazel" branch
git_repository(
name = "boringssl",
Expand Down
8 changes: 4 additions & 4 deletions apib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ cc_library(
"-lm",
],
deps = [
"//third_party/http_parser",
"@absl//absl/strings",
"@httpparser",
],
)

Expand Down Expand Up @@ -78,12 +78,12 @@ cc_library(
],
deps = [
":common",
"//third_party:base64",
"//third_party/base64",
"//third_party/http_parser",
"//third_party/libev",
"@absl//absl/strings:str_format",
"@boringssl//:crypto",
"@boringssl//:ssl",
"@httpparser",
],
)

Expand Down Expand Up @@ -112,7 +112,7 @@ cc_binary(
],
deps = [
":io",
"//third_party:base64",
"//third_party/base64",
],
)

Expand Down
20 changes: 10 additions & 10 deletions apib/apib_iothread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,31 +428,31 @@ std::string IOThread::GetEvBackends(int b) {
if (b & EVBACKEND_POLL) {
formats.push_back("poll");
}
#ifdef EVBACKEND_EPOLL
#ifdef EVBACKEND_EPOLL
if (b & EVBACKEND_EPOLL) {
formats.push_back("epoll");
}
#endif
#ifdef EVBACKEND_LINUXAIO
#endif
#ifdef EVBACKEND_LINUXAIO
if (b & EVBACKEND_LINUXAIO) {
formats.push_back("linux AIO");
}
#endif
#ifdef EVBACKEND_KQUEUE
#endif
#ifdef EVBACKEND_KQUEUE
if (b & EVBACKEND_KQUEUE) {
formats.push_back("kqueue");
}
#endif
#ifdef EVBACKEND_DEVPOLL
#endif
#ifdef EVBACKEND_DEVPOLL
if (b & EVBACKEND_DEVPOLL) {
formats.push_back("/dev/poll");
}
#endif
#ifdef EVBACKEND_PORT
#endif
#ifdef EVBACKEND_PORT
if (b & EVBACKEND_PORT) {
formats.push_back("Solaris event port");
}
#endif
#endif
return absl::StrJoin(formats, ", ");
}

Expand Down
97 changes: 91 additions & 6 deletions doc/BUILDING.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# How to Build apib

Sample build instructions for CentOS:
apib can be built in two ways:

1. Using Bazel, which takes care of fetching and building all the dependencies
2. Using cmake, which uses system-provided libraries for some things

If you just want to build and run locally, then Bazel, once installed,
makes the process quick.

Otherwise, cmake builds fewer things. Cmake is what we use to build
for Homebrew and someday for other repositories.

## Building using Bazel

In short, this will build the main executable:

1. Get the source using git
2. [Install Bazel](https://docs.bazel.build/versions/0.29.0/install.html)
3. make
3. bazel build -c opt //apib //apib:apibmon
4. The binaries will be in ./bazel-bin/apib/apib and ./bazel-bin/apib/apibmon

This will work on most Linux platforms. We have also tested it on Mac OS X
and FreeBSD. It also runs on Windows 10 using the "Windows Subsystem for Linux."
We have not tried to build it on native Windows.

## Details
### Details

apib builds using [Bazel](https://www.bazel.build/). This gives us a consistent build
environment on many platforms. Bazel also
Expand All @@ -25,7 +39,7 @@ page for installation instructions. Specifically:
version is available without doing further work to build the port for
a more recent version.)

## Dependencies
### Dependencies

As part of the build, Bazel fetches the third-party code that apib needs.
So, once Bazel is installed you don't need anything else in order to build.
Expand All @@ -36,9 +50,80 @@ I/O and scheduling on all our platforms.
* [BoringSSL](https://boringssl.googlesource.com/boringssl/) Google's port of TLS
that is consistent and easy to build with Bazel
* A Base64 encoder from the Apache project, found in "third_party".
* The "Node.js HTTP parser," also in third_party.

## Testing
### Testing

make test
bazel test ...

will use Bazel run the tests.

## Building using CMake

The CMake build uses the versions of libev and openssl found
on the system. That means they need to be installed before
apib can be built. Specifically:

* OpenSSL 1.1 or higher must be installed
* libev's headers and libraries must be installed

Once installed, the Cmake build is pretty simple:

1. mkdir release
2. cd release
3. cmake .. -DCMAKE_BUILD_TYPE=Release
4. make apib apibmon

Hint: If you are impatient, try installing "ninja".
Then replace the last two commands:

* cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
* ninja apib apibmon

### Finding Dependencies

If that didn't work, then depending on the platform,
you may need to set any of four variables:

* EXTRA_INCLUDE_DIR: An additional path to find include directories
* EXTRA_LIB_DIR: Same for libraries
* OPENSSL_INCLUDE_DIR: An additional extra directory that will go before the rest
* OPENSSL_LIB_DIR: Same for libraries

For example, on my Mac Homebrew is installed in /opt/homebrew, and
furthermore OpenSSL 1.1 is in a weird place. So I set:

export EXTRA_INCLUDE_DIR=/opt/homebrew/include
export EXTRA_LIB_DIR=/opt/homebrew/lib
export OPENSSL_INCLUDE_DIR=/opt/homebrew/opt/[email protected]/include
export OPENSSL_LIB_DIR=/opt/homebrew/opt/[email protected]/lib

Similarly, on FreeBSD you may need to set the first two to /usr/local/include and
/usr/local/lib.

(You see? If you had used Bazel you wouldn't have had to deal with any of this.)

### Troubleshooting the CMake Build

If "ev.h" is not found, then EXTRA_INCLUDE_DIR must be set to where it's found.
Or it may not be installed yet.

Similarly if "ssl.h" is not found, the similar problem exists for OpenSSL.

If something like "_sk_push" is not found at link time, then either
OPENSSL_LIB_DIR is not set to find the right library, or there is a
mismatch between the OpenSSL version found in the OPENSSL_INCLUDE_DIR
and OPENSSL_LIB_DIR directories.

Finally, if functions like "TLS_client_method" can't be found, then
you have selected the wrong version of OpenSSL. Install OpenSSL 1.1,
and use the variables described above to point the build to it.
It may not be in one of the usual locations, and the include and
library files that come up for "ssl.h" and "libssl" will be OpenSSL
1.0, which is not what we want.

### Testing

1. cd release
2. make
3. make test
2 changes: 1 addition & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ cc_library(
hdrs = ["test_server.h"],
deps = [
"//apib:common",
"//third_party/http_parser",
"//third_party/libev",
"@boringssl//:ssl",
"@httpparser",
],
)

Expand Down
Empty file added third_party/BUILD
Empty file.
12 changes: 1 addition & 11 deletions httpparser.build → third_party/http_parser/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "httpparser",
name = "http_parser",
srcs = [
"http_parser.c",
],
Expand All @@ -12,13 +12,3 @@ cc_library(
"-DHTTP_PARSER_STRICT=0",
],
)

cc_test(
name = "test",
srcs = [
"test.c",
],
deps = [
":httpparser",
],
)

0 comments on commit dbc9dac

Please sign in to comment.