Skip to content

Commit

Permalink
Initial import of code from rules_nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Apr 22, 2022
1 parent 857da78 commit 3b21d73
Show file tree
Hide file tree
Showing 30 changed files with 1,515 additions and 432 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ set -o errexit -o nounset -o pipefail
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
PREFIX="rules_mylang-${TAG:1}"
PREFIX="rules_ts-${TAG:1}"
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')

cat << EOF
WORKSPACE snippet:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_myorg_rules_mylang",
name = "aspect_rules_ts",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/myorg/rules_mylang/archive/refs/tags/${TAG}.tar.gz",
url = "https://github.com/aspect-build/rules_ts/archive/refs/tags/${TAG}.tar.gz",
)
# Fetches the rules_mylang dependencies.
# Fetches the rules_ts dependencies.
# If you want to have a different version of some dependency,
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@com_myorg_rules_mylang//mylang:repositories.bzl", "rules_mylang_dependencies")
rules_mylang_dependencies()
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
rules_ts_dependencies()
\`\`\`
EOF
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trailingComma: 'es5'
tabWidth: 4
semi: false
singleQuote: true
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Run `bazel run //:gazelle` to keep them up-to-date.
## Using this as a development dependency of other rules

You'll commonly find that you develop in another WORKSPACE, such as
some other ruleset that depends on rules_mylang, or in a nested
some other ruleset that depends on rules_ts, or in a nested
WORKSPACE in the integration_tests folder.

To always tell Bazel to use this directory rather than some release
artifact or a version fetched from the internet, run this from this
directory:

```sh
OVERRIDE="--override_repository=rules_mylang=$(pwd)/rules_mylang"
OVERRIDE="--override_repository=rules_ts=$(pwd)/rules_ts"
echo "common $OVERRIDE" >> ~/.bazelrc
```

This means that any usage of `@rules_mylang` on your system will point to this folder.
This means that any usage of `@rules_ts` on your system will point to this folder.

## Releasing

Expand Down
35 changes: 4 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
# Template for Bazel rules
# Bazel rules for ts

Copy this template to create a Bazel ruleset.

Features:

- follows the official style guide at https://docs.bazel.build/versions/main/skylark/deploying.html
- includes Bazel formatting as a pre-commit hook (using [buildifier])
- includes stardoc API documentation generator
- includes typical toolchain setup
- CI configured with GitHub Actions
- Release on GitHub Actions when pushing a tag

See https://docs.bazel.build/versions/main/skylark/deploying.html#readme

[buildifier]: https://github.com/bazelbuild/buildtools/tree/master/buildifier#readme

Ready to get started? Copy this repo, then

1. search for "com_myorg_rules_mylang" and replace with the name you'll use for your workspace
1. search for "myorg" and replace with GitHub org
1. search for "mylang" and replace with the language/tool your rules are for
1. rename directory "mylang" similarly
1. run `pre-commit install` to get lints (see CONTRIBUTING.md)
1. if you don't need to fetch platform-dependent tools, then remove anything toolchain-related.
1. update the `actions/cache@v2` bazel cache key in [.github/workflows/ci.yaml](.github/workflows/ci.yaml) and [.github/workflows/release.yml](.github/workflows/release.yml) to be a hash of your source files.
1. delete this section of the README (everything up to the SNIP).

---- SNIP ----

# Bazel rules for mylang
High-performance alternative to the `@bazel/typescript` npm package, based on
Aspect's rules_js.

## Installation

From the release you wish to use:
<https://github.com/myorg/rules_mylang/releases>
<https://github.com/aspect-build/rules_ts/releases>
copy the WORKSPACE snippet into your `WORKSPACE` file.
20 changes: 11 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
workspace(
# If your ruleset is "official"
# (i.e. is in the bazelbuild GitHub org)
# then this should just be named "rules_mylang"
# then this should just be named "rules_ts"
# see https://docs.bazel.build/versions/main/skylark/deploying.html#workspace
name = "com_myorg_rules_mylang",
name = "aspect_rules_ts",
)

load(":internal_deps.bzl", "rules_mylang_internal_deps")
load(":internal_deps.bzl", "rules_ts_internal_deps")

# Fetch deps needed only locally for development
rules_mylang_internal_deps()
rules_ts_internal_deps()

load("//mylang:repositories.bzl", "mylang_register_toolchains", "rules_mylang_dependencies")
load("//ts:repositories.bzl", "rules_ts_dependencies")

# Fetch dependencies which users need as well
rules_mylang_dependencies()
rules_ts_dependencies()

mylang_register_toolchains(
name = "mylang1_14",
mylang_version = "1.14.2",
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node16",
node_version = "16.9.0",
)

# For running our own unit tests
Expand Down
9 changes: 3 additions & 6 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")

stardoc_with_diff_test(
bzl_library_target = "//mylang:defs",
out_label = "//docs:rules.md",
name = "rules",
bzl_library_target = "//ts:defs",
)

update_docs(
name = "update",
docs_folder = "docs",
)
update_docs(name = "update")
117 changes: 116 additions & 1 deletion docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/simple/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "ts",
srcs = ["foo.ts"],
declaration = True,
)
1 change: 1 addition & 0 deletions examples/simple/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a: string = 'a'
5 changes: 5 additions & 0 deletions examples/simple/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declaration": true
}
}
9 changes: 1 addition & 8 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ statement from these, that's a bug in our distribution.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_mylang_internal_deps():
def rules_ts_internal_deps():
"Fetch deps needed for local development"
maybe(
http_archive,
Expand Down Expand Up @@ -62,10 +62,3 @@ def rules_mylang_internal_deps():
"https://github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
],
)

maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "8c8cf0554376746e2451de85c4a7670cc8d7400c1f091574c1c1ed2a65021a4c",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v0.2.6/bazel_lib-0.2.6.tar.gz",
)
36 changes: 0 additions & 36 deletions mylang/BUILD.bazel

This file was deleted.

1 change: 0 additions & 1 deletion mylang/defs.bzl

This file was deleted.

13 changes: 0 additions & 13 deletions mylang/private/BUILD.bazel

This file was deleted.

Loading

0 comments on commit 3b21d73

Please sign in to comment.