Skip to content

bazel: allow using locally-installed node on freebsd#82762

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rickystewart:freebsdnode
Jun 14, 2022
Merged

bazel: allow using locally-installed node on freebsd#82762
craig[bot] merged 1 commit intocockroachdb:masterfrom
rickystewart:freebsdnode

Conversation

@rickystewart
Copy link
Copy Markdown
Collaborator

@rickystewart rickystewart commented Jun 10, 2022

  • Pull in a patch to rules_nodejs to support FreeBSD.
  • Add a new toolchain pointing to the locally-installed node which
    is compatible with FreeBSD.

Closes #74208.

Release note: None

@rickystewart rickystewart requested a review from a team as a code owner June 10, 2022 22:54
@rickystewart rickystewart requested a review from knz June 10, 2022 22:54
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@rickystewart
Copy link
Copy Markdown
Collaborator Author

@knz Can you try this patch out (work through the new dev doctor checks and try dev build on FreeBSD)? I suspect it should work but wasn't able to try everything end-to-end.

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

thanks for the heads up!

here what I get now:

INFO: Build option --//pkg/ui:with_ui_flag has changed, discarding analysis cache.
INFO: Repository npm_db_console instantiated at:
  /data/home/kena/src/go/src/github.com/cockroachdb/cockroach/WORKSPACE:256:13: in <toplevel>
  /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/index.bzl:83:18: in yarn_install
Repository rule yarn_install defined at:
  /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl:977:31: in <toplevel>
ERROR: An error occurred during the fetch of repository 'npm_db_console':
   Traceback (most recent call last):
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 827, column 36, in _yarn_install_impl
                is_windows_host = is_windows_os(repository_ctx)
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/rules_nodejs/nodejs/private/os_name.bzl", line 65, column 19, in is_windows_os
                return os_name(rctx) == OS_NAMES[0]
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/rules_nodejs/nodejs/private/os_name.bzl", line 62, column 9, in os_name
                fail("Unsupported operating system {} architecture {}".format(os_name, arch))
Error in fail: Unsupported operating system freebsd architecture amd64
ERROR: /data/home/kena/src/go/src/github.com/cockroachdb/cockroach/WORKSPACE:256:13: fetching yarn_install rule //external:npm_db_console: Traceback (most recent call last):
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 827, column 36, in _yarn_install_impl
                is_windows_host = is_windows_os(repository_ctx)
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/rules_nodejs/nodejs/private/os_name.bzl", line 65, column 19, in is_windows_os
                return os_name(rctx) == OS_NAMES[0]
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/rules_nodejs/nodejs/private/os_name.bzl", line 62, column 9, in os_name
                fail("Unsupported operating system {} architecture {}".format(os_name, arch))
Error in fail: Unsupported operating system freebsd architecture amd64
ERROR: /data/home/kena/src/go/src/github.com/cockroachdb/cockroach/pkg/ui/distccl/BUILD.bazel:3:8: //pkg/ui/distccl:genassets depends on //pkg/ui/workspaces/db-console:db-console-ccl in repository @ which failed to fetch. no such package '@npm_db_console//typescript': Unsupported operating system freebsd architecture amd64
ERROR: Analysis of target '//pkg/cmd/cockroach:cockroach' failed; build aborted:
INFO: Elapsed time: 27.693s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (442 packages loaded, 22737 targets configured)
    currently loading: pkg/ui/workspaces/db-console
ERROR: exit status 1

So maybe it's able to pick up node, but we should teach it to pick up system-wide yarn as well.

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

