Skip to content

Commit

Permalink
Merge #82762
Browse files Browse the repository at this point in the history
82762: bazel: allow using locally-installed `node` on freebsd r=knz a=rickystewart

* Pull in a patch to [rules_nodejs](cockroachdb/rules_nodejs@59a92cc) to support FreeBSD.
* Add a new `toolchain` pointing to the locally-installed `node` which
  is compatible with FreeBSD.

Closes #74208.

Release note: None

Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
craig[bot] and rickystewart committed Jun 14, 2022
2 parents bd5462a + d9fb4a7 commit 1a5f7b0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
28 changes: 21 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")]""",
)
3 changes: 1 addition & 2 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions build/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
#
Expand Down
2 changes: 1 addition & 1 deletion dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/dev/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 1a5f7b0

Please sign in to comment.