Skip to content

Commit 3b069fc

Browse files
committed
Bazel build (excluding test/ sources and SBT extra)
1 parent ea6459d commit 3b069fc

File tree

25 files changed

+412
-198
lines changed

25 files changed

+412
-198
lines changed

sim/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.4.1

sim/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ test_run_dir/
3030
.bloop/
3131
project/metals.sbt
3232
project/project
33+
34+
# bazel
35+
bazel-*
36+
MODULE.bazel.lock

sim/BUILD.bazel

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
4+
5+
buildifier(
6+
name = "buildifier-fix",
7+
exclude_patterns = [
8+
"./.git/*",
9+
],
10+
lint_mode = "fix",
11+
mode = "fix",
12+
)
13+
14+
buildifier(
15+
name = "buildifier-check",
16+
exclude_patterns = [
17+
"./.git/*",
18+
],
19+
lint_mode = "warn",
20+
mode = "diff",
21+
)
22+
23+
24+
scala_library(
25+
name = "cde",
26+
srcs = glob(["cde/cde/src/**/*.scala"]),
27+
deps = [
28+
"@mvn//:com_lihaoyi_sourcecode_2_13",
29+
],
30+
)
31+
32+
scala_library(
33+
name = "hardfloat",
34+
srcs = glob(["berkeley-hardfloat/hardfloat/src/main/**/*.scala"]),
35+
deps = [
36+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
37+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
38+
],
39+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
40+
)
41+
42+
scala_library(
43+
name = "diplomacy_base",
44+
srcs = glob([
45+
"diplomacy/diplomacy/src/diplomacy/lazymodule/**/*.scala",
46+
"diplomacy/diplomacy/src/diplomacy/nodes/**/*.scala",
47+
"diplomacy/diplomacy/src/diplomacy/package.scala",
48+
]),
49+
deps = [
50+
":cde",
51+
"@mvn//:com_lihaoyi_sourcecode_2_13",
52+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
53+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
54+
],
55+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
56+
)
57+
58+
scala_library(
59+
name = "diplomacy_aop",
60+
srcs = glob(["diplomacy/diplomacy/src/diplomacy/aop/**/*.scala"]),
61+
deps = [
62+
":cde",
63+
":diplomacy_base",
64+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
65+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
66+
],
67+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
68+
)
69+
70+
scala_library(
71+
name = "diplomacy_bundlebridge",
72+
srcs = glob(["diplomacy/diplomacy/src/diplomacy/bundlebridge/**/*.scala"]),
73+
deps = [
74+
":cde",
75+
":diplomacy_base",
76+
"@mvn//:com_lihaoyi_sourcecode_2_13",
77+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
78+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
79+
],
80+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
81+
)
82+
83+
scala_library(
84+
name = "diplomacy",
85+
exports = [
86+
":diplomacy_base",
87+
":diplomacy_aop",
88+
":diplomacy_bundlebridge",
89+
],
90+
)
91+
92+
scala_library(
93+
name = "rocket-chip_macros",
94+
srcs = glob(["rocket-chip/macros/src/main/**/*.scala"]),
95+
deps = [
96+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
97+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
98+
],
99+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
100+
)
101+
102+
# TODO: refactor/split into smaller targets
103+
# rocket-chip is not really splittable (can split into utils/unittest and everything else)
104+
scala_library(
105+
name = "rocket-chip",
106+
srcs = glob(["rocket-chip/src/main/**/*.scala"]),
107+
deps = [
108+
":hardfloat",
109+
":rocket-chip_macros",
110+
":diplomacy",
111+
":cde",
112+
"@mvn//:com_lihaoyi_sourcecode_2_13",
113+
"@mvn//:com_lihaoyi_mainargs_2_13",
114+
"@mvn//:com_lihaoyi_os_lib_2_13",
115+
"@mvn//:com_lihaoyi_geny_2_13",
116+
"@mvn//:org_json4s_json4s_jackson_2_13",
117+
"@mvn//:org_json4s_json4s_jackson_core_2_13",
118+
"@mvn//:org_json4s_json4s_native_2_13",
119+
"@mvn//:org_json4s_json4s_core_2_13",
120+
"@mvn//:org_json4s_json4s_ast_2_13",
121+
"@mvn//:org_scala_graph_graph_core_2_13",
122+
"@mvn//:org_scala_lang_modules_scala_collection_compat_2_13",
123+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
124+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
125+
],
126+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
127+
)
128+
129+
# at the top-level so that it can at runtime depend on firesim sources
130+
scala_binary(
131+
name = "chisel-generator",
132+
main_class = "midas.chiselstage.Generator",
133+
deps = [
134+
"//midas/src/main/scala:midas",
135+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
136+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
137+
],
138+
runtime_deps = [
139+
"//src/main/scala/examples:examples",
140+
"//src/main/scala/fasedtests:fased-tests",
141+
"//src/main/scala/midasexamples:midas-examples",
142+
],
143+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
144+
)

