flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Bazel build rules require npm

Open tchatow opened this issue 1 year ago • 6 comments

After upgrading to v23.5.26, projects importing flatbuffers via Bazel fail if @npm repo isn't present, even if the TS rules aren't in use.

WORKSPACE rule:

http_archive(
    name = "com_github_google_flatbuffers",
    sha256 = "1cce06b17cddd896b6d73cc047e36a254fb8df4d7ea18a46acf16c4c0cd3f3f3",
    strip_prefix = "flatbuffers-23.5.26",
    urls = ["https://github.com/google/flatbuffers/archive/refs/tags/v23.5.26.tar.gz"],
)

Build command: bazel build -c opt @com_github_google_flatbuffers//:flatbuffers

Error:

ERROR: Skipping '@com_github_google_flatbuffers//:flatbuffers': error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined.
WARNING: Target pattern parsing failed.
ERROR: error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined.
INFO: Elapsed time: 0.023s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
    currently loading: @com_github_google_flatbuffers//

This seems to be a regression as of https://github.com/google/flatbuffers/pull/7928

@philsc thoughts?

tchatow avatar Jun 02 '23 00:06 tchatow

Good callout. Not sure how easy it'll be to fix. Will take a look tomorrow.

philsc avatar Jun 03 '23 05:06 philsc

This looks to be fixable. It requires me to fix a few things I overlooked in the original patch. WIP branch here: https://github.com/philsc/flatbuffers/tree/unreviewed/phil/fix-7988

philsc avatar Jun 04 '23 06:06 philsc

I just ran into this, it would be nice to have fixed! As a workaround, this very simple patch seems to work if you're only interested in building flatc/cc library:

--- BUILD.bazel
+++ BUILD.bazel
@@ -1,2 +0,0 @@
-load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
-load("@npm//:defs.bzl", "npm_link_all_packages")
@@ -9,7 +6,0 @@
-)
-
-npm_link_all_packages(name = "node_modules")
-
-npm_link_package(
-    name = "node_modules/flatbuffers",
-    src = "//ts:flatbuffers",

calebzulawski avatar Aug 22 '23 17:08 calebzulawski

I did fix this via #7990, but as per #8019 it might be a while before it gets merged.

philsc avatar Aug 24 '23 02:08 philsc

@philsc Hello, any updates on this?

misha-antonenko avatar Dec 08 '23 14:12 misha-antonenko

The PR is still open. @dbaileychess , is it something you can (and have time to) look at?

philsc avatar Dec 08 '23 17:12 philsc

Bumping this as I do see recent PR being merged.

faximan avatar Apr 09 '24 08:04 faximan

@dbaileychess , any chance you have time to review #7990 ?

philsc avatar Apr 18 '24 04:04 philsc