Last active
June 4, 2021 14:19
-
-
Save jayconrod/bc72d5946cbe120f6f67e38625535742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To set up the Go repo | |
git clone https://go.googlesource.com/go | |
cd go | |
git checkout dev.typeparams | |
cd src | |
./make.bash | |
Use that directory with go_local_sdk in WORKSPACE. | |
-- WORKSPACE -- | |
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | |
http_archive( | |
name = "io_bazel_rules_go", | |
sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b", | |
urls = [ | |
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", | |
"https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", | |
], | |
) | |
load("@io_bazel_rules_go//go:deps.bzl", "go_local_sdk", "go_register_toolchains", "go_rules_dependencies") | |
go_rules_dependencies() | |
go_local_sdk( | |
name = "go_sdk", | |
path = "/Users/jayconrod/goroot", | |
) | |
go_register_toolchains() | |
-- BUILD.bazel -- | |
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | |
go_binary( | |
name = "hello", | |
embed = [":hello_lib"], | |
visibility = ["//visibility:public"], | |
) | |
go_library( | |
name = "hello_lib", | |
srcs = ["hello.go"], | |
gc_goopts = ["-G=3"], | |
importpath = "example.com/hello", | |
visibility = ["//visibility:private"], | |
deps = ["//length"], | |
) | |
-- hello.go -- | |
package main | |
import ( | |
"fmt" | |
"length" | |
) | |
func main() { | |
a := []string{"a", "b"} | |
b := []int{1, 2, 3, 4} | |
fmt.Println(length.Len(a)) | |
fmt.Println(length.Len(b)) | |
} | |
-- length/BUILD.bazel -- | |
load("@io_bazel_rules_go//go:def.bzl", "go_library") | |
go_library( | |
name = "length", | |
srcs = ["length.go"], | |
gc_goopts = ["-G=3"], | |
importpath = "length", | |
visibility = ["//visibility:public"], | |
) | |
-- length/length.go -- | |
package length | |
func Len[T any](s []T) int { | |
return len(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment