Skip to content

Commit 1bf5955

Browse files
committed
try adding an sh_wrapper around heir-opt to populate env vars
1 parent 1281797 commit 1bf5955

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bazel_dep(name = "rules_license", version = "1.0.0")
2727
bazel_dep(name = "rules_foreign_cc", version = "0.14.0")
2828
bazel_dep(name = "rules_cc", version = "0.2.0")
2929
bazel_dep(name = "rules_go", version = "0.53.0")
30+
bazel_dep(name = "rules_shell", version = "0.6.0")
3031
bazel_dep(name = "rules_python", version = "1.2.0")
3132
bazel_dep(name = "googletest", version = "1.16.0")
3233
bazel_dep(name = "google_benchmark", version = "1.9.1")

MODULE.bazel.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/BUILD

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# HEIR tools
22
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
33
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
4+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
45

56
package(
67
default_applicable_licenses = ["@heir//:license"],
@@ -12,7 +13,7 @@ WORKSPACE_PATH = ""
1213

1314
# Custom `mlir-opt` replacement that links our dialect and passes
1415
cc_binary(
15-
name = "heir-opt",
16+
name = "heir-opt-bin",
1617
srcs = ["heir-opt.cpp"],
1718
data = select({
1819
"@heir//:config_enable_yosys": [
@@ -198,6 +199,12 @@ cc_binary(
198199
}),
199200
)
200201

202+
sh_binary(
203+
name = "heir-opt",
204+
srcs = ["heir-opt-wrapper.sh"],
205+
data = [":heir-opt-bin"],
206+
)
207+
201208
# Custom `mlir-translate` replacement that adds our custom translations
202209
cc_binary(
203210
name = "heir-translate",

tools/heir-opt-wrapper.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# This script is a wrapper for heir-opt-bin that sets up the environment
3+
# for standalone execution by relying on the predictable structure of the
4+
# bazel runfiles directory.
5+
6+
set -e
7+
8+
# When run via `bazel run`, $0 is the path to this script. The runfiles
9+
# directory is created by bazel as a sibling directory with a .runfiles suffix.
10+
RUNFILES_DIR="${0}.runfiles"
11+
12+
# The main workspace is symlinked as '_main' inside the runfiles dir.
13+
HEIR_WORKSPACE="_main"
14+
ABC_WORKSPACE="edu_berkeley_abc"
15+
16+
HEIR_OPT_BIN="${RUNFILES_DIR}/${HEIR_WORKSPACE}/tools/heir-opt-bin"
17+
18+
# These paths correspond to the `data` dependencies of the `heir-opt-bin` target.
19+
export HEIR_ABC_BINARY="${RUNFILES_DIR}/${ABC_WORKSPACE}/abc"
20+
export HEIR_YOSYS_SCRIPTS_DIR="${RUNFILES_DIR}/${HEIR_WORKSPACE}/lib/Transforms/YosysOptimizer/yosys"
21+
22+
# Use exec to replace this script's process with the actual binary.
23+
exec "${HEIR_OPT_BIN}" "$@"

0 commit comments

Comments
 (0)