diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..9a3f717 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,46 @@ +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [main] + pull_request: + branches: [main] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + test: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + folder: + # TODO: needs a bit of work to work on CI + # - 'rules_js-npm' + - 'rules_ts' + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + - name: Write engflow credentials + working-directory: ${{ matrix.folder }} + run: | + touch engflow.crt engflow.key + chmod 0600 engflow.crt engflow.key + echo "$ENGFLOW_CLIENT_CRT" > engflow.crt + echo "$ENGFLOW_PRIVATE_KEY" > engflow.key + env: + ENGFLOW_CLIENT_CRT: ${{ secrets.ENGFLOW_CLIENT_CRT }} + ENGFLOW_PRIVATE_KEY: ${{ secrets.ENGFLOW_PRIVATE_KEY }} + - name: Run benchmarks + env: + # Bazelisk will download bazel to here, ensure it is cached between runs. + XDG_CACHE_HOME: ~/.cache/bazel-repo + working-directory: ${{ matrix.folder }} + run: ./run_benchmarks.sh diff --git a/rules_js-npm/.bazelversion b/rules_js-npm/.bazelversion index ac14c3d..03f488b 100644 --- a/rules_js-npm/.bazelversion +++ b/rules_js-npm/.bazelversion @@ -1 +1 @@ -5.1.1 +5.3.0 diff --git a/rules_js-npm/run_benchmark.sh b/rules_js-npm/run_benchmarks.sh similarity index 92% rename from rules_js-npm/run_benchmark.sh rename to rules_js-npm/run_benchmarks.sh index 4103a8d..911e4e9 100755 --- a/rules_js-npm/run_benchmark.sh +++ b/rules_js-npm/run_benchmarks.sh @@ -63,3 +63,9 @@ source ./benchmark_4.sh git checkout npm_install/package.json git checkout npm_translate_lock/package.json git checkout yarn_install/package.json + +# sort the results +cat "$results_file" | sort > "$results_file" + +echo "========================================" +cat "$results_file" diff --git a/rules_ts/.bazelrc b/rules_ts/.bazelrc index bc590be..542a323 100644 --- a/rules_ts/.bazelrc +++ b/rules_ts/.bazelrc @@ -1 +1,60 @@ -build --worker_max_instances=8 \ No newline at end of file +# In general, the rules in this repository assume that runfiles +# are enabled as we do not support no runfiles case. +# +# If you are developing on Windows, you must either run bazel +# with administrator priviledges or enable developer mode. If +# you do not you may hit this error on Windows: +# +# Bazel needs to create symlinks to build the runfiles tree. +# Creating symlinks on Windows requires one of the following: +# 1. Bazel is run with administrator privileges. +# 2. The system version is Windows 10 Creators Update (1703) or later +# and developer mode is enabled. +build --enable_runfiles + +build --incompatible_allow_tags_propagation + +# Turn off legacy external runfiles. +# This prevents accidentally depending on this feature, which Bazel will remove. +build --nolegacy_external_runfiles + +# Turn on --incompatible_strict_action_env which was on by default +# in Bazel 0.21.0 but turned off again in 0.22.0. Follow +# https://github.com/bazelbuild/bazel/issues/7026 for more details. +# This flag is needed to so that postinstall scripts can be executed +# on the host. +# See https://github.com/angular/angular/issues/27514. +build --incompatible_strict_action_env + +# TODO: enable once this is supported in Bazel +build:rbe --experimental_allow_unresolved_symlinks + +# Generic remote cache +build --remote_local_fallback +build --remote_download_toplevel +build --remote_timeout=3600 +build --remote_upload_local_results +## Fixes builds hanging on CI that get the TCP connection closed without sending RST packets. +build --grpc_keepalive_time=30s + +# Generic remote build execution +build:rbe --extra_execution_platforms=@aspect_rules_js//platforms:x86_64_linux_remote +build:rbe --genrule_strategy=remote +build:rbe --host_platform=@aspect_rules_js//platforms:x86_64_linux_remote +build:rbe --jobs=32 + +# EngFlow remote cache +build:rbe --bes_backend=grpcs://tourmaline.cluster.engflow.com +build:rbe --bes_results_url=https://tourmaline.cluster.engflow.com/invocation/ +build:rbe --remote_cache=grpcs://tourmaline.cluster.engflow.com + +# EngFlow remote build execution +build:rbe --remote_executor=grpcs://tourmaline.cluster.engflow.com + +# TODO: remove workaround for failure +build:rbe --modify_execution_info=GoCompilePkg=+no-remote-exec + +# These files are written during CI setup, using secrets registered with the CI platforms +# For local development with RBE, you should override these in your ~/.bazelrc +build:rbe --tls_client_certificate=engflow.crt +build:rbe --tls_client_key=engflow.key diff --git a/rules_ts/.bazelversion b/rules_ts/.bazelversion index 91ff572..b1c26c3 100644 --- a/rules_ts/.bazelversion +++ b/rules_ts/.bazelversion @@ -1 +1 @@ -5.2.0 +aspect-build/6.0.0-aspect1 \ No newline at end of file diff --git a/rules_ts/.gitignore b/rules_ts/.gitignore index 336b287..7597826 100644 --- a/rules_ts/.gitignore +++ b/rules_ts/.gitignore @@ -2,12 +2,16 @@ src bazel-* node_modules ts_project +ts_project_rbe ts_project_worker ts_project_sandboxed_worker ts_project_swc +ts_project_swc_rbe ts_project_worker_swc ts_project_sandboxed_worker_swc +ts_project_esbuild ts_project_rules_nodejs ts_project_rules_nodejs_swc ts_library +ts_library_rbe tsc diff --git a/rules_ts/WORKSPACE b/rules_ts/WORKSPACE index b69a3eb..9b351c6 100644 --- a/rules_ts/WORKSPACE +++ b/rules_ts/WORKSPACE @@ -23,9 +23,9 @@ nodejs_register_toolchains( http_archive( name = "aspect_rules_swc", # HEAD of https://github.com/aspect-build/rules_swc/tree/swc_rust_2 - sha256 = "1d3cfb38426728c5464c15b9d393ff1bf114a1b2a25091f261758252a770eaad", - strip_prefix = "rules_swc-acc8fc27903ecb49a44725813be7c2e2d21e660a", - url = "https://github.com/aspect-build/rules_swc/archive/acc8fc27903ecb49a44725813be7c2e2d21e660a.tar.gz", + sha256 = "74f49c7cd25ce62b1c09681723cec5577fd07bac4790bc65474d32d53de4e843", + strip_prefix = "rules_swc-d94c52f017a87c958dc431ebaac10cc034a816f5", + url = "https://github.com/aspect-build/rules_swc/archive/d94c52f017a87c958dc431ebaac10cc034a816f5.tar.gz", ) load("@aspect_rules_swc//swc:dependencies.bzl", "rules_swc_dependencies") @@ -40,7 +40,26 @@ swc_register_toolchains( "darwin-arm64": "sha512-DuBBKIyk0iUGPmq6RQc7/uOCkGnvB0JDWQbWxA2NGAEcK0ZtI9J0efG9M1/gLIb0QD+d2DVS5Lx7VRIUFTx9lA==", "darwin-x64": "sha512-WvDN6tRjQ/p+4gNvT4UVU4VyJLXy6hT4nT6mGgrtftG/9pP5dDPwwtTm86ISfqGUs8/LuZvrr4Nhwdr3j+0uAA==", }, - swc_version = "v1.2.204", + swc_version = "v1.2.244", +) + +http_archive( + name = "aspect_rules_esbuild", + # HEAD of https://github.com/dzbarsky/rules_esbuild/tree/esbuild_transpiler + sha256 = "24f49ec473c9a96e8efef0f211642579ebc790e4e21cd6a5818ae4bfc610deb0", + strip_prefix = "rules_esbuild-e23be685e07a78ef14dd744ac844193dec09bd2c", + url = "https://github.com/aspect-build/rules_esbuild/archive/e23be685e07a78ef14dd744ac844193dec09bd2c.tar.gz", +) + +load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies") + +rules_esbuild_dependencies() + +load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains") + +esbuild_register_toolchains( + name = "esbuild", + esbuild_version = LATEST_VERSION, ) ######################################################## diff --git a/rules_ts/generate.sh b/rules_ts/generate.sh index cbca969..b9a0d17 100755 --- a/rules_ts/generate.sh +++ b/rules_ts/generate.sh @@ -4,4 +4,4 @@ set -o errexit -o nounset style=$1 rm -rf "$style" -node generator.js "$style" "$style" 5 10 10 1000 +node generator.js "$style" "$style" 5 10 10 100 diff --git a/rules_ts/generator.js b/rules_ts/generator.js index 4d09a65..1e36b53 100644 --- a/rules_ts/generator.js +++ b/rules_ts/generator.js @@ -34,14 +34,18 @@ const featureNames = [ class Generator { static STYLES = [ 'ts_project', + 'ts_project_rbe', 'ts_project_worker', 'ts_project_sandboxed_worker', 'ts_project_swc', + 'ts_project_swc_rbe', 'ts_project_worker_swc', 'ts_project_sandboxed_worker_swc', + 'ts_project_esbuild', 'ts_project_rules_nodejs', 'ts_project_rules_nodejs_swc', 'ts_library', + 'ts_library_rbe', 'tsc', ] @@ -139,6 +143,7 @@ ${this._ts_attributes()} _load() { switch (this.style) { case 'ts_project': + case 'ts_project_rbe': case 'ts_project_worker': case 'ts_project_sandboxed_worker': return [ @@ -147,6 +152,7 @@ ${this._ts_attributes()} ].join("\n") case 'ts_project_swc': + case 'ts_project_swc_rbe': case 'ts_project_worker_swc': case 'ts_project_sandboxed_worker_swc': return [ @@ -155,6 +161,12 @@ ${this._ts_attributes()} 'load("@aspect_rules_swc//swc:defs.bzl", "swc_transpiler")', ].join("\n") + case 'ts_project_esbuild': + return [ + 'load("@aspect_rules_ts//ts:defs.bzl", "ts_project")', + 'load("@aspect_rules_js//js:defs.bzl", "js_library")', + 'load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild_transpiler")', + ].join("\n") case 'ts_project_rules_nodejs': return [ 'load("@npm//@bazel/typescript:index.bzl", "ts_project")', @@ -168,6 +180,7 @@ ${this._ts_attributes()} ].join("\n") case 'ts_library': + case 'ts_library_rbe': return [ 'load("@npm_tslibrary//@bazel/concatjs:index.bzl", ts_project = "ts_library")', 'load("@npm_tslibrary//@bazel/concatjs:index.bzl", js_library = "ts_library")', @@ -202,11 +215,14 @@ ${this._ts_attributes()} _root_build(rootDeps) { switch (this.style) { case 'ts_project': + case 'ts_project_rbe': case 'ts_project_worker': case 'ts_project_sandboxed_worker': case 'ts_project_swc': + case 'ts_project_swc_rbe': case 'ts_project_worker_swc': case 'ts_project_sandboxed_worker_swc': + case 'ts_project_esbuild': return ` # Generated BUILD file, see /generate.js load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") @@ -230,6 +246,7 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} case 'ts_project_rules_nodejs': case 'ts_project_rules_nodejs_swc': case 'ts_library': + case 'ts_library_rbe': return ` # Generated BUILD file, see /generate.js ${this._load()} @@ -253,6 +270,7 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} let attrs = [] switch (this.style) { case 'ts_project': + case 'ts_project_rbe': attrs.push(` tsconfig = "//${this.outputDir}:tsconfig",`) attrs.push(' declaration = True,') attrs.push(' supports_workers = False,') @@ -266,6 +284,7 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} break; case 'ts_project_swc': + case 'ts_project_swc_rbe': attrs.push(` tsconfig = "//${this.outputDir}:tsconfig",`) attrs.push(' declaration = True,') attrs.push(' transpiler = swc_transpiler,') @@ -280,6 +299,13 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} attrs.push(' supports_workers = True,') break; + case 'ts_project_esbuild': + attrs.push(` tsconfig = "//${this.outputDir}:tsconfig",`) + attrs.push(' declaration = True,') + attrs.push(' transpiler = esbuild_transpiler,') + attrs.push(' supports_workers = False,') + break; + case 'ts_project_rules_nodejs': attrs.push(` tsconfig = "//${this.outputDir}:tsconfig.json",`) attrs.push(' declaration = True,') @@ -292,6 +318,7 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} break; case 'ts_library': + case 'ts_library_rbe': attrs.push(` tsconfig = "//${this.outputDir}:tsconfig.json",`) break; diff --git a/rules_ts/run_benchmark.sh b/rules_ts/run_benchmark.sh index 4ede731..c8e1a7d 100755 --- a/rules_ts/run_benchmark.sh +++ b/rules_ts/run_benchmark.sh @@ -43,6 +43,10 @@ else bazel_flags+=( --noworker_sandboxing ) fi +if [[ "$style" == *"rbe"* ]]; then + bazel_flags+=( --config=rbe ) +fi + pushd "$style" if [ "$style" == "tsc" ]; then yarn install diff --git a/rules_ts/run_benchmarks.sh b/rules_ts/run_benchmarks.sh index e8ca013..16710da 100755 --- a/rules_ts/run_benchmarks.sh +++ b/rules_ts/run_benchmarks.sh @@ -6,14 +6,18 @@ rm -f "$results_file" styles=( 'ts_project' + 'ts_project_rbe' 'ts_project_worker' 'ts_project_sandboxed_worker' 'ts_project_swc' + 'ts_project_swc_rbe' 'ts_project_worker_swc' 'ts_project_sandboxed_worker_swc' + 'ts_project_esbuild' 'ts_project_rules_nodejs' 'ts_project_rules_nodejs_swc' 'ts_library' + 'ts_library_rbe' 'tsc' ) @@ -21,3 +25,9 @@ for style in "${styles[@]}" do ./run_benchmark.sh "$style" "$results_file" done + +# sort the results +sort "$results_file" -o "$results_file" + +echo "========================================" +cat "$results_file"