Skip to content

Commit aceb662

Browse files
committed
WIP Initial bazelification
1 parent a02fd12 commit aceb662

File tree

529 files changed

+20227
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

529 files changed

+20227
-0
lines changed

.bazelignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Directories to exclude from Bazel's file watching
2+
.git
3+
node_modules
4+
.avalanchego
5+
build
6+
.direnv
7+
result

.bazelrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Bazel configuration for avalanchego
2+
3+
# Enable bzlmod (default in Bazel 7+, explicit for clarity)
4+
common --enable_bzlmod
5+
6+
# Build settings
7+
build --incompatible_enable_cc_toolchain_resolution
8+
9+
# CGO flags for BLST cryptography library
10+
# Must match scripts/build.sh: CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
11+
build --action_env=CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
12+
build --action_env=CGO_ENABLED=1
13+
14+
# Use purego build tag for gnark-crypto to avoid assembly include path issues
15+
# gnark-crypto's assembly files use cross-package #include which Bazel doesn't support
16+
build --define gotags=purego
17+
18+
# Test settings
19+
test --test_output=errors
20+
21+
# Performance
22+
build --jobs=auto
23+
24+
# Nix integration - allow network for nix-build
25+
# This may need adjustment based on your Bazel sandbox configuration
26+
build --sandbox_add_mount_pair=/nix
27+
28+
# Version injection - provides STABLE_GIT_COMMIT for x_defs
29+
build --workspace_status_command=tools/bazel/workspace_status.sh
30+
build --stamp

BUILD.bazel

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("@gazelle//:def.bzl", "gazelle")
2+
3+
# Gazelle configuration
4+
# gazelle:prefix github.com/ava-labs/avalanchego
5+
# gazelle:exclude .git
6+
# gazelle:exclude build
7+
# gazelle:exclude .direnv
8+
9+
# Resolve coreth imports to local packages (handle replace directive)
10+
# gazelle:resolve go github.com/ava-labs/avalanchego/graft/coreth //graft/coreth
11+
# gazelle:resolve go github.com/ava-labs/avalanchego/graft/coreth/plugin/evm //graft/coreth/plugin/evm
12+
13+
# Resolve proto pb imports - prefer the pb versions
14+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/p2p //proto/pb/p2p
15+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/rpcdb //proto/pb/rpcdb
16+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/sharedmemory //proto/pb/sharedmemory
17+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/aliasreader //proto/pb/aliasreader
18+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/appsender //proto/pb/appsender
19+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/validatorstate //proto/pb/validatorstate
20+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/sdk //proto/pb/sdk
21+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/platformvm //proto/pb/platformvm
22+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/warp //proto/pb/warp
23+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/sync //proto/pb/sync
24+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/vm //proto/pb/vm
25+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/http //proto/pb/http
26+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/http/responsewriter //proto/pb/http/responsewriter
27+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/io/reader //proto/pb/io/reader
28+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/io/writer //proto/pb/io/writer
29+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/net/conn //proto/pb/net/conn
30+
# gazelle:resolve go github.com/ava-labs/avalanchego/proto/pb/signer //proto/pb/signer
31+
# gazelle:resolve go github.com/ava-labs/avalanchego/connectproto/pb/proposervm //connectproto/pb/proposervm
32+
# gazelle:resolve go github.com/ava-labs/avalanchego/connectproto/pb/xsvm //connectproto/pb/xsvm
33+
34+
gazelle(name = "gazelle")
35+
36+
# Target to update external Go dependencies
37+
gazelle(
38+
name = "gazelle-update-repos",
39+
args = [
40+
"-from_file=go.mod",
41+
"-to_macro=deps.bzl%go_dependencies",
42+
"-prune",
43+
],
44+
command = "update-repos",
45+
)

