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

Bazel: building glog with custom version gflags #480

Closed
levhuan opened this issue Oct 31, 2019 · 2 comments
Closed

Bazel: building glog with custom version gflags #480

levhuan opened this issue Oct 31, 2019 · 2 comments
Assignees

Comments

@levhuan
Copy link

levhuan commented Oct 31, 2019

It is my first time here, and I already read the contribution guideline. So I hope creating an issue is an appropriate step for this discussion.

I am working on a bazel workspace that needs to import and build both gflags and glog from source. I would like to build glog using the version of gflags in my workspace, instead of the one specified in glog WORKSPACE file. Hence, would the following change work and be accepted?

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_github_gflags_gflags",
    strip_prefix = "gflags-2.2.2",
    urls = [
        "https://mirror.bazel.build/github.com/gflags/gflags/archive/v2.2.2.tar.gz",
        "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
    ],
)

to:

if "com_github_gflags_gflags" not in native.existing_rules():
    http_archive(
        name = "com_github_gflags_gflags",
        strip_prefix = "gflags-2.2.2",
        urls = [
            "https://mirror.bazel.build/github.com/gflags/gflags/archive/v2.2.2.tar.gz",
            "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
        ],
    )
@drigz
Copy link
Member

drigz commented Nov 1, 2019

If I understand correctly, you shouldn't need to change glog to do what you want. Since Bazel ignores the WORKSPACE files of external repositories (see bazelbuild/bazel#1943), adding glog to your WORKSPACE will not add gflags: you'll have to add it yourself. You can add any version that you want, as long as it includes gflags/gflags@57ceb0e (2.2.2 is the first release with this commit).

Does that help?

PS: The if ... not in native.existing_rules(): pattern can't be used directly in the WORKSPACE file (if statements aren't allowed in BUILD or WORKSPACE files), but it is useful inside a dependencies macro that is intended to be called from the WORKSPACE to add a group of dependencies. glog doesn't provide a macro like that since it only has one (optional) dependency, so it's easier to let people add gflags to the top-level WORKSPACE themselves.

@levhuan
Copy link
Author

levhuan commented Nov 1, 2019

Thanks for the response @drigz. Close the issue then.

@levhuan levhuan closed this as completed Nov 1, 2019
@sergiud sergiud mentioned this issue May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants