Skip to content

Commit

Permalink
docker: use make from image unless running locally
Browse files Browse the repository at this point in the history
Signed-off-by: Øyvind Harboe <[email protected]>
  • Loading branch information
oharboe committed Sep 2, 2024
1 parent 2bb24e8 commit 32958d6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
9 changes: 9 additions & 0 deletions docker.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ filegroup(
visibility = ["//visibility:public"],
)

filegroup(
name = "make",
data = [
":ld.so",
],
srcs = ["usr/bin/make"],
visibility = ["//visibility:public"],
)

filegroup(
name = "yosys-abc",
data = [
Expand Down
10 changes: 9 additions & 1 deletion make.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e

cd "$(dirname "$0")"
if [ -z "$FLOW_HOME" ]; then
export MAKE_PATH="${MAKE_PATH}"
export YOSYS_EXE="${YOSYS_PATH}"
export OPENROAD_EXE="${OPENROAD_PATH}"
export KLAYOUT_CMD="${KLAYOUT_PATH}"
Expand All @@ -21,5 +22,12 @@ if [ -z "$FLOW_HOME" ]; then
export QT_PLUGIN_PATH="${QT_PLUGIN_PATH:+$PWD/$QT_PLUGIN_PATH}"
export LIBGL_DRIVERS_PATH="${LIBGL_DRIVERS_PATH:+$PWD/$LIBGL_DRIVERS_PATH}"
export GIO_MODULE_DIR="${GIO_MODULE_DIR:+$PWD/$GIO_MODULE_DIR}"
else
# if make is not in the path, error out, otherwise set MAKE_PATH
if ! command -v make >/dev/null; then
echo "Error: make is not in the PATH"
exit 1
fi
export MAKE_PATH="$(command -v make)"
fi
exec make --file "$FLOW_HOME/Makefile" "$@"
exec $MAKE_PATH --file "$FLOW_HOME/Makefile" "$@"
49 changes: 40 additions & 9 deletions openroad.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _run_impl(ctx):
ctx.attr.src[PdkInfo].files,
ctx.attr._openroad[DefaultInfo].default_runfiles.files,
ctx.attr._openroad[DefaultInfo].default_runfiles.symlinks,
ctx.attr._make[DefaultInfo].default_runfiles.files,
ctx.attr._make[DefaultInfo].default_runfiles.symlinks,
ctx.attr._makefile[DefaultInfo].default_runfiles.files,
ctx.attr._makefile[DefaultInfo].default_runfiles.symlinks,
]
Expand All @@ -97,7 +99,7 @@ def _run_impl(ctx):
ctx.file._makefile.path,
"open_{}".format(ctx.attr.src[OrfsInfo].odb.basename),
],
command = "make $@",
command = ctx.executable._make.path + " $@",
env = {
"HOME": "/".join([ctx.genfiles_dir.path, ctx.label.package]),
"WORK_HOME": "/".join([ctx.genfiles_dir.path, ctx.label.package]),
Expand All @@ -114,7 +116,7 @@ def _run_impl(ctx):
ctx.files.src +
ctx.files.data +
ctx.files._tcl +
[config, ctx.file.script, ctx.executable._openroad, ctx.file._makefile],
[config, ctx.file.script, ctx.executable._openroad, ctx.executable._make, ctx.file._makefile],
transitive = transitive_inputs,
),
outputs = outs,
Expand Down Expand Up @@ -153,6 +155,13 @@ orfs_run = rule(
allow_single_file = ["Makefile"],
default = Label("@docker_orfs//:makefile"),
),
"_make": attr.label(
doc = "make binary",
executable = True,
allow_files = True,
cfg = "exec",
default = Label("@docker_orfs//:make"),
),
"_openroad": attr.label(
doc = "OpenROAD binary.",
executable = True,
Expand Down Expand Up @@ -206,12 +215,14 @@ def commonpath(files):

def flow_substitutions(ctx):
return {
"${MAKE_PATH}": ctx.executable._make.path,
"${MAKEFILE_PATH}": ctx.file._makefile.path,
"${FLOW_HOME}": ctx.file._makefile.dirname,
}

def openroad_substitutions(ctx):
return {
"${MAKE_PATH}": ctx.executable._make.path,
"${YOSYS_PATH}": "",
"${OPENROAD_PATH}": ctx.executable._openroad.path,
"${KLAYOUT_PATH}": ctx.executable._klayout.path,
Expand All @@ -223,6 +234,7 @@ def openroad_substitutions(ctx):

def yosys_substitutions(ctx):
return {
"${MAKE_PATH}": ctx.executable._make.path,
"${YOSYS_PATH}": ctx.executable._yosys.path,
"${OPENROAD_PATH}": "",
}
Expand Down Expand Up @@ -298,6 +310,13 @@ def yosys_only_attrs():
cfg = "exec",
default = Label("@docker_orfs//:yosys"),
),
"_make": attr.label(
doc = "make binary.",
executable = True,
allow_files = True,
cfg = "exec",
default = Label("@docker_orfs//:make"),
),
}