(as mentioned in issue #74208 we want all 3 of node, yarn and npm to be picked up from the system-wide install without download)

@rickystewart
Copy link
Copy Markdown
Collaborator Author

rickystewart commented Jun 13, 2022

I made a small change, let me know if the build works with the latest version.

(as mentioned in issue #74208 we want all 3 of node, yarn and npm to be picked up from the system-wide install without download)

This is not how this is implemented -- the globally installed node will be used, but yarn is not platform-specific and will be downloaded instead of using whatever you have installed locally.

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's progress now!

ERROR: An error occurred during the fetch of repository 'npm_db_console':
   Traceback (most recent call last):
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 971, column 32, in _yarn_
install_impl
                _apply_post_install_patches(repository_ctx)
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 377, column 19, in _apply
_post_install_patches
                _apply_patches(repository_ctx, working_directory, repository_ctx.attr.post_install_patches, marker_file)
        File "/data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 435, column 21, in _apply
_patches
                fail("Error applying patch %s in %s:\n%s%s" % (str(patch_file), working_directory, st.stderr, st.stdout))
Error in fail: Error applying patch //pkg/ui:patches/aria-query/remove-filenames-with-spaces.db-console.patch in /data/home/kena/src/go/src/github.com/cockroachdb/cockroach:
File to patch:
No file found--skip this patch? [y]
1 out of 1 hunks ignored--saving rejects to Oops.rej
...
No file found--skip this patch? [y]
1 out of 1 hunks ignored--saving rejects to Oops.rej
File to patch:
No file found--skip this patch? [y]
1 out of 1 hunks ignored--saving rejects to Oops.rej
ERROR: Analysis of target '//pkg/cmd/cockroach:cockroach' failed; build aborted:

FWIW, I symlinked patch as instructed and patch --version returns 2.7.6.

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rickystewart)

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

FYI, by the time this patch command is running, pkg/ui/workspaces/cluster-ui/node_modules is still empty.

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

FYI, I've re-run dev build multiple times, and at some point it stopped bugging me about these unapplied patches.
Is it able to make forward progress somehow?

After it stopped complaining about patch I could see pkg/ui/workspaces/cluster-ui/node_modules was populated, then I got a different error:

ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_db_console/webpack-cli/bin/BUILD.bazel:9:14: 
While resolving toolchains for target @npm_db_console//webpack-cli/bin:webpack-cli: 
no matching toolchains found for types @rules_nodejs//nodejs:toolchain_type

@rickystewart
Copy link
Copy Markdown
Collaborator Author

@knz That error looks odd to me, can you run with the Bazel flag '--toolchain_resolution_debug=.*' and paste the full output?

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

I get the following

% bazel build //pkg/cmd/cockroach:cockroach --config=with_ui  --toolchain_resolution_debug='.*'
INFO: Invocation ID: 7e371d82-6850-40a4-a7be-d5c8b079b08d
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_db_console/webpack-cli/bin/BUILD.bazel:9:14: While resolving toolchains for target @npm_db_console//webpack-cli/bin:webpack-cli: no matching toolchains found for types @rules_nodejs//nodejs:toolchain_type
ERROR: Analysis of target '//pkg/cmd/cockroach:cockroach' failed; build aborted:
INFO: Elapsed time: 4.878s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 0 targets configured)
    currently loading: @npm_db_console//

@rickystewart
Copy link
Copy Markdown
Collaborator Author

I think I know what that is, try the latest version please?

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

NVM I had to discard the analysis cache.

Here you are: https://gist.github.com/knz/fa9f9e648fb79577aba54995f0c5365e

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest change, there's progress!

image.png

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rickystewart)

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

it's alive!
image

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

okay but there's something not clean yet:

If I run dev ui clean --all, then dev build, I run into the patch error above again.

I have to run dev build and let it fail 2 times, first,

then at the 3rd time it's able to make progress and finish the build.

@rickystewart
Copy link
Copy Markdown
Collaborator Author

@knz Not sure what's going on with that, I'll pull Sean into the discussion in Slack.

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

I'm going to apply Sean's suggestion:

wanna give that a try on your machine since patch is still borked for you? Should be as easy as find $moduleDir -name '* *' -delete at the end of seed_yarn_cache.sh

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

I did this:

  • removed the two patch specs in the top level WORKSPACE
  • added the find ... -delete in the shell script

as a result I observe once:

