From 1d345e8b99194234f1cb980d2fbdf60090cbe52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Mon, 2 Sep 2024 20:16:27 +0200 Subject: [PATCH] docker: use make from image unless running locally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Øyvind Harboe --- docker.BUILD.bazel | 9 +++++++++ make.tpl | 10 +++++++++- openroad.bzl | 49 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/docker.BUILD.bazel b/docker.BUILD.bazel index abb29150..33de815b 100644 --- a/docker.BUILD.bazel +++ b/docker.BUILD.bazel @@ -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 = [ diff --git a/make.tpl b/make.tpl index 4a22c3e4..1860b717 100644 --- a/make.tpl +++ b/make.tpl @@ -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}" @@ -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" "$@" diff --git a/openroad.bzl b/openroad.bzl index 9e87e303..94ed5d34 100644 --- a/openroad.bzl +++ b/openroad.bzl @@ -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, ] @@ -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]), @@ -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, @@ -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, @@ -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, @@ -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}": "", } @@ -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(): @@ -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, @@ -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, @@ -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]), @@ -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, @@ -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), ), @@ -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, )), @@ -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.file._makefile.path + " $@", reports + logs) ctx.actions.run_shell( arguments = ["--file", ctx.file._makefile.path] + steps, @@ -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, @@ -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), ), @@ -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, )),