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

Failed to import repo as a third party dependency using bazel #61

Open
yyyokata opened this issue Feb 8, 2023 · 2 comments
Open

Failed to import repo as a third party dependency using bazel #61

yyyokata opened this issue Feb 8, 2023 · 2 comments

Comments

@yyyokata
Copy link

yyyokata commented Feb 8, 2023

Hi there, we're currently working on a graph-compiler based on [some front graph]-mhlo-linalg-[some backend]. When we tried to use mhlo as a third party dependency in another repo as following BUILD:

cc_library(
  name = "utils",
  srcs = [
    "utils.cc",
  ],
  hdrs = [
    "utils.h",
  ],
  deps = [
    "@mlir-hlo//stablehlo:stablehlo_ops",
    "@mlir-hlo//stablehlo:chlo_ops",
    "@mlir-hlo//stablehlo:vhlo_ops",
    "@llvm-project//mlir:IR",
    "@llvm-project//mlir:Dialect",
    "@llvm-project//mlir:Support"
  ]

An error occured in bazel build //target:this rule is missing dependency declarations for the following files.

I found out this error may caused by attr strip_include_prefix = "." in BUILD file, and the extensive use of this attribute seems due to file includes mainly for generated files.
https://github.com/tensorflow/mlir-hlo/blob/master/mhlo/IR/hlo_ops.cc#L87
Once all file includes are in full path, the problem is solved.

We are wondering that are these file includes written by some certain purpose for CMAKE(we tried bazel only), or they are just some known issues need to be rewrite in the future?

@GleasonK
Copy link
Member

GleasonK commented Feb 9, 2023

An error occured in bazel build //target:this rule is missing dependency declarations for the following files.

Could you paste the exact error (or as much of it as you are able to share), wondering which files specifically are causing issues.

We have a change coming through to the StableHLO BUILD file soon, if the issues are //stablehlo-related, I'm curious if that will resolve this at all. Hopefully will have that submitted tomorrow.

@yyyokata
Copy link
Author

yyyokata commented Feb 10, 2023

An error occured in bazel build //target:this rule is missing dependency declarations for the following files.

Could you paste the exact error (or as much of it as you are able to share), wondering which files specifically are causing issues.

We have a change coming through to the StableHLO BUILD file soon, if the issues are //stablehlo-related, I'm curious if that will resolve this at all. Hopefully will have that submitted tomorrow.

Sry my example is a bit misleading, basically there were two kinds of errors I met during compilation:
a.

/root/.cache/bazel/_bazel_root/faa28599d0ac45f3d2c3ab566eab2bcf/external/mlir-hlo/BUILD:198:11: undeclared inclusion(s) in rule '@mlir-hlo//:convert_op_folder':
this rule is missing dependency declarations for the following files included by 'external/mlir-hlo/utils/convert_op_folder.cc':
  'external/mlir-hlo/utils/convert_op_folder.h'
for BUILD rule like this:
cc_library(
  name = "utils",
  srcs = [
    "utils.cc",
  ],
  hdrs = [
    "utils.h",
  ],
  includes = [
    "/external/mlir-hlo/", (tried several includes but didnt work)
    ],
  deps = [
    "@mlir-hlo//:any_target_with_a_short_file_include",
  ]
)

This kind of error only occures when mhlo libs are used as a third party dep. I didnt meet any problem when using stablehlo's targets. My solution is bacally what I wrote behind: to write a patch making all file includes use full path from mhlo root and remove all strip_include_prefix attr in BUILD file.

b.

legalize_patterns.td:7:9: error: Could not find include file 'stablehlo/dialect/StableHloOps.td'
include "stablehlo/dialect/StableHloOps.td"
        ^
legalize_patterns.td:7:9: error: Unexpected token at top level
include "stablehlo/dialect/StableHloOps.td"
for BUILD rule like this:
gentbl_cc_library(
    name = "legalize_pattern_gen",
    td_file = "legalize_patterns.td",
    tbl_outs = [
        (
            ["-gen-rewriters"] ,
            "legalize_patterns.h.inc",
        ),
    ],
    td_srcs = [
      "unary_patterns.td",
      "@mlir-hlo//:hlo_ops_td_files",
      "@mlir-hlo//stablehlo:stablehlo_ops_td_files",
      "@mlir-hlo//stablehlo:chlo_ops_td_files",
      "@llvm-project//mlir:OpBaseTdFiles",
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    includes = [
      "/external/mlir-hlo/",
      "/external/mlir-hlo/stablehlo/",
    ],
)

This one is much more non-intrusive since I can just write includes in own repo to mark td path like import MLIR using bazel.

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

No branches or pull requests

2 participants