$ bazel build //pkg/cmd/cockroach:cockroach --config=with_ui
INFO: Invocation ID: 345544b4-928f-4b8a-9752-b2130c8914ba
INFO: Analyzed target //pkg/cmd/cockroach:cockroach (312 packages loaded, 10816 targets configured).
INFO: Found 1 target...
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:9021:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/des.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/des.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/des.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:20573:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/sha.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/sha.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/sha.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:15405:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/md5.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/md5.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/md5.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:6637:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/big.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/big.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/big.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:15405:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/md5.js failed: 1 input file(s) do not exist
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:20573:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/sha.js failed: 1 input file(s) do not exist
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:9021:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/des.js failed: 1 input file(s) do not exist
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:6669:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/bn.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/bn.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/bn.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:6637:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/big.js failed: 1 input file(s) do not exist
Target //pkg/cmd/cockroach:cockroach failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:15405:10 Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/md5.js failed: 1 input file(s) do not exist
INFO: Elapsed time: 65.084s, Critical Path: 0.20s
INFO: 38 processes: 26 internal, 12 local.
FAILED: Build did NOT complete successfully

but then if I run dev build again it completes without error.

(For certainty, I have run dev ui clean --all then dev build again. Same thing: it fails once, then succeeds.)

@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 13, 2022

I have another idea. lemme try this too

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the following command in the script instead:

find $moduleDir/node_modules/aria-query -name '* *' -delete || true

This improves the situation, but not yet 100%. I then get the follwoing error (still, only once - the 2nd time there's no error and the command succeeds)

ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:9789:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/enquire.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/enquire.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/enquire.js'
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:9789:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/enquire.js failed: 1 input file(s) do not exist
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:16765:10: Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/omit.js failed: missing input file 'external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/omit.js', owner: '@npm_cluster_ui//:_/pkg/ui/workspaces/cluster-ui/node_modules/omit.js'
Target //pkg/cmd/cockroach:cockroach failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /data/home/kena/.cache/bazel/_bazel_kena/9b9f53b7334495d6a871cbb472c466bb/external/npm_cluster_ui/BUILD.bazel:9789:10 Copying directory external/npm_cluster_ui/_/pkg/ui/workspaces/cluster-ui/node_modules/enquire.js failed: 1 input file(s) do not exist
INFO: Elapsed time: 59.211s, Critical Path: 0.07s
INFO: 110 processes: 30 internal, 80 local.
FAILED: Build did NOT complete successfully

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rickystewart)

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the convo with @sjbarag the remaining issue is not related to this fix. So the PR as is is very much acceptable as a solution to the original issue. Thanks!

:lgtm_strong:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @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 cockroachdb#74208.

Release note: None
@knz
Copy link
Copy Markdown
Contributor

knz commented Jun 14, 2022

I'll gladly be using this piece of functionality today, so going ahead and merging this. Thanks again

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 14, 2022

Build succeeded:

@craig craig bot merged commit 1a5f7b0 into cockroachdb:master Jun 14, 2022
rickystewart added a commit to cockroachdb/rules_nodejs that referenced this pull request Jun 21, 2022
It is possible to use `rules_nodejs` on operating systems besides
Windows, Linux, and macOS, but they need to be handled in `os_name()`
or else you get a `Unsupported operating system freebsd` error message.
This change allows you to add a FreeBSD toolchain to your project by
declaring a `nodejs_freebsd_amd64` repo with a `bin/node` executable.
cockroachdb/cockroach#82762 is an example of this.
alexeagle pushed a commit to bazel-contrib/rules_nodejs that referenced this pull request Jun 21, 2022
It is possible to use `rules_nodejs` on operating systems besides
Windows, Linux, and macOS, but they need to be handled in `os_name()`
or else you get a `Unsupported operating system freebsd` error message.
This change allows you to add a FreeBSD toolchain to your project by
declaring a `nodejs_freebsd_amd64` repo with a `bin/node` executable.
cockroachdb/cockroach#82762 is an example of this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bazel: yarn download error on freebsd upon dev build cockroach

3 participants