Skip to content

Commit

Permalink
dependency_support/com_icarus_iverilog: update bazel build
Browse files Browse the repository at this point in the history
  • Loading branch information
proppy committed Oct 31, 2023
1 parent 723965f commit 0bc7113
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 529 deletions.
1 change: 0 additions & 1 deletion dependency_support/com_icarus_iverilog/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
licenses(["restricted"]) # GPLv2

exports_files([
"dummy.sh",
"hello.v",
"hello_verilog_test.sh",
"hello_vpi.c",
Expand Down
42 changes: 7 additions & 35 deletions dependency_support/com_icarus_iverilog/build-plugins.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,23 @@
"""BUILD helpers for using iverilog.
"""

load("@rules_cc//cc:defs.bzl", "cc_binary")

def iverilog_compile(srcs, flags = "", name = ""):
"""Compiles the first .v files given in srcs into a .vvp file.
Passes the flags to iverilog.
"""
vvp_file = srcs[0] + "vp" # Changes .v to .vvp
native.genrule(
name = "gen_" + vvp_file,
srcs = srcs,
outs = [vvp_file],
cmd = (
"$(location @com_icarus_iverilog//:iverilog) " +
flags + " " +
"-o $@ " +
"$(location " + srcs[0] + ")"
),
tools = ["@com_icarus_iverilog//:iverilog"],
)

# Creates a dummy test which will force the .vvp file production.
native.sh_test(
name = "dummy_iverilog_compile_test_" + name + "_" + vvp_file,
srcs = ["@rules_hdl//dependency_support/com_icarus_iverilog:dummy.sh"],
data = [vvp_file],
)

def vpi_binary(name, srcs, **kwargs):
def vpi_binary(name, out, srcs, **kwargs):
"""Creates a .vpi file with the given name from the given sources.
All the extra arguments are passed directly to cc_binary.
"""
so_name = name + ".so"
cc_binary(
name = so_name,
cc_target = name + "_shared"
native.cc_binary(
name = cc_target,
srcs = srcs,
linkshared = 1,
**kwargs
)

native.genrule(
name = "gen_" + name,
srcs = [so_name],
outs = [name],
name = name,
srcs = [":" + cc_target],
outs = [out],
cmd = "cp $< $@",
output_to_bindir = 1,
executable = 1,
Expand Down
Loading

0 comments on commit 0bc7113

Please sign in to comment.