google / google/heir

Cannot find `abc` binary when running `heir-opt` as a standalone binary

Open
#885 9 comments 0 reactions 0 assignees View on GitHub
build
Dominant language
MLIR
Stars
906
Forks
171
Avg merge
4d 12h
Merged PRs (30d)
32

Description

## Issue

When running heir-opt as a standalone binary, it cannot find the abc binary.

## To reproduce

(This assumes we are in the `heir` directory)

1. Build `heir-opt` using bazel
- I use `bazel build @heir//tools:heir-opt`
- There should be a folder under `heir/bazel-bin/tools/heir-opt`. The abc binary should also be located at `heir/bazel-bin/external/edu_berkeley_abc/abc`

2. Run heir-opt from the bazel-bin directory with a --yosys-optimizer
- I ran `./bazel-bin/tools/heir-opt --yosys-optimizer --canonicalize --cse heir/tests/yosys_optimizer/add_one.mlir`
- There should be no visible output, whereas we expect for it to show the modified mlir output.

3. Run heir-opt again, but this time use `strace`
- I ran ` strace ./bazel-bin/tools/heir-opt --yosys-optimizer --canonicalize --cse heir/tests/yosys_optimizer/add_one.mlir`
- The output is quite large so I've pasted it [here](https://gist.github.com/kevaundray/8ca04c8ae92e0c99e7a9de8e67f28c46)
- The line `read(3, "sh: 1: external/edu_berkeley_abc"..., 4096) = 48` seems to indicate that it cannot find the abc tool

## Solution

What fixed it for me was telling bazel to link to the output location of wherever the abc binary was once it was built.

The modification was made in `heir/tools/BUILD`.

I changed `"HEIR_ABC_BINARY=\\\"$(rootpath @edu_berkeley_abc//:abc)\\\"",` to `"HEIR_ABC_BINARY=\\\"$(location @edu_berkeley_abc//:abc)\\\"",`

## Observations

- Everything works for me when running from bazel, ie bazel build and bazel run work fine.
- After the change, bazel build and bazel run still work fine for me.
- The location seems to be an absolute path, so as long as the abc binary is not moved, it works. Otherwise, I had to override the HEIR_ABC_BINARY environment variable to point to the new location of the abc binary

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.