How to use Bazel to build third party c++ library that includes openssl?

2,785 views
Skip to first unread message

hyungj...@gmail.com

unread,
May 26, 2017, 2:06:29 AM5/26/17
to bazel-discuss
Sorry if this is a stupid question, I am trying to use Bazel to build a c++ project on OSX that depends on a library called uWebSockets. I am running into a problem with how to add openssl as a dependency so that files in uWebSockets are able to include files from openssl like so:

#include <openssl/opensslv.h>

My WORKSPACE file in the repo looks like(it looks for openssl installed via homebrew):

new_http_archive(
name = "uwebsockets",
urls = ["https://github.com/uNetworking/uWebSockets/archive/master.zip"],
build_file = "BUILD.uWebSockets",
)

new_local_repository(
name = "systemssl",
path = "/usr/local/opt/openssl",
build_file = "BUILD.systemssl",
)
BUILD.uWebSockets:

cc_library(
name = "uwebsockets-lib",
hdrs = glob(["**/src/*.h"]),
srcs = glob(["**/src/*.cpp"]),
visibility = ["//visibility:public"],
deps = [
"@systemssl//:openssl",
],
)
BUILD.systemssl:

cc_library(
name = "openssl",
hdrs = glob(["**/openssl/*.h"]),
srcs = glob([
"**/libssl.a",
"**/libcrypto.a",
]),
visibility = ["//visibility:public"],
)
Whenever I try to run the build I get:

external/uwebsockets/uWebSockets-master/src/Networking.h:7:10: fatal error: 'openssl/opensslv.h' file not found

I must be missing something here, what am I doing wrong?

Austin Schuh

unread,
May 26, 2017, 12:36:02 PM5/26/17
to hyungj...@gmail.com, bazel-discuss
Use --verbose_failures to see the command line that triggered the error.

I would guess that you don't have '/usr/local/opt/openssl' (or '/usr/local/opt') in the list of include paths for the compiler.  That should be easy to verify with --verbose_failures, though you might need to peek inside the params file in bazel-bin to find all the options.  Take a look at https://bazel.build/versions/master/docs/be/c-cpp.html#cc_library.includes for how to add something to the include path.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/4e6fc15f-74c9-4e03-b6ae-aadaba3720de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hyungj...@gmail.com

unread,
May 26, 2017, 10:39:31 PM5/26/17
to bazel-discuss, hyungj...@gmail.com
Thank you for your help, I got it to work! In the end my BUILD.systemssl file ended up looking like this:

cc_library(
name = "openssl",
hdrs = glob(["**/include/openssl/*.h"]),
srcs = glob([
"**/libssl.a",
"**/libcrypto.a",
]),
strip_include_prefix= "include",
includes = ['./include/openssl'],
visibility = ["//visibility:public"],
)

I guess the include directory was a couple levels at "external/systemssl/include/openssl" so I had to add strip_include_prefix= "include" in order to allow uWebSockets to #include <openssl/opensslv.h>. Is this the right way to do this?

Austin Schuh

unread,
May 26, 2017, 11:04:29 PM5/26/17
to hyungj...@gmail.com, bazel-discuss
On Fri, May 26, 2017 at 7:39 PM <hyungj...@gmail.com> wrote:
Thank you for your help, I got it to work! In the end my BUILD.systemssl file ended up looking like this:

cc_library(
    name = "openssl",
    hdrs = glob(["**/include/openssl/*.h"]),
    srcs = glob([
        "**/libssl.a",
        "**/libcrypto.a",
    ]),
    strip_include_prefix= "include",
    includes = ['./include/openssl'],
    visibility = ["//visibility:public"],
)

I guess the include directory was a couple levels at "external/systemssl/include/openssl" so I had to add strip_include_prefix= "include" in order to allow uWebSockets to #include <openssl/opensslv.h>. Is this the right way to do this?

You shouldn't need  strip_include_prefix.  I would think that all you need is the includes line, and that should be includes = ['./include'],

Austin
Reply all
Reply to author
Forward
0 new messages