From d9fb4a7252de07178eb2181b4937a04d5e72f54e Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Fri, 10 Jun 2022 17:48:23 -0500 Subject: [PATCH] bazel: allow using locally-installed `node` on freebsd * Pull in a patch to [rules_nodejs](https://github.com/cockroachdb/rules_nodejs/commit/59a92ccbcd2f5c40cf2368bbb9f7b102491f537b) to support FreeBSD. * Add a new `toolchain` pointing to the locally-installed `node` which is compatible with FreeBSD. Closes #74208. Release note: None --- WORKSPACE | 28 +++++++++++++++++++++------- build/bazelutil/distdir_files.bzl | 3 +-- build/toolchains/BUILD.bazel | 15 +++++++++++++++ dev | 2 +- pkg/cmd/dev/doctor.go | 12 +++++++++++- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index aa1b2b59a492..a369204d974a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,15 +27,21 @@ http_archive( # Like the above, but for nodeJS. http_archive( - name = "rules_nodejs", - sha256 = "4d48998e3fa1e03c684e6bdf7ac98051232c7486bfa412e5b5475bbaec7bb257", - urls = ["https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_nodejs-core-5.5.0.tar.gz"], + name = "build_bazel_rules_nodejs", + sha256 = "7f3f747db3f924547b9ffdf86da6c604335ad95e09d4e5a69fdcfdb505099421", + strip_prefix = "cockroachdb-rules_nodejs-59a92cc", + # As of 59a92ccbcd2f5c40cf2368bbb9f7b102491f537b, crl-5.5.0 in our + # rules_nodejs fork. + urls = ["https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-rules_nodejs-5.5.0-1-g59a92cc.tar.gz"], ) +# The rules_nodejs "core" module. We use the same source archive as the non-core +# module above, because otherwise it'll pull from upstream. http_archive( - name = "build_bazel_rules_nodejs", - sha256 = "0fad45a9bda7dc1990c47b002fd64f55041ea751fafc00cd34efb96107675778", - urls = [ "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_nodejs-5.5.0.tar.gz" ], + name = "rules_nodejs", + sha256 = "7f3f747db3f924547b9ffdf86da6c604335ad95e09d4e5a69fdcfdb505099421", + strip_prefix = "cockroachdb-rules_nodejs-59a92cc", + urls = ["https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-rules_nodejs-5.5.0-1-g59a92cc.tar.gz"], ) # Load gazelle. This lets us auto-generate BUILD.bazel files throughout the @@ -205,7 +211,7 @@ build_bazel_rules_nodejs_dependencies() # Configure nodeJS. load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install") -load("@rules_nodejs//nodejs:yarn_repositories.bzl", "yarn_repositories") +load("@build_bazel_rules_nodejs//nodejs:yarn_repositories.bzl", "yarn_repositories") node_repositories( node_repositories = { @@ -552,6 +558,7 @@ register_toolchains( "//build/toolchains:cross_arm64_macos_toolchain", "//build/toolchains:cross_arm64_macos_arm_toolchain", "//build/toolchains:dev_darwin_x86_64_toolchain", + "//build/toolchains:node_freebsd_toolchain", ) http_archive( @@ -589,3 +596,10 @@ http_archive( load("//build/bazelutil:repositories.bzl", "distdir_repositories") distdir_repositories() + +# This is used only by rules_nodejs to find the local version of node. +new_local_repository( + name = "nodejs_freebsd_amd64", + path = "/usr/local", + build_file_content = """exports_files[("bin/node")]""", +) diff --git a/build/bazelutil/distdir_files.bzl b/build/bazelutil/distdir_files.bzl index 650522162ea0..b39364ff1e73 100644 --- a/build/bazelutil/distdir_files.bzl +++ b/build/bazelutil/distdir_files.bzl @@ -946,12 +946,11 @@ DISTDIR_FILES = { "https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-protobuf-3f5d91f.tar.gz": "6d4e7fe1cbd958dee69ce9becbf8892d567f082b6782d3973a118d0aa00807a8", "https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-rules_foreign_cc-6f7f1b1.tar.gz": "272ac2cde4efd316c8d7c0140dee411c89da104466701ac179286ef5a89c7b58", "https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-rules_go-v0.27.0-117-g3fc3373.tar.gz": "8b4ac0c07e95679766c55dba4b83df3f466fe9e383ae06177bc0e00198ffb907", + "https://storage.googleapis.com/public-bazel-artifacts/bazel/cockroachdb-rules_nodejs-5.5.0-1-g59a92cc.tar.gz": "7f3f747db3f924547b9ffdf86da6c604335ad95e09d4e5a69fdcfdb505099421", "https://storage.googleapis.com/public-bazel-artifacts/bazel/google-starlark-go-e043a3d.tar.gz": "a35c6468e0e0921833a63290161ff903295eaaf5915200bbce272cbc8dfd1c1c", "https://storage.googleapis.com/public-bazel-artifacts/bazel/platforms-0.0.4.tar.gz": "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d", "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_java-981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz": "f5a3e477e579231fca27bf202bb0e8fbe4fc6339d63b38ccb87c2760b533d1c3", "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_license-0.0.1.tar.gz": "4865059254da674e3d18ab242e21c17f7e3e8c6b1f1421fffa4c5070f82e98b5", - "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_nodejs-5.5.0.tar.gz": "0fad45a9bda7dc1990c47b002fd64f55041ea751fafc00cd34efb96107675778", - "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_nodejs-core-5.5.0.tar.gz": "4d48998e3fa1e03c684e6bdf7ac98051232c7486bfa412e5b5475bbaec7bb257", "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_pkg-0.7.0.tar.gz": "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2", "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_proto-b0cc14be5da05168b01db282fe93bdf17aa2b9f4.tar.gz": "88b0a90433866b44bb4450d4c30bc5738b8c4f9c9ba14e9661deb123f56a833d", "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_python-0.1.0.tar.gz": "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0", diff --git a/build/toolchains/BUILD.bazel b/build/toolchains/BUILD.bazel index 625b50a13007..b0f8e0e8b6a7 100644 --- a/build/toolchains/BUILD.bazel +++ b/build/toolchains/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@build_bazel_rules_nodejs//nodejs:toolchain.bzl", "node_toolchain") # We define a number of toolchains, each of which has a name of the form: # cross_HOST_TARGET_toolchain @@ -287,6 +288,20 @@ platform( ], ) +toolchain( + name = "node_freebsd_toolchain", + exec_compatible_with = [ + "@platforms//os:freebsd", + ], + toolchain = ":node_freebsd_local_toolchain", + toolchain_type = "@rules_nodejs//nodejs:toolchain_type", +) + +node_toolchain( + name = "node_freebsd_local_toolchain", + target_tool_path = "/usr/local/bin/node", +) + # There are aliases for each of these flags defined in .bazelrc; for example, # --crdb_test instead of --//build/toolchains:crdb_test_flag. # diff --git a/dev b/dev index 261f575b353c..95f14ceab736 100755 --- a/dev +++ b/dev @@ -3,7 +3,7 @@ set -euo pipefail # Bump this counter to force rebuilding `dev` on all machines. -DEV_VERSION=36 +DEV_VERSION=37 THIS_DIR=$(cd "$(dirname "$0")" && pwd) BINARY_DIR=$THIS_DIR/bin/dev-versions diff --git a/pkg/cmd/dev/doctor.go b/pkg/cmd/dev/doctor.go index a024291c5d02..4869590cd75c 100644 --- a/pkg/cmd/dev/doctor.go +++ b/pkg/cmd/dev/doctor.go @@ -32,7 +32,7 @@ const ( // doctorStatusVersion is the current "version" of the status checks performed // by `dev doctor``. Increasing it will force doctor to be re-run before other // dev commands can be run. - doctorStatusVersion = 5 + doctorStatusVersion = 6 noCacheFlag = "no-cache" ) @@ -185,6 +185,16 @@ Please perform the following steps: } } + d.log.Println("doctor: running node check") + if runtime.GOOS == "freebsd" { + // Having a pre-installed node is only necessary on freebsd. + _, err := d.exec.CommandContextSilent(ctx, "/usr/local/bin/node", "--version") + if err != nil { + failures = append(failures, `/usr/local/bin/node not found. +You can install node with: `+"`pkg install node`") + } + } + const binDir = "bin" const submodulesMarkerPath = binDir + "/.submodules-initialized" d.log.Println("doctor: running submodules check")