Skip to content

Add support for Bazel build system #1275

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

Merged
merged 3 commits into from
May 6, 2021

Conversation

mglb
Copy link
Contributor

@mglb mglb commented Mar 8, 2021

Adds support for using JsonCpp as an external package in Bazel projects.

Tested in https://github.com/google/verible by replacing:

http_archive(
    name = "jsoncpp_git",
    sha256 = "77a402fb577b2e0e5d0bdc1cf9c65278915cdb25171e3452c68b6da8a561f8f0",
    build_file = "//bazel:jsoncpp.BUILD",
    strip_prefix = "jsoncpp-1.9.2",
    urls = [
        "https://github.com/open-source-parsers/jsoncpp/archive/1.9.2.tar.gz",
    ],
)

with:

git_repository(
    name = "jsoncpp_git",
    branch = "mglb/bazel-support",
    remote = "https://github.com/mglb/jsoncpp.git",
)

in WORKSPACE file, and then running bazel clean; bazel test //...

@baylesj
Copy link
Contributor

baylesj commented Mar 10, 2021

Not sure why the build is failing, I'm wondering if it is a fluke?

@mglb
Copy link
Contributor Author

mglb commented Mar 10, 2021

Name conflict. The CI has been building in build folder, but now BUILD is a file in the repo.
I've changed the build folder name.

Copy link
Contributor

@cdunn2001 cdunn2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're very happy to include support for Bazel. Thank you!

appveyor.yml Outdated
@@ -16,7 +16,7 @@ build_script:
- cmake --version
# The build script starts in root.
- set JSONCPP_FOLDER=%cd%
- set JSONCPP_BUILD_FOLDER=%JSONCPP_FOLDER%\build\release
- set JSONCPP_BUILD_FOLDER=%JSONCPP_FOLDER%\build_out\release
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why build_out for cmake? Is that to be consistent with a bagel folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name conflict. The CI has been building in build folder, but now BUILD is a file in the repo.

Anyway, I've removed this change and renamed the Bazel file to BUILD.bazel. This name is less popular, but officialy recognized by Bazel.

README.md Outdated
@@ -58,6 +58,34 @@ https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdat
### The Meson Build System
If you are using the [Meson Build System](http://mesonbuild.com), then you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/jsoncpp), or simply use `meson wrap install jsoncpp`.

### The Bazel build system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep README.md short and move as much as possible to our wiki? The reason is simple: To avoid doc-only changes in the source-code repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@mglb mglb force-pushed the mglb/bazel-support branch from 819ff7b to bb82896 Compare April 1, 2021 20:31
@mglb
Copy link
Contributor Author

mglb commented Apr 1, 2021

Note to be added to the wiki:

The Bazel build system

To use specific JsonCpp version in your Bazel project, edit your WORKSPACE file and add a http_archive rule:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# ...
http_archive(
    name = "jsoncpp",
    # sha256 = "X.Y.Z.tar.gz SHA256",
    strip_prefix = "jsoncpp-X.Y.Z",
    urls = [
        "https://github.com/open-source-parsers/jsoncpp/archive/X.Y.Z.tar.gz",
    ],
)

Replace X.Y.Z with a correct version, and optionally specify archive file's SHA256 hash.
To get the code directly from a git repository, add a git_repository instead:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# ...
git_repository(
    name = "jsoncpp",
    branch = "master",
    remote = "https://github.com/open-source-parsers/jsoncpp.git",
)

In either case, add "@jsoncpp//:jsoncpp" as a dependency to targets that use JsonCpp.

@cdunn2001
Copy link
Contributor

The commits seem to be gone. Rebase maybe?

@mglb
Copy link
Contributor Author

mglb commented May 5, 2021

@cdunn2001
Branch rebased, everything seems to be working.

@cdunn2001
Copy link
Contributor

Copied to wiki. Thanks!

@cdunn2001 cdunn2001 merged commit 375a111 into open-source-parsers:master May 6, 2021
haeyeon1234 added a commit to haeyeon1234/jsoncpp that referenced this pull request Jun 20, 2021
haeyeon1234 added a commit to haeyeon1234/jsoncpp that referenced this pull request Jun 20, 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

Successfully merging this pull request may close these issues.

3 participants