1*9bb1b549SSpandan Das# Load the http ruleset and expose the http_archive rule 2*9bb1b549SSpandan Dasload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3*9bb1b549SSpandan Das 4*9bb1b549SSpandan Das# Download rules_go ruleset. 5*9bb1b549SSpandan Das# Bazel makes a https call and downloads the zip file, and then 6*9bb1b549SSpandan Das# checks the sha. 7*9bb1b549SSpandan Dashttp_archive( 8*9bb1b549SSpandan Das name = "io_bazel_rules_go", 9*9bb1b549SSpandan Das sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f", 10*9bb1b549SSpandan Das urls = [ 11*9bb1b549SSpandan Das "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", 12*9bb1b549SSpandan Das "https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", 13*9bb1b549SSpandan Das ], 14*9bb1b549SSpandan Das) 15*9bb1b549SSpandan Das 16*9bb1b549SSpandan Das# Download the bazel_gazelle ruleset. 17*9bb1b549SSpandan Dashttp_archive( 18*9bb1b549SSpandan Das name = "bazel_gazelle", 19*9bb1b549SSpandan Das sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", 20*9bb1b549SSpandan Das urls = [ 21*9bb1b549SSpandan Das "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", 22*9bb1b549SSpandan Das "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", 23*9bb1b549SSpandan Das ], 24*9bb1b549SSpandan Das) 25*9bb1b549SSpandan Das 26*9bb1b549SSpandan Das# Load rules_go ruleset and expose the toolchain and dep rules. 27*9bb1b549SSpandan Dasload("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") 28*9bb1b549SSpandan Das 29*9bb1b549SSpandan Das# the line below instructs gazelle to save the go dependency definitions 30*9bb1b549SSpandan Das# in the deps.bzl file. Located under '//'. 31*9bb1b549SSpandan Dasload("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") 32*9bb1b549SSpandan Das 33*9bb1b549SSpandan Das############################################################ 34*9bb1b549SSpandan Das# Define your own dependencies here using go_repository. 35*9bb1b549SSpandan Das# Else, dependencies declared by rules_go/gazelle will be used. 36*9bb1b549SSpandan Das# The first declaration of an external repository "wins". 37*9bb1b549SSpandan Das############################################################ 38*9bb1b549SSpandan Das 39*9bb1b549SSpandan Das# The following line defines the symbol go_dependencies from the deps.bzl file. 40*9bb1b549SSpandan Das# Having the deps in that file, helps the WORKSPACE file stay less 41*9bb1b549SSpandan Das# cluttered. The library symbol go_dependencies is then added to 42*9bb1b549SSpandan Das# the envionment. The line below calls that function. 43*9bb1b549SSpandan Dasload("//:deps.bzl", "go_dependencies") 44*9bb1b549SSpandan Das 45*9bb1b549SSpandan Das# The next comment line includes a macro that gazelle reads. 46*9bb1b549SSpandan Das# This macro tells Gazelle to look for repository rules in a macro in a .bzl file, 47*9bb1b549SSpandan Das# and allows Gazelle to find the correct file to maintain the Go dependencies. 48*9bb1b549SSpandan Das# Then the line after the comment calls go_dependencies(), and that funcation 49*9bb1b549SSpandan Das# contains calls to various go_repository rules. 50*9bb1b549SSpandan Das 51*9bb1b549SSpandan Das# gazelle:repository_macro deps.bzl%go_dependencies 52*9bb1b549SSpandan Dasgo_dependencies() 53*9bb1b549SSpandan Das 54*9bb1b549SSpandan Das# go_rules_dependencies is a function that registers external dependencies 55*9bb1b549SSpandan Das# needed by the Go rules. 56*9bb1b549SSpandan Das# https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#go_rules_dependencies 57*9bb1b549SSpandan Dasgo_rules_dependencies() 58*9bb1b549SSpandan Das 59*9bb1b549SSpandan Das# The next rule installs the Go toolchains. The Go version is specified 60*9bb1b549SSpandan Das# using the version parameter. This rule will download the Go SDK. 61*9bb1b549SSpandan Das# https://github.com/bazelbuild/rules_go/blob/master/go/toolchains.rst#go_register_toolchains 62*9bb1b549SSpandan Dasgo_register_toolchains(version = "1.20.2") 63*9bb1b549SSpandan Das 64*9bb1b549SSpandan Das# The following call configured the gazelle dependencies, Go environment and Go SDK. 65*9bb1b549SSpandan Dasgazelle_dependencies() 66