Skip to content

Commit ad09584

Browse files
committed
netlistsvg: example of how to generate a .svg from a .v file
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f4f5d03 commit ad09584

File tree

8 files changed

+1357
-2
lines changed

8 files changed

+1357
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ build/
55
.metals/
66
.vscode/
77
__pycache__/
8+
node_modules/
9+

BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_binary")
12
load("@bazel-orfs-pip//:requirements.bzl", "requirement")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
24
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
35
load("//:eqy.bzl", "eqy_test")
6+
load("//:netlistsvg.bzl", "netlistsvg")
47
load("//:openroad.bzl", "get_stage_args", "orfs_floorplan", "orfs_flow", "orfs_macro", "orfs_run")
58
load("//:ppa.bzl", "orfs_ppa")
69
load("//:sweep.bzl", "orfs_sweep")
@@ -467,3 +470,21 @@ yosys(
467470
"read_verilog $(location alu.v); proc; write_json $(location alu.json)",
468471
],
469472
)
473+
474+
npm_link_all_packages(name = "node_modules")
475+
476+
js_binary(
477+
name = "netlistsvg",
478+
data = [
479+
"//:node_modules/netlistsvg",
480+
"//:node_modules/yargs",
481+
],
482+
entry_point = "main.js",
483+
visibility = ["//visibility:public"],
484+
)
485+
486+
netlistsvg(
487+
name = "alu_svg",
488+
src = "alu.json",
489+
out = "alu.svg",
490+
)

MODULE.bazel

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ module(
44
compatibility_level = 1,
55
)
66

7+
bazel_dep(name = "aspect_rules_js", version = "2.1.3")
8+
9+
####### Node.js version #########
10+
# By default you get the node version from DEFAULT_NODE_VERSION in @rules_nodejs//nodejs:repositories.bzl
11+
# Optionally you can pin a different node version:
12+
bazel_dep(name = "rules_nodejs", version = "6.3.0")
13+
14+
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
15+
node.toolchain(node_version = "16.14.2")
16+
#################################
17+
18+
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
19+
npm.npm_translate_lock(
20+
name = "npm",
21+
pnpm_lock = "//:pnpm-lock.yaml",
22+
#verify_node_modules_ignored = "//:.bazelignore",
23+
)
24+
use_repo(npm, "npm")
25+
26+
pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
27+
28+
# Allows developers to use the matching pnpm version, for example:
29+
# bazel run -- @pnpm --dir /home/runner/work/rules_js/rules_js install
30+
use_repo(pnpm, "pnpm")
31+
732
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
833

934
http_archive(

MODULE.bazel.lock

Lines changed: 721 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// netlistsvg is a dependency installed with npm
2+
// call netlistsvg module with the command line arguments
3+
var netlistsvg = require('netlistsvg/bin/netlistsvg.js');
4+
5+
var yargs = require('yargs');
6+
7+
var argv = yargs
8+
.demand(1)
9+
.usage('usage: $0 input_json_file [-o output_svg_file] [--skin skin_file] [--layout elk_json_file]')
10+
.argv;
11+
12+
// print cwd
13+
console.log(process.cwd());
14+
15+
netlistsvg.main(argv._[0], argv.o, argv.skin, argv.layout);

netlistsvg.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""netlistsvg utility function"""
2+
3+
load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
4+
5+
def netlistsvg(name, src, out):
6+
"""Run netlistsvg on the given source file"""
7+
js_run_binary(
8+
name = name,
9+
srcs = [src],
10+
outs = [out],
11+
chdir = native.package_name(),
12+
# $(location :alu) does not work as the cwd of the nodejs binary is not the
13+
# workspace root
14+
args = [src, "-o", out],
15+
tool = "@bazel-orfs//:netlistsvg",
16+
)

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "bazel-orfs",
3+
"version": "0.0.1",
4+
"description": "A project for Bazel ORFS",
5+
"dependencies": {
6+
"netlistsvg": "^1.0.2",
7+
"yargs": "^17.0.1"
8+
}
9+
}

0 commit comments

Comments
 (0)