blst: Change from blst from http_archive to go_repository (#15709)

This commit is contained in:
Preston Van Loon
2025-09-22 14:00:57 -05:00
committed by GitHub
parent 35bc9b1a0f
commit 5b1a9fb077
4 changed files with 169 additions and 10 deletions

View File

@@ -0,0 +1,3 @@
### Changed
- Changed blst dependency from `http_archive` to `go_repository` so that gazelle can keep it in sync with go.mod.

View File

@@ -3312,6 +3312,15 @@ def prysm_deps():
sum = "h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=",
version = "v1.10.0",
)
go_repository(
name = "com_github_supranational_blst",
build_file_generation = "off",
importpath = "github.com/supranational/blst",
patch_args = ["-p1"],
patches = ["//third_party:com_github_supranational_blst.patch"],
sum = "h1:xNMoHRJOTwMn63ip6qoWJ2Ymgvj7E2b9jY2FAwY+qRo=",
version = "v0.3.14",
)
go_repository(
name = "com_github_syndtr_goleveldb",
importpath = "github.com/syndtr/goleveldb",
@@ -4939,13 +4948,3 @@ def prysm_deps():
sum = "h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=",
version = "v1.27.0",
)
http_archive(
name = "com_github_supranational_blst",
urls = [
"https://github.com/supranational/blst/archive/8c7db7fe8d2ce6e76dc398ebd4d475c0ec564355.tar.gz",
],
strip_prefix = "blst-8c7db7fe8d2ce6e76dc398ebd4d475c0ec564355",
build_file = "//third_party:blst/blst.BUILD",
sha256 = "e9041d03594271c9739d22d9f013ea8b5c28403285a2e8938f6e41a2437c6ff8",
)

25
third_party/blst/README.md vendored Normal file
View File

@@ -0,0 +1,25 @@
# blst BUILD file
Due to the project structure of [blst](https://github.com/supranational/blst) having go bindings
and cdeps in different directories, [gazelle](https://github.com/bazel-contrib/bazel-gazelle)
is unable to appropriately generate the BUILD.bazel files for this repository. We have hand written
the BUILD.bazel file here by the name `blst.BUILD`. PR [#6539](https://github.com/OffchainLabs/prysm/pull/6539)
added build support for blst, but relied on an [http_archive](https://bazel.build/rules/lib/repo/http#http_archive)
repository rule to provide blst as a dependency. This pattern worked, but gazelle would not keep the
dependency in sync with go.mod. There was a risk that go and bazel builds would include different versions
of blst.
Now, we can switch to a [go_repository](https://github.com/bazel-contrib/bazel-gazelle/blob/master/reference.md#go_repository)
model which gazelle understand how to sync with go.mod. However, we still have to tell gazelle how generate a BUILD.bazel file.
Our solution is to tell gazelle not to generate any build file, then we provide blst.BUILD as a patch.
Generating the patch is relatively straight forward:
```
mkdir /tmp/a
mkdir /tmp/b
cp ./third_party/blst/blst.BUILD /tmp/b/BUILD.bazel
(cd /tmp && diff -urN a b) > ./third_party/com_github_supranational_blst.patch
```
If future edits are needed, edit the ./third_party/blst/blst.BUILD and regenerate the patch.

View File

@@ -0,0 +1,132 @@
diff --color -urN a/BUILD.bazel b/BUILD.bazel
--- a/BUILD.bazel 1969-12-31 18:00:00.000000000 -0600
+++ b/BUILD.bazel 2025-09-17 10:29:51.159884226 -0500
@@ -0,0 +1,128 @@
+load("@prysm//tools/go:def.bzl", "go_library")
+load("@io_bazel_rules_go//go:def.bzl", "go_test")
+
+config_setting(
+ name = "blst_modern",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
+ values = {
+ "define": "blst_modern=true",
+ },
+)
+
+go_library(
+ name = "go_default_library",
+ srcs = [
+ "bindings/go/blst.go",
+ "bindings/go/cgo_server.c",
+ ],
+ cgo = True,
+ copts = [
+ "-D__BLST_CGO__",
+ "-Ibindings",
+ "-Isrc",
+ "-O2",
+ ] + select({
+ "@io_bazel_rules_go//go/platform:amd64": [
+ "-mno-avx",
+ "-D__ADX__",
+ ],
+ "//conditions:default": [],
+ }) + select({
+ "//conditions:default": [
+ "-D__BLST_PORTABLE__",
+ ],
+ ":blst_modern": [],
+ }),
+ cdeps = [":blst"],
+ importpath = "github.com/supranational/blst/bindings/go",
+ visibility = ["//visibility:public"],
+)
+
+go_test(
+ name = "go_default_test",
+ srcs = [
+ "bindings/go/blst_htoc_test.go",
+ "bindings/go/blst_minpk_test.go",
+ "bindings/go/blst_minsig_test.go",
+ ],
+ embed = [":go_default_library"],
+ data = glob([
+ "bindings/go/hash_to_curve/*.json",
+ ]),
+)
+
+cc_library(
+ name = "blst",
+ srcs = [
+ "bindings/blst.h",
+ "bindings/blst_aux.h",
+ ],
+ hdrs = [
+ "bindings/blst.h",
+ "bindings/blst_aux.h",
+ ],
+ deps = [
+ ":src",
+ ":asm",
+ ],
+ strip_include_prefix = "bindings",
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "asm_hdrs",
+ hdrs = glob([
+ "build/**/*.s",
+ "build/**/*.S",
+ ], exclude = ["build/assembly.s"]),
+)
+
+cc_library(
+ name = "asm",
+ srcs = [
+ "build/assembly.S",
+ ],
+ copts = [
+ "-O2",
+ ] + select({
+ "@io_bazel_rules_go//go/platform:amd64": [
+ "-mno-avx",
+ "-D__ADX__",
+ ],
+ "//conditions:default": [],
+ }) + select({
+ "//conditions:default": [
+ "-D__BLST_PORTABLE__",
+ ],
+ ":blst_modern": [],
+ }),
+ deps = [":asm_hdrs"],
+ linkstatic = True,
+)
+
+cc_library(
+ name = "hdrs",
+ hdrs = glob(
+ [
+ "src/*.c",
+ "src/*.h",
+ ],
+ exclude = [
+ "src/client_*.c",
+ ],
+ ),
+ strip_include_prefix = "src",
+)
+
+cc_library(
+ name = "src",
+ srcs = [
+ "src/server.c",
+ ],
+ deps = [
+ ":hdrs",
+ ],
+)