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

Add C++ API. #77

Merged
merged 1 commit into from
Mar 16, 2016
Merged

Add C++ API. #77

merged 1 commit into from
Mar 16, 2016

Conversation

davidzchen
Copy link
Contributor

Fixes #71

Background

I started working on this to get a better idea of what the Java bindings should look like. This implementation is a thin wrapper on top of the C API, providing some C++ niceties such as std::string, STL containers, and std::function for import callbacks.

I am opening this pull request as an RFC for now to get feedback on the API's design. There are still some additional changes I would like to add before this is fully ready, including:

  • Adding a test for import callbacks
  • Fixing Makefile. Currently, it no longer builds the .so files by default for some reason, even though they are under $(ALL)
  • Add documentation for the C++ import callbacks.

ALL = \
jsonnet \
libjsonnet.so \
libjsonnet-cpp.so \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, running make only builds jsonnet but not the .so libraries, even though the so's are under ALL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is expected. Running make all builds the .so's.

This change also adds an external dependency for gmock to the Bazel
build, which is used by the C++ library's unit test.

Issue google#71
@davidzchen
Copy link
Contributor Author

This PR is ready for review. I have just added some unit tests for the C++ API.

Since the jsonnet_jpaths_add API has been added, and the primary use case of the import callback has been to add directories to the import path, I am leaving out the import callback from this API for now.

Currently, the C++ API is a simple wrapper around the C APIs. This is not ideal since Jsonnet itself is implemented in C++. It would be better to refactor common logic out of libjsonnet.c and expose both C and C++ APIs. This way, we would able to also expose classes such as FmtOpts in the C++ API, which would be more suitable than having separate methods for setting each formatter option.

@@ -8,7 +8,7 @@ filegroup(
genrule(
name = "gen-std-jsonnet-h",
srcs = ["stdlib/std.jsonnet"],
outs = ["core/std.jsonnet.h"],
outs = ["std.jsonnet.h"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unrelated to this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting an Bazel build error about being unable to find the generated header file:

❯❯❯ bazel build //:jsonnet-common
INFO: Found 1 target...
ERROR: /Volumes/Ocean/Projects/google/jsonnet/BUILD:17:1: undeclared inclusion(s) in rule '//:jsonnet-common':
this rule is missing dependency declarations for the following files included by 'core/desugarer.cpp':
  'bazel-out/local_darwin-fastbuild/genfiles/std.jsonnet.h'.
Target //:jsonnet-common failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.457s, Critical Path: 1.29s

This might be a bug in the C/C++ rules related to using the includes attribute while looking for a header file in the genfiles tree. Changing the genrule to output the file in the current package rather than core/ worked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok as long as it works, no need for it to be the same location as the makefile for example.

@sparkprime
Copy link
Contributor

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants