项目作者: bazelbuild

项目描述 :
D rules for Bazel
高级语言: Starlark
项目地址: git://github.com/bazelbuild/rules_d.git
创建时间: 2016-03-15T15:04:29Z
项目社区:https://github.com/bazelbuild/rules_d

开源协议:Apache License 2.0

下载


Build status

D rules

Status

We make sure this repository works with the latest version of Bazel, but no
other development is planned.

Volunteers are welcome. If you want to use the rules, consider contributing to
this repository and becoming a maintainer.

Rules

Setup

To use the D rules, add the following to your WORKSPACE file to add the
external repositories for the D toolchain:

  1. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
  2. http_archive(
  3. name = "io_bazel_rules_d",
  4. urls = ["https://github.com/bazelbuild/rules_d/archive/bcf137e3c9381545ce54715632bc1d31c51ee4da.tar.gz"],
  5. sha256 = "a32847bf2ae634563dece49c4dc8353956b64ba5c2d01ce811ea243e1a21b5b7",
  6. strip_prefix = "rules_d-bcf137e3c9381545ce54715632bc1d31c51ee4da",
  7. )
  8. load("@io_bazel_rules_d//d:d.bzl", "d_repositories")
  9. d_repositories()

Roadmap

d_library

  1. d_library(name, srcs, deps, includes, linkopts, versions)




































Attributes
name
Name, required

A unique name for this rule.



This name will be used as the name of the library built by this rule.


srcs
List of labels, required

List of D .d source files used to build the library.


deps
List of labels, optional

List of libraries to be linked to this library target.



These can either be other d_library targets,
source-only d_source_library targets, or
cc_library targets if linking a native library.


imports
List of strings, optional

List of import dirs to add to the compile line.



These will be passed to the D compiler via -I flags.


linkopts
List of strings, optional

List of flags that are added to the D linker command.



These will be passed to the D compiler via -L flags.


versions
List of strings, optional

List of versions to be defined during compilation.



Versions are used for conditional compilation and are enabled in the
code using version condition blocks. These versions
listed here will be passed to the D compiler using
-version flags.


Example

Suppose you have the following directory structure for a D project:

  1. [workspace]/
  2. WORKSPACE
  3. foo/
  4. BUILD
  5. foo.d
  6. bar.d
  7. baz.d

The library foo is built using a d_library target:

foo/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_library")
  2. d_library(
  3. name = "foo",
  4. srcs = [
  5. "foo.d",
  6. "bar.d",
  7. "baz.d",
  8. ],
  9. )

d_source_library

  1. d_source_library(name, srcs, deps, includes, linkopts, versions)




































Attributes
name
Name, required

A unique name for this rule.


srcs
List of labels, required


List of D .d source files that comprises this source
library target.


deps
List of labels, optional

List of library targets depended on by this target.



These can either be other d_source_library targets or
cc_library targets, such as when this source library
target implements the D interface for a native library. Any native
libraries will be linked by d_library targets that
depend on this target.


imports
List of strings, optional

List of import dirs to add to the compile line.



These will be passed to the D compiler via -I flags for
any d_library targets that depend on this target.


linkopts
List of strings, optional

List of flags that are added to the D linker command.



These will be passed to the D compiler via -L flags for
any d_library targets that depend on this target.


versions
List of strings, optional

List of version flags to be defined during compilation.



Versions are used for conditional compilation and are enabled in the
code using version condition blocks. These versions
listed here will be passed to the D compiler using
-version flags for any d_library targets
that depend on this target.


Example

Suppose you have the following directory structure for a project building a
C library and a D interface for the C
library:

  1. [workspace]/
  2. WORKSPACE
  3. greeter/
  4. BUILD
  5. native_greeter.c
  6. native_greeter.h
  7. native_greeter.d
  8. hello_world
  9. BUILD
  10. hello_world.d

Build the C library using the cc_library rule and then use the
d_source_library to define the target for the D interface for the C
native_greeter library:

greeter/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_source_library")
  2. cc_library(
  3. name = "native_greeter_lib",
  4. srcs = ["native_greeter.c"],
  5. hdrs = ["native_greeter.h"],
  6. )
  7. d_source_library(
  8. name = "native_greeter",
  9. srcs = ["native_greeter.d"],
  10. deps = [":native_greeter_lib"],
  11. )

Other targets can directly depend on the d_source_library target to link
the C library:

hello_world/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_source_library")
  2. d_binary(
  3. name = "hello_world",
  4. srcs = ["hello_world.d"],
  5. deps = ["//greeter:native_greeter"],
  6. )

d_binary

  1. d_binary(name, srcs, deps, includes, linkopts, versions)




































Attributes
name
Name, required

A unique name for this rule.



This name will be used as the name of the binary built by this rule.


srcs
List of labels, required

List of D .d source files used to build the binary.


deps
List of labels, optional

List of libraries to be linked to this binary target.



These can either be other d_library targets,
source-only d_source_library targets, or
cc_library targets if linking a native library.


imports
List of strings, optional

List of import dirs to add to the compile line.



These will be passed to the D compiler via -I flags.


linkopts
List of strings, optional

List of flags that are added to the D linker command.



These will be passed to the D compiler via -L flags.


versions
List of strings, optional

List of versions to be defined during compilation.



Versions are used for conditional compilation and are enabled in the
code using version condition blocks. These versions
listed here will be passed to the D compiler using
-version flags.


Suppose you have the following directory structure for a D project:

  1. [workspace]/
  2. WORKSPACE
  3. hello_lib/
  4. BUILD
  5. greeter.d
  6. hello_world
  7. BUILD
  8. hello_world.d

The source file hello_lib/greeter.d defines a module greeter:

  1. module greeter;
  2. ...

The hello_lib library is built using a d_library target:

hello_lib/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_library")
  2. d_library(
  3. name = "hello_lib",
  4. srcs = ["greeter.d"],
  5. )

By default, import paths are from the root of the workspace. Thus, the source
for the hello_world binary, hello_world.d, would import the greeter
module as follows:

  1. import hello_lib.greeter;

However, this can be changed via the imports attribute on the d_library
rule.

The hello_world binary is built using a d_binary target:

hello_world/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_library")
  2. d_binary(
  3. name = "hello_world",
  4. srcs = ["hello_world.d"],
  5. deps = ["//hello_lib"],
  6. )

d_test

  1. d_test(name, srcs, deps, includes, linkopts, versions)




































Attributes
name
Name, required

A unique name for this rule.



This name will be used as the name of the test built by this rule.


srcs
List of labels, required

List of D .d source files used to build the test.


deps
List of labels, optional

List of libraries to be linked to this test target.



These can either be other d_library targets,
source-only d_source_library targets, or
cc_library targets if linking a native library.


imports
List of strings, optional

List of import dirs to add to the compile line.



These will be passed to the D compiler via -I flags.


linkopts
List of strings, optional

List of flags that are added to the D linker command.



These will be passed to the D compiler via -L flags.


versions
List of strings, optional

List of versions to be defined during compilation.



Versions are used for conditional compilation and are enabled in the
code using version condition blocks. These versions
listed here will be passed to the D compiler using
-version flags.


Example

Suppose you have the following directory structure for a D project:

  1. [workspace]/
  2. WORKSPACE
  3. hello_lib/
  4. BUILD
  5. greeter.d
  6. greeter_test.d

hello_lib/greeter.d:

  1. module greeter;
  2. import std.stdio;
  3. import std.string;
  4. class Greeter {
  5. private string greeting;
  6. public:
  7. this(in string greeting) {
  8. this.greeting = greeting.dup;
  9. }
  10. string makeGreeting(in immutable string thing) {
  11. return format("%s %s!", this.greeting, thing);
  12. }
  13. void greet(in immutable string thing) {
  14. writeln(makeGreeting(thing));
  15. }
  16. }

hello_lib/greeter_test.d:

  1. import hello_lib.greeter;
  2. unittest {
  3. auto greeter = new Greeter("Hello");
  4. assert(greeter.makeGreeting("world") == "Hello world!");
  5. }
  6. void main() {}

To build the library and unit test:

hello_lib/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_library", "d_test")
  2. d_library(
  3. name = "greeter",
  4. srcs = ["greeter.d"],
  5. )
  6. d_test(
  7. name = "greeter_test",
  8. srcs = ["greeter_test.d"],
  9. deps = [":greeter"],
  10. )

The unit test can then be run using:

  1. bazel test //hello_lib:greeter_test

d_docs

  1. d_docs(name, dep)




















Attributes
name
Name, required

A unique name for this rule.


dep
Label, required

The label of the target to generate code documentation for.



d_docs can generate HTML code documentation for the
source files of d_library, d_source_library,
d_binary, or d_test targets.


Example

Suppose you have the following directory structure for a D project:

  1. [workspace]/
  2. WORKSPACE
  3. foo/
  4. BUILD
  5. foo.d
  6. bar.d
  7. baz.d

The foo/ directory contains the sources for the d_library foo. To
generate HTML documentation for the foo library, define a d_docs target
that takes the d_library foo as its dependency:

foo/BUILD:

  1. load("@io_bazel_rules_d//d:d.bzl", "d_library", "d_docs")
  2. d_library(
  3. name = "foo",
  4. srcs = [
  5. "foo.d",
  6. "bar.d",
  7. "baz.d",
  8. ],
  9. )
  10. d_docs(
  11. name = "foo_docs",
  12. dep = ":foo",
  13. )

Running bazel build //foo:foo_docs will generate a zip file containing the
HTML documentation generated from the source files. See the official D language
documentation on the Documentation Generator for
more information on the conventions for source documentation.