blob: e57ccbff89650a550b45e0d0778353256de5e8d3 [file] [log] [blame]
Chris Frantzb3a10932022-06-03 14:52:06 -07001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5"""Rust `cargo` related rules for OpenTitan.
6"""
7
8def _cargo_raze_impl(ctx):
9 out_file = ctx.actions.declare_file(ctx.label.name + ".bash")
10 substitutions = {
11 "@@FILES@@": " ".join(ctx.attr.cargo),
12 "@@CARGO_RAZE@@": ctx.attr.cargo_raze,
13 }
14 ctx.actions.expand_template(
15 template = ctx.file._runner,
16 output = out_file,
17 substitutions = substitutions,
18 is_executable = True,
19 )
20 return DefaultInfo(
21 files = depset([out_file]),
22 executable = out_file,
23 )
24
25cargo_raze = rule(
26 implementation = _cargo_raze_impl,
27 attrs = {
28 # This should really be a label_list, but cargo-raze generates a
29 # BUILD file in the same directory as Cargo.toml and prevents us
30 # from making Cargo.toml visible to bazel.
31 "cargo": attr.string_list(
32 doc = "Workspace relative paths of Cargo.toml files",
33 ),
34 # This should also be a label, but we need to pass the raw text
35 # of the label into the template script.
36 "cargo_raze": attr.string(
37 default = "@cargo_raze//:raze",
38 doc = "Label of cargo-raze",
39 ),
40 "_runner": attr.label(
41 default = "//rules/scripts:cargo_raze.template.sh",
42 allow_single_file = True,
43 ),
44 },
45 executable = True,
46)