aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-22 04:21:33 -0700
committerFuwn <[email protected]>2022-05-22 04:21:33 -0700
commit16cb282ad266674de090cc5c6439944e242074c5 (patch)
treee067967f45c880053fe3063642f0167689c32ddf
downloadrules_cobol-main.tar.xz
rules_cobol-main.zip
feat(0.1.0): initial releaseHEAD0.1.0main
-rw-r--r--.gitignore5
-rw-r--r--LICENSE21
-rw-r--r--README.md83
-rw-r--r--WORKSPACE5
-rw-r--r--cobol/BUILD0
-rw-r--r--cobol/def.bzl5
-rw-r--r--cobol/deps.bzl22
-rw-r--r--cobol/internal/BUILD0
-rw-r--r--cobol/internal/actions.bzl23
-rw-r--r--cobol/internal/rules.bzl30
-rw-r--r--examples/BUILD8
-rw-r--r--examples/HELLO_WORLD.CBL8
12 files changed, 210 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fbf5040
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+# Bazel
+bazel-*
+
+# Old
+old
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2b16572
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the <organization> nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4db9486
--- /dev/null
+++ b/README.md
@@ -0,0 +1,83 @@
+<h1 align="center"><code>rules_cobol</code></h1>
+
+<p align="center"><b>COBOL build rules for Bazel</b></p>
+
+`rules_cobol` is a set of Bazel build rules to make working with COBOL in Bazel
+possible.
+
+## Usage
+
+### `WORKSPACE`
+
+First, grab the latest version of `rules_cobol` and set it up in your
+`WORKSPACE`.
+
+```python
+# Load `http_archive`
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+# Preferably, the latest version of `rules_cobol`
+RULES_COBOL_VERSION = "0.1.0"
+
+# Download `rules_cobol`
+http_archive(
+ name = "io_bazel_rules_cobol",
+ sha256 = "fcbc86d25e9fa38c86c9b2a34e914d2553c659f3b9b52796560aefb2423af56a",
+ strip_prefix = "rules_cobol-{v}".format(v = RULES_COBOL_VERSION),
+ urls = [
+ "https://github.com/Fuwn/rules_cobol/archive/refs/tags/{v}.zip".format(v = RULES_COBOL_VERSION),
+ ],
+)
+
+# Load `cobol_rules_dependencies` from `rules_cobol`
+load("@io_bazel_rules_cobol//cobol:deps.bzl", "cobol_rules_dependencies")
+
+# Grab `rules_cobol`s dependencies
+cobol_rules_dependencies()
+```
+
+### `BUILD`
+
+Next, create a target using the `cobol_binary` rule in your `BUILD` file.
+
+```python
+# Load `cobol_binary` from `rules_cobol`
+load("@io_bazel_rules_cobol//cobol:def.bzl", "cobol_binary")
+
+# Create a binary target named "hello_world"
+cobol_binary(
+ name = "hello_world",
+ srcs = ["HELLO_WORLD.CBL"],
+)
+```
+
+### `HELLO_WORLD.CBL`
+
+Finally, create a `HELLO_WORLD.CBL` file and print "Hello, World!", of course.
+
+```cobol
+000100 IDENTIFICATION DIVISION.
+000200 PROGRAM-ID. HELLO_WORLD.
+000300 DATA DIVISION.
+000400 WORKING-STORAGE SECTION.
+000500 77 FOO PIC 99 VALUE 43.
+000600 PROCEDURE DIVISION.
+000700 DISPLAY "Hello, World!" FOO
+000800 STOP RUN.
+```
+
+Now, just run `bazel run //:hello_world` to build and execute your new COBOL
+program using Bazel!
+
+## Examples
+
+An example of a COBOL program using `rules_cobol` can be found at
+[Fuwn/bazel-cobol-example](https://github.com/Fuwn/bazel-cobol-example).
+
+More examples can be found in the [`examples/`](examples) directory.
+
+## License
+
+This project is licensed with the
+[BSD 3-Clause "New" or "Revised" License](LICENSE) and has been derived from
+[jayconrad/rules_go_simple](https://github.com/jayconrod/rules_go_simple).
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..46e8c07
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,5 @@
+workspace(name = "io_bazel_rules_cobol")
+
+load("//cobol:deps.bzl", "cobol_rules_dependencies")
+
+cobol_rules_dependencies()
diff --git a/cobol/BUILD b/cobol/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cobol/BUILD
diff --git a/cobol/def.bzl b/cobol/def.bzl
new file mode 100644
index 0000000..c78094b
--- /dev/null
+++ b/cobol/def.bzl
@@ -0,0 +1,5 @@
+"""Public definitions for rules_cobol"""
+
+load("//cobol/internal:rules.bzl", _cobol_binary = "cobol_binary")
+
+cobol_binary = _cobol_binary
diff --git a/cobol/deps.bzl b/cobol/deps.bzl
new file mode 100644
index 0000000..baaf611
--- /dev/null
+++ b/cobol/deps.bzl
@@ -0,0 +1,22 @@
+"""Macro for declaring repository dependencies"""
+
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+def cobol_rules_dependencies():
+ """Declares the external repostories that rules_cobol depends on."""
+
+ _maybe(
+ http_archive,
+ name = "bazel_skylib",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
+ ],
+ sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
+ )
+
+def _maybe(rule, name, **kwargs):
+ """Declares an external repository if it has not been declared already."""
+
+ if name not in native.existing_rules():
+ rule(name = name, **kwargs)
diff --git a/cobol/internal/BUILD b/cobol/internal/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cobol/internal/BUILD
diff --git a/cobol/internal/actions.bzl b/cobol/internal/actions.bzl
new file mode 100644
index 0000000..a57bd58
--- /dev/null
+++ b/cobol/internal/actions.bzl
@@ -0,0 +1,23 @@
+"""Common functions for creating actions to build COBOL programs"""
+
+load("@bazel_skylib//lib:shell.bzl", "shell")
+
+def cobol_compile_executable(ctx, srcs, out):
+ """Compiles a single COBOL program from sources
+
+ Args:
+ ctx: the build context
+ srcs: the source files to compile
+ out: the output file
+ """
+
+ ctx.actions.run_shell(
+ outputs = [out],
+ inputs = srcs,
+ command = "cobc -x -o {out} {srcs}".format(
+ out = shell.quote(out.path),
+ srcs = " ".join([shell.quote(src.path) for src in srcs]),
+ ),
+ mnemonic = "COBOLCompile",
+ use_default_shell_env = True,
+ )
diff --git a/cobol/internal/rules.bzl b/cobol/internal/rules.bzl
new file mode 100644
index 0000000..8dac747
--- /dev/null
+++ b/cobol/internal/rules.bzl
@@ -0,0 +1,30 @@
+"Rules for building COBOL programs"
+
+load(":actions.bzl", "cobol_compile_executable")
+
+def _cobol_binary_impl(ctx):
+ prefix = ctx.label.name + "%/"
+ executable = ctx.actions.declare_file(prefix + ctx.label.name)
+
+ cobol_compile_executable(
+ ctx,
+ srcs = ctx.files.srcs,
+ out = executable,
+ )
+
+ return [DefaultInfo(
+ files = depset([executable]),
+ executable = executable,
+ )]
+
+cobol_binary = rule(
+ _cobol_binary_impl,
+ attrs = {
+ "srcs": attr.label_list(
+ allow_files = True,
+ doc = "The COBOL source files to compile for this binary",
+ ),
+ },
+ doc = "Builds an executable program from COBOL source code",
+ executable = True,
+)
diff --git a/examples/BUILD b/examples/BUILD
new file mode 100644
index 0000000..e90e7fa
--- /dev/null
+++ b/examples/BUILD
@@ -0,0 +1,8 @@
+load("//cobol:def.bzl", "cobol_binary")
+
+cobol_binary(
+ name = "hello_world",
+ srcs = [
+ "HELLO_WORLD.CBL",
+ ],
+)
diff --git a/examples/HELLO_WORLD.CBL b/examples/HELLO_WORLD.CBL
new file mode 100644
index 0000000..704c58a
--- /dev/null
+++ b/examples/HELLO_WORLD.CBL
@@ -0,0 +1,8 @@
+ IDENTIFICATION DIVISION.
+ PROGRAM-ID. HELLO_WORLD.
+ DATA DIVISION.
+ WORKING-STORAGE SECTION.
+ 77 FOO PIC 99 VALUE 43.
+ PROCEDURE DIVISION.
+ DISPLAY "Hello, World!" FOO
+ STOP RUN.