MODULE.bazel

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
"""Bazel module definition for avalanchego."""
2+
3+
module(
4+
name = "avalanchego",
5+
version = "0.0.0",
6+
)
7+
8+
# Core dependencies from Bazel Central Registry
9+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
10+
bazel_dep(name = "platforms", version = "1.0.0")
11+
bazel_dep(name = "rules_go", version = "0.59.0")
12+
bazel_dep(name = "gazelle", version = "0.47.0")
13+
14+
# Go SDK registration
15+
# Uses same SHA256 checksums as nix/go/default.nix for identical binaries
16+
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
17+
go_sdk.download(
18+
name = "go_sdk",
19+
sdks = {
20+
# SHA256s from nix/go/default.nix lines 24-29
21+
"linux_amd64": ("go1.24.9.linux-amd64.tar.gz", "5b7899591c2dd6e9da1809fde4a2fad842c45d3f6b9deb235ba82216e31e34a6"),
22+
"linux_arm64": ("go1.24.9.linux-arm64.tar.gz", "9aa1243d51d41e2f93e895c89c0a2daf7166768c4a4c3ac79db81029d295a540"),
23+
"darwin_amd64": ("go1.24.9.darwin-amd64.tar.gz", "961aa2ae2b97e428d6d8991367e7c98cb403bac54276b8259aead42a0081591c"),
24+
"darwin_arm64": ("go1.24.9.darwin-arm64.tar.gz", "af451b40651d7fb36db1bbbd9c66ddbed28b96d7da48abea50a19f82c6e9d1d6"),
25+
},
26+
version = "1.24.9",
27+
)
28+
use_repo(go_sdk, "go_sdk")
29+
30+
# Go dependencies from go.mod
31+
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
32+
go_deps.from_file(go_mod = "//:go.mod")
33+
34+
# Override libevm's secp256k1 BUILD file to include C source files for CGO
35+
# The gazelle-generated BUILD file doesn't include the libsecp256k1 C sources
36+
go_deps.module_override(
37+
patch_strip = 1,
38+
patches = ["//patches:libevm_secp256k1.patch"],
39+
path = "github.com/ava-labs/libevm",
40+
)
41+
42+
# Disable gazelle for blst and use custom BUILD file via patch
43+
# blst has complex CGO with assembly that gazelle cannot handle automatically
44+
# The patch creates BUILD.bazel from /dev/null (new file) based on Prysm's blst.BUILD
45+
go_deps.gazelle_override(
46+
build_file_generation = "off",
47+
path = "github.com/supranational/blst",
48+
)
49+
go_deps.module_override(
50+
patch_strip = 1,
51+
patches = ["//patches:blst_build.patch"],
52+
path = "github.com/supranational/blst",
53+
)
54+
55+
# Use purego build tag for gnark-crypto to avoid assembly include path issues
56+
# gnark-crypto's assembly files use cross-package #include which Bazel doesn't support
57+
# The purego implementation is slower but avoids the complex assembly setup
58+
go_deps.gazelle_override(
59+
directives = [
60+
"gazelle:build_tags purego",
61+
],
62+
path = "github.com/consensys/gnark-crypto",
63+
)
64+
65+
# Fix firewood-go-ethhash FFI to use cc_import for pre-built static libraries
66+
# The gazelle-generated BUILD uses -L paths that don't work in Bazel sandbox
67+
go_deps.gazelle_override(
68+
build_file_generation = "off",
69+
path = "github.com/ava-labs/firewood-go-ethhash/ffi",
70+
)
71+
go_deps.module_override(
72+
patch_strip = 1,
73+
patches = ["//patches:firewood_ffi.patch"],
74+
path = "github.com/ava-labs/firewood-go-ethhash/ffi",
75+
)
76+
77+
# Additional dependencies from graft/coreth/go.mod that aren't in the main go.mod
78+
go_deps.module(
79+
path = "github.com/ava-labs/firewood-go-ethhash/ffi",
80+
sum = "h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY=",
81+
version = "v0.0.15",
82+
)
83+
go_deps.module(
84+
path = "github.com/go-cmd/cmd",
85+
sum = "h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y=",
86+
version = "v1.4.3",
87+
)
88+
go_deps.module(
89+
path = "github.com/google/go-cmp",
90+
sum = "h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=",
91+
version = "v0.7.0",
92+
)
93+
use_repo(
94+
go_deps,
95+
"com_connectrpc_connect",
96+
"com_connectrpc_grpcreflect",
97+
"com_github_antithesishq_antithesis_sdk_go",
98+
"com_github_ava_labs_avalanchego_graft_coreth",
99+
"com_github_ava_labs_firewood_go_ethhash_ffi",
100+
"com_github_ava_labs_libevm",
101+
"com_github_ava_labs_simplex",
102+
"com_github_ava_labs_subnet_evm",
103+
"com_github_btcsuite_btcd_btcutil",
104+
"com_github_cespare_xxhash_v2",
105+
"com_github_cockroachdb_pebble",
106+
"com_github_compose_spec_compose_go",
107+
"com_github_datadog_zstd",
108+
"com_github_davecgh_go_spew",
109+
"com_github_deckarep_golang_set_v2",
110+
"com_github_decred_dcrd_dcrec_secp256k1_v4",
111+
"com_github_go_cmd_cmd",
112+
"com_github_google_btree",
113+
"com_github_google_go_cmp",
114+
"com_github_google_renameio_v2",
115+
"com_github_google_uuid",
116+
"com_github_gorilla_mux",
117+
"com_github_gorilla_rpc",
118+
"com_github_gorilla_websocket",
119+
"com_github_grpc_ecosystem_go_grpc_prometheus",
120+
"com_github_hashicorp_go_bexpr",
121+
"com_github_hashicorp_golang_lru",
122+
"com_github_holiman_billy",
123+
"com_github_holiman_bloomfilter_v2",
124+
"com_github_holiman_uint256",
125+
"com_github_huin_goupnp",
126+
"com_github_jackpal_gateway",
127+
"com_github_jackpal_go_nat_pmp",
128+
"com_github_leanovate_gopter",
129+
"com_github_mattn_go_colorable",
130+
"com_github_mattn_go_isatty",
131+
"com_github_mitchellh_mapstructure",
132+
"com_github_mr_tron_base58",
133+
"com_github_nbutton23_zxcvbn_go",
134+
"com_github_onsi_ginkgo_v2",
135+
"com_github_pires_go_proxyproto",
136+
"com_github_prometheus_client_golang",
137+
"com_github_prometheus_client_model",
138+
"com_github_prometheus_common",
139+
"com_github_rs_cors",
140+
"com_github_shirou_gopsutil",
141+
"com_github_spf13_cast",
142+
"com_github_spf13_cobra",
143+
"com_github_spf13_pflag",
144+
"com_github_spf13_viper",
145+
"com_github_stephenbuttolph_canoto",
146+
"com_github_stretchr_testify",
147+
"com_github_supranational_blst",
148+
"com_github_syndtr_goleveldb",
149+
"com_github_thepudds_fzgen",
150+
"com_github_tyler_smith_go_bip39",
151+
"com_github_urfave_cli_v2",
152+
"com_github_victoriametrics_fastcache",
153+
"in_gopkg_natefinch_lumberjack_v2",
154+
"in_gopkg_yaml_v3",
155+
"io_k8s_api",
156+
"io_k8s_apimachinery",
157+
"io_k8s_client_go",
158+
"io_k8s_utils",
159+
"io_opentelemetry_go_otel",
160+
"io_opentelemetry_go_otel_exporters_otlp_otlptrace",
161+
"io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracegrpc",
162+
"io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracehttp",
163+
"io_opentelemetry_go_otel_sdk",
164+
"io_opentelemetry_go_otel_trace",
165+
"org_golang_google_genproto_googleapis_rpc",
166+
"org_golang_google_grpc",
167+
"org_golang_google_protobuf",
168+
"org_golang_x_crypto",
169+
"org_golang_x_exp",
170+
"org_golang_x_net",
171+
"org_golang_x_sync",
172+
"org_golang_x_term",
173+
"org_golang_x_time",
174+
"org_golang_x_tools",
175+
"org_gonum_v1_gonum",
176+
"org_uber_go_goleak",
177+
"org_uber_go_mock",
178+
"org_uber_go_zap",
179+
)

0 commit comments

Comments
 (0)