Giter Club home page Giter Club logo

rules_capnproto's Introduction

rules_capnproto

Bazel rules for capnproto

For a list of releases and changes see the CHANGELOG

Installing

Add the following lines to your WORKSPACE file to download and initialize rules_capnproto in your repo:

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

http_archive(
    name = "rules_capnproto",
    sha256 = "c75b4ebcd4f7db7ac2a2a6a5be3c64599c97a26934db67de51d3935304ab6e8c",
    strip_prefix = "rules_capnproto-0.1.0",
    urls = ["https://github.com/kgreenek/rules_capnproto/archive/refs/tags/v0.1.0.tar.gz"],
)

load(
    "@rules_capnproto//capnp:repositories.bzl",
    "capnp_cc_toolchain",
    "capnp_dependencies",
    "capnp_toolchain",
)

capnp_dependencies()
capnp_toolchain()
capnp_cc_toolchain()

Usage

Create a capnp_library

These targets define the dependency relationships between your capnp files, which are used by all the other language-specific rules.

load("@rules_capnproto//capnp:capnp_library.bzl", "capnp_library")

capnp_library(
    name = "foo_capnp",
    srcs = ["foo.capnp"],
)

In order to import a capnp file from one capnp_library from another capnp file in a different capnp_library, the former must be listed in the deps of the latter.

For example, if we create a second capnp file called bar.capnp that imports foo.capnp, we might define a capnp_library like so:

capnp_library(
    name = "bar_capnp",
    srcs = ["bar.capnp"],
    deps = [":foo_capnp"],
)

NOTE: You do not need to create a separate capnp_library for each capnp source file. That is done here for illustration purposes. However, the more granularly you define your capnp_libraries, the better bazel will be able to speed up your builds, since it can be smarter about only generating / compiling sources that are actually imported.

Create a C++ capnproto library

This is an example of creating a cc_capnp_library target. This target generates the C++ headers using the capnp compiler, including resolving all transitive dependencies. This target can be used in the deps of any normal cc_library or cc_binary target.

load("@rules_capnproto//capnp:cc_capnp_library.bzl", "cc_capnp_library")

cc_capnp_library(
    name = "foo_cc_capnp",
    deps = [":foo_capnp"],
)

Include paths for all generated C++ headers mirror the corresponding capnp file's location in the mono-repo. For example, if you create a capnp file called //foo/bar/baz.capnp, the generated C++ header will be imported like so: #include "foo/bar/baz.capnp.h".

It is highly recommended to choose namespaces in your capnp files so that they match the bazel workspace hierarchy. This will create consistency in how you use the generated files across all languages.

In this case, the namespace in //foo/bar/baz.capnp would be declared as:

using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("foo::bar");

The generated C++ class / namespace would be e.g. ::foo::bar::Baz

Language targets such as cc_capnp_library can only depend on existing capnp_library targets.

Full examples

For full examples for all supported languages, browse through the examples package.

rules_capnproto's People

Contributors

kgreenek avatar blais avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.