From 4779f77e37db9f0b3005734f0268f99b7204fe3e Mon Sep 17 00:00:00 2001 From: John Millikin Date: Sat, 2 Mar 2019 22:23:37 -0800 Subject: [PATCH] Add a README --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..60f46ab --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# Bazel build rules for GNU M4 + +## Overview + +```python +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_m4", + # See https://github.com/jmillikin/rules_m4/releases for copy-pastable + # URLs and checksums. +) + +load("@rules_m4//m4:m4.bzl", "m4_register_toolchains") + +m4_register_toolchains() +``` + +```python +load("@rules_m4//m4:m4.bzl", "m4") + +m4( + name = "hello_world", + srcs = ["hello_world.in.txt"], + output = "hello_world.txt", +) +``` + +```python +genrule( + name = "hello_world_gen", + srcs = ["hello_world.in.txt"], + outs = ["hello_world_gen.txt"], + cmd = "$(M4) $(SRCS) > $@", + toolchains = ["@rules_m4//m4:toolchain"], +) +``` + +## Toolchains + +```python +load("@rules_m4//m4:m4.bzl", "m4_common") + +def _my_rule(ctx): + m4_toolchain = m4_common.m4_toolchain(ctx) + ctx.actions.run( + executable = m4_toolchain.m4_executable, + inputs = m4_toolchain.files, + # ... + ) + +my_rule = rule( + _my_rule, + toolchains = [m4_common.TOOLCHAIN_TYPE], +) +```