def openroad_only_attrs():
Expand All @@ -310,6 +329,13 @@ def openroad_only_attrs():
allow_single_file = ["Makefile"],
default = Label("@docker_orfs//:makefile"),
),
"_make": attr.label(
doc = "make binary.",
executable = True,
allow_files = True,
cfg = "exec",
default = Label("@docker_orfs//:make"),
),
"_openroad": attr.label(
doc = "OpenROAD binary.",
executable = True,
Expand Down Expand Up @@ -437,7 +463,7 @@ def _yosys_impl(ctx, canonicalize, log_names = [], report_names = []):
previous_logs.extend(ctx.attr.canonicalized[LoggingInfo].logs)
previous_reports.extend(ctx.attr.canonicalized[LoggingInfo].logs)

command = _add_optional_generation_to_command("make $@", logs + reports)
command = _add_optional_generation_to_command(ctx.executable._make.path + " $@", logs + reports)

transitive_inputs = [
ctx.attr.pdk[PdkInfo].files,
Expand All @@ -447,6 +473,8 @@ def _yosys_impl(ctx, canonicalize, log_names = [], report_names = []):
ctx.attr._yosys[DefaultInfo].default_runfiles.symlinks,
ctx.attr._makefile[DefaultInfo].default_runfiles.files,
ctx.attr._makefile[DefaultInfo].default_runfiles.symlinks,
ctx.attr._make[DefaultInfo].default_runfiles.files,
ctx.attr._make[DefaultInfo].default_runfiles.symlinks,
depset([dep[OrfsInfo].gds for dep in ctx.attr.deps if dep[OrfsInfo].gds]),
depset([dep[OrfsInfo].lef for dep in ctx.attr.deps if dep[OrfsInfo].lef]),
depset([dep[OrfsInfo].lib for dep in ctx.attr.deps if dep[OrfsInfo].lib]),
Expand Down Expand Up @@ -485,6 +513,7 @@ def _yosys_impl(ctx, canonicalize, log_names = [], report_names = []):
config,
ctx.executable._abc,
ctx.executable._yosys,
ctx.executable._make,
ctx.file._makefile,
],
transitive = transitive_inputs,
Expand Down Expand Up @@ -525,7 +554,7 @@ def _yosys_impl(ctx, canonicalize, log_names = [], report_names = []):
[dep[OrfsInfo].lib for dep in ctx.attr.deps if dep[OrfsInfo].lib],
),
runfiles = ctx.runfiles(
synth_outputs + [config_short, make, ctx.executable._yosys, ctx.file._makefile] +
synth_outputs + [config_short, make, ctx.executable._yosys, ctx.file._makefile, ctx.executable._make] +
verilog_files + rtlil + ctx.files.data + logs + reports + previous_logs + previous_reports,
transitive_files = depset(transitive = transitive_inputs),
),
Expand All @@ -546,7 +575,7 @@ def _yosys_impl(ctx, canonicalize, log_names = [], report_names = []):
config = config_short,
files = [config_short] + verilog_files + rtlil + ctx.files.data,
runfiles = ctx.runfiles(transitive_files = depset(
[config_short, make, ctx.executable._yosys, ctx.file._makefile] +
[config_short, make, ctx.executable._yosys, ctx.file._makefile, ctx.executable._make] +
verilog_files + rtlil + ctx.files.data,
transitive = transitive_inputs,
)),
Expand Down Expand Up @@ -667,13 +696,15 @@ def _make_impl(ctx, stage, steps, result_names = [], object_names = [], log_name
ctx.attr._klayout[DefaultInfo].default_runfiles.symlinks,
ctx.attr._makefile[DefaultInfo].default_runfiles.files,
ctx.attr._makefile[DefaultInfo].default_runfiles.symlinks,
ctx.attr._make[DefaultInfo].default_runfiles.files,
ctx.attr._make[DefaultInfo].default_runfiles.symlinks,
]

for datum in ctx.attr.data:
transitive_inputs.append(datum.default_runfiles.files)
transitive_inputs.append(datum.default_runfiles.symlinks)

command = _add_optional_generation_to_command("make $@", reports + logs)
command = _add_optional_generation_to_command(ctx.executable._make.path + " $@", reports + logs)

ctx.actions.run_shell(
arguments = ["--file", ctx.file._makefile.path] + steps,
Expand All @@ -691,7 +722,7 @@ def _make_impl(ctx, stage, steps, result_names = [], object_names = [], log_name
ctx.files.src +
ctx.files.data +
ctx.files._tcl +
[config, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile],
[config, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile, ctx.executable._make],
transitive = transitive_inputs,
),
outputs = results + objects + logs + reports,
Expand Down Expand Up @@ -733,7 +764,7 @@ def _make_impl(ctx, stage, steps, result_names = [], object_names = [], log_name
],
),
runfiles = ctx.runfiles(
[config_short, make, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile] +
[config_short, make, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile, ctx.executable._make] +
results + ctx.files.data + ctx.files._tcl + ctx.files._opengl + ctx.files._qt_plugins + ctx.files._gio_modules + logs + reports + previous_logs + previous_reports,
transitive_files = depset(transitive = transitive_inputs),
),
Expand All @@ -756,7 +787,7 @@ def _make_impl(ctx, stage, steps, result_names = [], object_names = [], log_name
config = config_short,
files = [config_short] + ctx.files.src + ctx.files.data,
runfiles = ctx.runfiles(transitive_files = depset(
[config_short, make, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile] +
[config_short, make, ctx.executable._openroad, ctx.executable._klayout, ctx.file._makefile, ctx.executable._make] +
ctx.files.src + ctx.files.data + ctx.files._tcl + ctx.files._opengl + ctx.files._qt_plugins + ctx.files._gio_modules,
transitive = transitive_inputs,
)),
Expand Down

0 comments on commit 32958d6

Please sign in to comment.