Skip to content

Commit

Permalink
Extends DSLX std lib search paths.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 513947045
  • Loading branch information
XLS Team authored and copybara-github committed Mar 4, 2023
1 parent 36ecd6e commit d97f48f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion xls/build_rules/xls_dslx_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ def _xls_dslx_library_impl(ctx):
# Parse and type check the DSLX source files.
dslx_srcs_str = " ".join([s.path for s in my_srcs_list])
dummy_file = ctx.actions.declare_file(ctx.attr.name + ".dummy")

# With runs outside a monorepo, the execution root for the workspace of
# the binary can be different with the execroot, requiring to change
# the dslx stdlib search path accordingly.
# e.g., Label("@repo//pkg/xls:binary").workspace_root == "external/repo"
wsroot = get_xls_toolchain_info(ctx).dslx_interpreter_tool.label.workspace_root
wsroot_dslx_path = ":{}".format(wsroot) if wsroot != "" else ""

ctx.actions.run_shell(
outputs = [dummy_file],
# The DSLX interpreter executable is a tool needed by the action.
Expand All @@ -289,7 +297,8 @@ def _xls_dslx_library_impl(ctx):
"for file in $FILES; do",
"{} $file --compare=none --execute=false --dslx_path={}{}".format(
dslx_interpreter_tool.path,
":${PWD}:" + ctx.genfiles_dir.path + ":" + ctx.bin_dir.path,
":${PWD}:" + ctx.genfiles_dir.path + ":" + ctx.bin_dir.path +
wsroot_dslx_path,
" --warnings_as_errors=false" if not ctx.attr.warnings_as_errors else "",
),
"if [ $? -ne 0 ]; then",
Expand Down
10 changes: 9 additions & 1 deletion xls/build_rules/xls_ir_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ def _convert_to_ir(ctx, src):
"warnings_as_errors",
)

# With runs outside a monorepo, the execution root for the workspace of
# the binary can be different with the execroot, requiring to change
# the dslx stdlib search path accordingly.
# e.g., Label("@repo//pkg/xls:binary").workspace_root == "external/repo"
wsroot = get_xls_toolchain_info(ctx).dslx_interpreter_tool.label.workspace_root
wsroot_dslx_path = ":{}".format(wsroot) if wsroot != "" else ""

ir_conv_args = dict(ctx.attr.ir_conv_args)
ir_conv_args["dslx_path"] = (
ir_conv_args.get("dslx_path", "") + ":${PWD}:" +
ctx.genfiles_dir.path + ":" + ctx.bin_dir.path
ctx.genfiles_dir.path + ":" + ctx.bin_dir.path +
wsroot_dslx_path
)

is_args_valid(ir_conv_args, IR_CONV_FLAGS)
Expand Down

0 comments on commit d97f48f

Please sign in to comment.