sim/MODULE.bazel

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module(
2+
name = "firesim",
3+
version = "0.0.1",
4+
)
5+
6+
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
7+
8+
bazel_dep(name = "rules_scala", version = "7.1.2")
9+
register_toolchains("//toolchains:custom_scala_toolchain")
10+
11+
bazel_dep(name = "rules_jvm_external", version = "6.8")
12+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
13+
maven.install(
14+
name = "mvn", # renamed mvn from maven to avoid naming conflicts
15+
artifacts = [
16+
# deps needed for 2.13.10 scala toolchain
17+
"org.scala-lang:scala-compiler:2.13.10",
18+
"org.scala-lang:scala-library:2.13.10",
19+
"org.scala-lang:scala-reflect:2.13.10",
20+
"org.scala-lang.modules:scala-xml_2.12:1.1.0",
21+
"org.scala-lang.modules:scala-parser-combinators_2.12:1.0.6",
22+
23+
# repository deps
24+
"edu.berkeley.cs:chisel3_2.13:3.6.1",
25+
"edu.berkeley.cs:chisel3-plugin_2.13.10:3.6.1",
26+
"edu.berkeley.cs:firrtl_2.13:1.6.0",
27+
"com.lihaoyi:sourcecode_2.13:0.4.4",
28+
"com.lihaoyi:os-lib_2.13:0.11.5",
29+
"com.lihaoyi:mainargs_2.13:0.7.6",
30+
"com.lihaoyi:geny_2.13:1.1.1",
31+
"org.json4s:json4s-jackson_2.13:4.1.0-M8",
32+
"org.json4s:json4s-jackson-core_2.13:4.1.0-M8",
33+
"org.json4s:json4s-native_2.13:4.1.0-M8",
34+
"org.json4s:json4s-native-core_2.13:4.1.0-M8",
35+
"org.json4s:json4s-core_2.13:4.1.0-M8",
36+
"org.json4s:json4s-ast_2.13:4.1.0-M8",
37+
"com.github.scopt:scopt_2.13:4.1.1-M3",
38+
"org.scala-graph:graph-core_2.13:2.0.3",
39+
"org.scala-lang.modules:scala-collection-compat_2.13:2.13.0"
40+
],
41+
repositories = [
42+
"https://s01.oss.sonatype.org/content/repositories/snapshots",
43+
"https://repo1.maven.org/maven2",
44+
"https://mvnrepository.com/artifact",
45+
"https://maven-central.storage.googleapis.com",
46+
],
47+
)
48+
use_repo(maven, "mvn")

sim/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ include make/utils.mk
5151

5252
include $(TARGET_PROJECT_MAKEFRAG)/config.mk
5353
include make/config.mk
54-
include make/scala-build.mk
5554

5655
include $(TARGET_PROJECT_MAKEFRAG)/build.mk
5756
include make/goldengate.mk
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
# TODO: split into smaller targets
4+
scala_library(
5+
name = "firesimlib",
6+
srcs = glob(["**/*.scala"]),
7+
deps = [
8+
"//midas/targetutils/src/main/scala/midas:targetutils",
9+
"@mvn//:edu_berkeley_cs_chisel3_2_13",
10+
"@mvn//:edu_berkeley_cs_firrtl_2_13",
11+
],
12+
plugins = ["@mvn//:edu_berkeley_cs_chisel3_plugin_2_13_10"],
13+
)

sim/make/config.mk

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,39 @@ ANNO_FILE := $(GENERATED_DIR)/$(long_name).anno.json
5656
subst_prefix :=,$(TARGET_CONFIG_PACKAGE).
5757

