Skip to content

Commit aad5430

Browse files
committed
init
0 parents  commit aad5430

26 files changed

Lines changed: 1205 additions & 0 deletions

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build --incompatible_disallow_empty_glob=true
2+
3+
# Keep user overrides at the end.
4+
try-import %workspace%/user.bazelrc

.bazelversion

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

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/bcr_helper.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: BCR Helper
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
update-release-with-bcr-info:
13+
name: Pack, Calc Hash & Release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Package & Calculate Hash
20+
id: calc
21+
run: |
22+
REPO_NAME="${{ github.event.repository.name }}"
23+
TAG_NAME="${{ github.ref_name }}"
24+
PURE_VERSION="${TAG_NAME#v}"
25+
ASSET_NAME="${REPO_NAME}-${PURE_VERSION}.tar.gz"
26+
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG_NAME}/${ASSET_NAME}"
27+
PREFIX_DIR="${REPO_NAME}-${PURE_VERSION}"
28+
29+
git archive --format=tar.gz --prefix="${PREFIX_DIR}/" -o "$ASSET_NAME" "$TAG_NAME"
30+
31+
HASH_VALUE=$(openssl dgst -sha256 -binary "$ASSET_NAME" | openssl base64 -A)
32+
SRI_HASH="sha256-$HASH_VALUE"
33+
34+
JSON_CONTENT=$(jq -n \
35+
--arg integrity "$SRI_HASH" \
36+
--arg strip_prefix "$PREFIX_DIR" \
37+
--arg url "$DOWNLOAD_URL" \
38+
'{integrity: $integrity, strip_prefix: $strip_prefix, url: $url}')
39+
40+
{
41+
echo "## BCR Submission Data"
42+
echo
43+
echo '```json'
44+
echo "$JSON_CONTENT" | jq .
45+
echo '```'
46+
} > release_body.md
47+
48+
echo "ASSET_NAME=$ASSET_NAME" >> "$GITHUB_ENV"
49+
50+
- name: Create/Update Release with Asset
51+
uses: softprops/action-gh-release@v2
52+
with:
53+
tag_name: ${{ github.ref_name }}
54+
name: Release ${{ github.ref_name }}
55+
body_path: release_body.md
56+
draft: false
57+
prerelease: false
58+
files: ${{ env.ASSET_NAME }}
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
- "LICENSE"
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
name: Build and Test
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Bazel
20+
uses: bazel-contrib/setup-bazel@0.15.0
21+
with:
22+
bazelisk-version: "1.x"
23+
bazelisk-cache: true
24+
repository-cache: true
25+
26+
- name: Build all targets
27+
run: bazel build //...
28+
29+
- name: Run smoke tests
30+
run: |
31+
bazel test //tests/smoke:verilog_concat_test --test_output=errors
32+
bazel test //tests/smoke:simple_adder_test --test_output=errors
33+
34+
- name: Run Chisel version compatibility checks
35+
run: tests/version_compat/check_chisel_versions.sh

.github/workflows/lint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
buildifier:
9+
runs-on: ubuntu-22.04
10+
env:
11+
BUILDIFIER_VERSION: v8.2.1
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- run: |
17+
sudo wget https://github.com/bazelbuild/buildtools/releases/download/${{ env.BUILDIFIER_VERSION }}/buildifier-linux-amd64 -O /usr/local/bin/buildifier
18+
sudo chmod +x /usr/local/bin/buildifier
19+
20+
- run: buildifier -lint=warn -mode=check -warnings=all -r .

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bazel-*
2+
user.bazelrc
3+
MODULE.bazel.lock
4+
.metals/

