Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_npm_package_bin should use installed bazel runfiles instead of build_bazel_rules_nodejs/third_party/github/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash #2189

Open
epigramengineer opened this issue Sep 11, 2020 · 1 comment
Labels
cleanup Tech debt, resolving it improves our own velocity has workaround Reduced severity because users aren't blocked

Comments

@epigramengineer
Copy link

🐞 bug report

Affected Rule

The issue is caused by the rule: Generated _npm_package_bin

Is this a regression?

No

Description

The generated rules from npm rely on a runfiles not from the local bazel installation, but from a static version. For operating systems which patch runfiles.bash (see https://github.com/NixOS/nixpkgs/issues/43955), tools aren't available.

🔬 Minimal Reproduction

npx create-nuxt-app broken

WORKSPACE

rules_nodejs_version="2.2.0"
rules_nixpkgs_version="dc24090573d74adcf38730422941fd69b87682c7"
rules_nixpkgs_sha256="aca86baa64174478c57f74ed09d5c2313113abe94aa3af030486d1b14032d3ed"
nixpkgs_version="20.03"
nixpkgs_sha256="f21ca8bc4c8f848a351232e09f3a58d280c05323173a78a5a6013937fb05c6fe"

http_archive( name = "io_tweag_rules_nixpkgs",
    strip_prefix = "rules_nixpkgs-{0}".format(rules_nixpkgs_version),
    url = "https://github.com/tweag/rules_nixpkgs/archive/{0}.tar.gz".format(rules_nixpkgs_version),
    sha256 = rules_nixpkgs_sha256,
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies()

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package")
nixpkgs_git_repository(
    name = "nixpkgs",
    revision = nixpkgs_version,
    sha256 = nixpkgs_sha256,
)

http_archive(
    name = "build_bazel_rules_nodejs",
    url = "https://github.com/bazelbuild/rules_nodejs/releases/download/{0}/rules_nodejs-{0}.tar.gz".format(rules_nodejs_version),
    sha256 = "4952ef879704ab4ad6729a29007e7094aef213ea79e9f2e94cbe1c9a753e63ef",
)

nixpkgs_package(
    name = "nixpkgs_nodejs",
    build_file_content = 'exports_files(glob(["nixpkgs_nodejs/**"]))',
    # See https://github.com/bazelbuild/rules_nodejs/issues/464
    # and https://github.com/bazelbuild/bazel/issues/2927.
    nix_file_content = """
    with import <nixpkgs> { config = {}; overlays = []; };
    runCommand "nodejs-build" { buildInputs = [ nodejs ]; } ''
      mkdir -p $out/nixpkgs_nodejs
      cd $out/nixpkgs_nodejs
      for i in ${nodejs}/*; do ln -s $i; done
      ''
    """,
    nixopts = [
        "--option",
        "sandbox",
        "false",
    ],
    repository = "@nixpkgs",
)

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
node_repositories(
  vendored_node = "@nixpkgs_nodejs",
  package_json = ["//src/web/epigram:package.json"],
)

load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
    name = "npm",
    package_json = "//src:package.json",
    package_lock_json = "//src:package-lock.json",
)

BUILD

load("@npm//@nuxt/cli:index.bzl", "nuxt_cli")

nuxt_cli(
    name = "build",
    args = [
       "build",
       "--dest=$(@D)",
    ],
    data = [
       "@npm//:node_modules",
    ],
    outs = ["dist"],
)

🔥 Exception or Error


Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/host/bin/external/npm/@nuxt/cli/bin/nuxt-cli.sh: line 20: grep: command not found
bazel-out/host/bin/external/npm/@nuxt/cli/bin/nuxt-cli.sh: line 20: cut: command not found
bazel-out/host/bin/external/npm/@nuxt/cli/bin/nuxt-cli.sh: line 263: dirname: command not found

🌍 Your Environment

Operating System:

  
❯ neofetch
          ::::.    ':::::     ::::'           epigramengineer@nixtop 
          ':::::    ':::::.  ::::'            ------------- 
            :::::     '::::.:::::             OS: NixOS 20.03 (Markhor) x86_64 
      .......:::::..... ::::::::              Host: MACH-WX9 M14 
     ::::::::::::::::::. ::::::    ::::.      Kernel: 5.4.35 
    ::::::::::::::::::::: :::::.  .::::'      Uptime: 2 hours, 23 mins 
           .....           ::::' :::::'       Packages: 829 (nix-system), 1385 (nix-user) 
          :::::            '::' :::::'        Shell: zsh 5.7.1 
 ........:::::               ' :::::::::::.   Resolution: 3000x2000 
:::::::::::::                 :::::::::::::   DE: none+i3 
 ::::::::::: ..              :::::            WM: i3 
     .::::: .:::            :::::             Terminal: kitty 
    .:::::  :::::          '''''    .....     Terminal Font: bitstream vera sans mono 12.0 
    :::::   ':::::.  ......:::::::::::::'     CPU: Intel i7-8550U (8) @ 4.000GHz 
     :::     ::::::. ':::::::::::::::::'      GPU: Intel UHD Graphics 620 
            .:::::::: '::::::::::             GPU: NVIDIA GeForce MX150 
           .::::''::::.     '::::.            Memory: 3787MiB / 15801MiB 
          .::::'   ::::.     '::::.
         .::::      ::::      '::::.                                  
                                                                      


  

Output of bazel version:

  
❯ bazel --version
bazel 3.3.1- (@non-git)
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

  
2.2.0
  

Anything else relevant?

Setting use_default_shell_env to True would likely also fix this issue. See bazelbuild/rules_typescript#235

@alexeagle
Copy link
Collaborator

hmm, interesting. I think we had to vendor the runfiles.bash because of a different need to patch it, @gregmagolan made these changes:
https://github.com/bazelbuild/rules_nodejs/commits/stable/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles

Obviously you can workaround by applying that patch
NixOS/nixpkgs@9c5b7cc
to our copy of runfiles.bash as well as the built-in one.

@alexeagle alexeagle added cleanup Tech debt, resolving it improves our own velocity has workaround Reduced severity because users aren't blocked labels Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Tech debt, resolving it improves our own velocity has workaround Reduced severity because users aren't blocked
Projects
None yet
Development

No branches or pull requests

2 participants