Skip to content

Commit fb07a24

Browse files
feat: add an example bazel module + go binary using the library
This is mostly so that I can add it as the test module to be used in the bazel registry presubmit
1 parent 2a263bf commit fb07a24

10 files changed

+96
-5
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
cpp-jsonnet
2+
examples/bazel

.gitignore

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ coverage.out
88
build/
99
dist/
1010
gojsonnet.egg-info/
11-
/bazel-bin
12-
/bazel-genfiles
13-
/bazel-go-jsonnet
14-
/bazel-out
15-
/bazel-testlogs
11+
bazel-*
1612
/dumpstdlibast
1713

1814
# built binaries

examples/bazel/.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
common --lockfile_mode=off

examples/bazel/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MODULE.bazel.lock

examples/bazel/BUILD.bazel

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@gazelle//:def.bzl", "gazelle")
2+
load("@rules_go//go:def.bzl", "go_binary", "go_library")
3+
4+
gazelle(name = "gazelle")
5+
6+
go_library(
7+
name = "use_go_jsonnet_lib",
8+
srcs = ["use_go_jsonnet.go"],
9+
importpath = "github.com/google/go-jsonnet/examples/bazel",
10+
visibility = ["//visibility:private"],
11+
deps = ["@com_github_google_go_jsonnet//:go_default_library"],
12+
)
13+
14+
go_binary(
15+
name = "use_go_jsonnet",
16+
embed = [":use_go_jsonnet_lib"],
17+
visibility = ["//visibility:public"],
18+
)

examples/bazel/MODULE.bazel

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
bazel_dep(name = "gazelle", version = "0.42.0")
2+
bazel_dep(name = "rules_go", version = "0.53.0")
3+
bazel_dep(name = "jsonnet_go")
4+
local_path_override(
5+
module_name = "jsonnet_go",
6+
path = "../..",
7+
)
8+
9+
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
10+
go_sdk.download(version = "1.23.7")
11+
12+
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
13+
go_deps.from_file(go_mod = "//:go.mod")
14+
use_repo(
15+
go_deps,
16+
"com_github_google_go_jsonnet",
17+
)
18+
19+
override_repo(
20+
go_deps,
21+
com_github_google_go_jsonnet = "jsonnet_go",
22+
)

examples/bazel/example.jsonnet

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local Person(name='Alice') = {
2+
name: name,
3+
welcome: 'Hello ' + name + '!',
4+
};
5+
{
6+
person1: Person(),
7+
person2: Person('Bob'),
8+
}

examples/bazel/go.mod

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module example/go-jsonnet-using-bazel
2+
3+
go 1.23.7
4+
5+
require github.com/google/go-jsonnet v0.21.0-rc2
6+
7+
require (
8+
golang.org/x/crypto v0.36.0 // indirect
9+
golang.org/x/sys v0.31.0 // indirect
10+
sigs.k8s.io/yaml v1.4.0 // indirect
11+
)
12+
13+
replace github.com/google/go-jsonnet => ../../

examples/bazel/go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
2+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3+
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
4+
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
5+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
6+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
7+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
8+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11+
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
12+
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

examples/bazel/use_go_jsonnet.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
gjs "github.com/google/go-jsonnet"
7+
)
8+
9+
func main() {
10+
fmt.Printf("Example using go jsonnet (%s)\n", gjs.Version())
11+
12+
vm := gjs.MakeVM()
13+
out, err := vm.EvaluateFile("example.jsonnet")
14+
if err != nil {
15+
fmt.Printf("%v\n", err)
16+
} else {
17+
fmt.Printf("%s", out)
18+
}
19+
}

0 commit comments

Comments
 (0)