AGENT.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AGENT文档
2+
3+
## 用户指令
4+
5+
你的任务是将`/home/yqj/proj/arch/BonbonPIM2/rules/generate.bzl`中的`chisel_binary`,`chisel_library``chisel_test`,以及`@bazel-orfs//:verilog.bzl`中的`verilog_single_file_library`这些工具函数,还有关于Scala和Chisel依赖管理,封装成名为`rules_chisel`的BCR包,使得用户可以通过类似下面的方式方便地使用chisel:
6+
```starlark
7+
# 一个可能的使用样例,你可以优化
8+
# User's MODULE.bazel
9+
bazel_dep(name = "rules_chisel", version = "0.1.0")
10+
11+
# Optional: Configure Chisel/Scala versions
12+
chisel = use_extension("@rules_chisel//chisel:extensions.bzl", "chisel")
13+
chisel.toolchain(
14+
chisel_version = "7.2.0", # Default: latest stable
15+
scala_version = "2.13.17", # Default: 2.13.17
16+
)
17+
use_repo(chisel, "chisel_maven")
18+
```
19+
20+
你需要仿照`/home/yqj/proj/buildtools/bazel_rules_verilator`,建立完善的BCR包工程,包括:简洁清晰的README、最小测试工程、GitHub CI以及BCR包相关元信息。
21+
22+
请你记得在下面的AGENT 日志用中文记录你的进展以便我审阅。
23+
24+
## AGENT 日志
25+
- 已完成初始方案设计:以 `rules_chisel` BCR 包形式封装 `chisel_binary``chisel_library``chisel_test``verilog_single_file_library`
26+
- 结合你的建议(Scala 可由用户自行管理),当前实现将 **Scala toolchain 注册**保留给用户在 `MODULE.bazel` 自管;`rules_chisel` 负责提供 Chisel/ScalaTest Maven 依赖扩展。
27+
- 已新增 `chisel/extensions.bzl`:提供 `chisel.toolchain(...)` 扩展,默认生成 `@chisel_maven`,并支持版本参数(`chisel_version``scala_version` 等)。
28+
- 已新增 `chisel/defs.bzl``verilog/defs.bzl`:实现/导出所需规则,并给 `chisel_test` 内置 Verilator 运行时包装。
29+
- 已建立最小测试工程 `tests/smoke`:覆盖 Chisel library/binary/test 与 Verilog 单文件拼接规则。
30+
- 已补齐工程化内容:`MODULE.bazel``BUILD.bazel``README.md``.github/workflows/{ci,lint,bcr_helper}.yml`、基础 Bazel 配置文件。
31+
- 下一步:执行本地 `bazel build //...` 与 smoke tests 自检,并根据结果修正细节。
32+
- 自检完成:
33+
- `bazel build //...` 通过。
34+
- `bazel test //tests/smoke:verilog_concat_test //tests/smoke:simple_adder_test --test_output=errors` 通过。
35+
- 修正记录:
36+
- 处理了 `chisel_test` 包装规则命名、模板字符串转义、示例 Scala API 兼容性(改为更稳妥的 smoke binary 示例)等问题。
37+
- 处理了 bzlmod 下 `maven_install` 生成仓库可见性问题,补充 `rules_shell` / `rules_java` 依赖。
38+
-`scalactic` 作为独立 Maven 工件移除,避免解析失败;`scalatest` 维持可用。
39+
- 根据评审意见修正文档表达:
40+
- README 已明确 Scala toolchain 配置是 **必须由用户自行管理**(非 optional)。
41+
- README 已增加 `chisel_test` 对 Verilator 依赖的说明(含 `bazel_dep(name = "verilator", ...)` 示例和注意事项)。
42+
- 继续按评审建议修正文档:README 已要求用户在 `chisel.toolchain(...)` 中显式指定 `firtool_resolver_version`,并注明其与 `chisel_version` 强绑定,同时给出官方版本对照文档链接(https://www.chisel-lang.org/docs/appendix/versioning)。
43+
- 同步更新仓库内 `MODULE.bazel` 示例,显式填写了 `chisel_version` / `scala_version` / `firtool_resolver_version`,避免隐式默认值造成误用。
44+
- 按新要求继续修订 README:已单独补充 Verilator 依赖说明,并明确该依赖是 **`chisel_test` 需要**`chisel_binary`/`chisel_library`/`verilog_single_file_library` 不要求该依赖)。

BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2026
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@rules_license//rules:license.bzl", "license")
16+
17+
package(
18+
default_applicable_licenses = [":package_license"],
19+
default_visibility = ["//visibility:private"],
20+
)
21+
22+
license(
23+
name = "package_license",
24+
package_name = "rules_chisel",
25+
)
26+
27+
licenses(["notice"])
28+
29+
exports_files(["LICENSE"])

0 commit comments

Comments
 (0)