5858
TARGET_CONFIG_QUALIFIED := $(TARGET_CONFIG_PACKAGE).$(subst _,$(subst_prefix),$(TARGET_CONFIG))
59+
60+
################################################################################
61+
# Sources used for building bazel
62+
################################################################################
63+
64+
# Returns a list of files in directories $1 with single file extension $2 that have $3 in the name.
65+
# Only works if $(1) is a valid string to prevent a large/long-running find command.
66+
fs_lookup_srcs = $(if $(strip $(1)), $(shell find -L $(1) -name target -prune -o \( -iname "*.$(strip $(2))" ! -iname ".*" \) -print 2> /dev/null | grep -E $(3)))
67+
68+
# Returns a list of files in directories $1 with *any* of the file extensions in $3 that have $2 in the name
69+
fs_lookup_srcs_by_multiple_type = $(foreach type,$(3),$(call fs_lookup_srcs,$(1),$(type),$(2)))
70+
71+
SCALA_EXT = scala
72+
VLOG_EXT = sv v
73+
74+
firesim_source_dirs = \
75+
$(addprefix $(firesim_base_dir)/,\
76+
src \
77+
midas \
78+
midas/targetutils \
79+
firesim-lib \
80+
)
81+
82+
firesim_main_srcs = \
83+
$(call fs_lookup_srcs_by_multiple_type, $(firesim_source_dirs), 'main/scala', $(SCALA_EXT)) \
84+
$(call fs_lookup_srcs_by_multiple_type, $(firesim_source_dirs), 'main/resources', $(VLOG_EXT))
85+
firesim_test_srcs = \
86+
$(call fs_lookup_srcs_by_multiple_type, $(firesim_source_dirs), 'test/scala', $(SCALA_EXT)) \
87+
$(call fs_lookup_srcs_by_multiple_type, $(firesim_source_dirs), 'test/resources', $(VLOG_EXT))
88+
89+
################################################################################
90+
# Scala invocation options
91+
################################################################################
92+
93+
JAVA_HEAP_SIZE ?= 16G
94+
export JAVA_TOOL_OPTIONS ?= -Xmx$(JAVA_HEAP_SIZE) -Xss8M -Djava.io.tmpdir=$(firesim_base_dir)/.java_tmp

sim/make/goldengate.mk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ compile: $(simulator_verilog)
2222
# Disable FIRRTL 1.4 deduplication because it creates multiple failures
2323
# Run the 1.3 version instead (checked-in). If dedup must be completely disabled,
2424
# pass --no-legacy-dedup as well
25-
$(simulator_verilog) $(simulator_xdc) $(header) $(fame_annos) &: $(FIRRTL_FILE) $(ANNO_FILE) $(FIRESIM_MAIN_CP)
26-
$(call run_jar_scala_main,$(firesim_base_dir),$(FIRESIM_MAIN_CP),midas.stage.GoldenGateMain,\
25+
$(simulator_verilog) $(simulator_xdc) $(header) $(fame_annos) &: $(FIRRTL_FILE) $(ANNO_FILE) $(firesim_main_srcs) $(firesim_test_srcs)
26+
bazel run //midas/src/main/scala:golden-gate -- \
2727
-i $(FIRRTL_FILE) \
2828
-td $(GENERATED_DIR) \
2929
-faf $(ANNO_FILE) \
3030
-ggcp $(PLATFORM_CONFIG_PACKAGE) \
3131
-ggcs $(PLATFORM_CONFIG) \
3232
--output-filename-base $(BASE_FILE_NAME) \
3333
--allow-unrecognized-annotations \
34-
--no-dedup)
34+
--no-dedup
3535
grep -sh ^ $(GENERATED_DIR)/firrtl_black_box_resource_files.f | \
3636
xargs cat >> $(simulator_verilog) # Append blackboxes to FPGA wrapper, if any
3737

@@ -44,10 +44,10 @@ $(simulator_verilog) $(simulator_xdc) $(header) $(fame_annos) &: $(FIRRTL_FILE)
4444
# to generate a runtime configuration that is compatible with the generated
4545
# hardware (BridgeModule). Useful for modelling a memory system that differs from the default.
4646
.PHONY: conf
47-
conf: $(fame_annos) $(FIRESIM_MAIN_CP)
47+
conf: $(fame_annos) $(firesim_main_srcs) $(firesim_test_srcs)
4848
mkdir -p $(GENERATED_DIR)
49-
$(call run_jar_scala_main,$(firesim_base_dir),$(FIRESIM_MAIN_CP),midas.stage.RuntimeConfigGeneratorMain,\
49+
bazel run //midas/src/main/scala:runtime-config-generator -- \
5050
-td $(GENERATED_DIR) \
5151
-faf $(fame_annos) \
5252
-ggcp $(PLATFORM_CONFIG_PACKAGE) \
53-
-ggcs $(PLATFORM_CONFIG))
53+
-ggcs $(PLATFORM_CONFIG)

0 commit comments

Comments
 (0)