Skip to content

use bazel 8 (bzlmod migration) #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.x
8.x
4 changes: 2 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("@gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/fizzbee-io/fizzbee
gazelle(name = "gazelle")
Expand Down
52 changes: 46 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
module(name = "fizzbee")

# Go with gazelle see https://github.com/bazel-contrib/rules_go/blob/master/docs/go/core/bzlmod.md
bazel_dep(name = "rules_go", version = "0.46.0")
bazel_dep(name = "gazelle", version = "0.34.0")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.4")

# External go deps
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

# run "bazel mod tidy" to update these after updating go.mod
use_repo(
go_deps,
"com_github_golang_glog",
"com_github_huandu_go_clone",
"com_github_stretchr_testify",
"in_gopkg_yaml_v3",
"net_starlark_go",
"org_golang_google_protobuf",
"org_golang_x_sys",
)

# Proto
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(
name = "protobuf",
version = "26.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously we were using 25.2 but that doesn't exist on bazel central

repo_name = "com_google_protobuf",
)

# Python
bazel_dep(name = "rules_python", version = "1.0.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.12", is_default = True)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.12",
requirements_lock = "//third_party:requirements_lock.txt",
)
use_repo(pip, "pypi")
3,918 changes: 3,880 additions & 38 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

143 changes: 0 additions & 143 deletions WORKSPACE

This file was deleted.

19 changes: 18 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
module github.com/fizzbee-io/fizzbee

go 1.22
go 1.22.4

require (
github.com/golang/glog v1.2.0
github.com/huandu/go-clone v0.0.0
github.com/stretchr/testify v1.8.4
go.starlark.net v0.0.0-20231121155337-90ade8b19d09
golang.org/x/sys v0.17.0
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)

replace github.com/huandu/go-clone => github.com/jayaprabhakar/go-clone v0.0.0-20240501195431-177708839df4
4 changes: 2 additions & 2 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "lib",
Expand All @@ -20,7 +20,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//proto",
"@com_github_jayaprabhakar_go_clone//:go-clone",
"@com_github_huandu_go_clone//:go-clone",
"@in_gopkg_yaml_v3//:yaml_v3",
"@net_starlark_go//lib/math",
"@net_starlark_go//starlark",
Expand Down
4 changes: 2 additions & 2 deletions lib/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package lib

import (
"encoding/json"
"github.com/jayaprabhakar/go-clone"
"sync"

"github.com/huandu/go-clone"
)

type Stack[T any] struct {
Expand Down Expand Up @@ -132,6 +133,5 @@ func (s *Stack[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(s.s)
}


// Ensures Queue implements LinearCollection
var _ LinearCollection[interface{}] = (*(Stack[interface{}]))(nil)
4 changes: 2 additions & 2 deletions modelchecker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "modelchecker",
Expand All @@ -25,7 +25,7 @@ go_library(
"//proto",
"//proto:options",
"@com_github_golang_glog//:glog",
"@com_github_jayaprabhakar_go_clone//:go-clone",
"@com_github_huandu_go_clone//:go-clone",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tekumara One reason I had to fork the cloning library was it was missing a feature to override pointer references.
huandu/go-clone#23

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still using your fork - see the replace statement in go.mod

I had to do it like this to make go.mod work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming bazel honours this but admittedly I haven't tested this - is there a way to test this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

"@org_golang_google_protobuf//encoding/protojson:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
"@net_starlark_go//starlark",
Expand Down
10 changes: 6 additions & 4 deletions modelchecker/clonehelper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package modelchecker

import (
"github.com/fizzbee-io/fizzbee/lib"
"github.com/jayaprabhakar/go-clone"
"go.starlark.net/starlark"
"reflect"
"unsafe"

"github.com/fizzbee-io/fizzbee/lib"
"github.com/huandu/go-clone"
"go.starlark.net/starlark"
)

func init() {
Expand All @@ -29,6 +30,7 @@ func init() {
}

const sizeOfPointers = unsafe.Sizeof((interface{})(0)) / unsafe.Sizeof(uintptr(0))

// interfaceData is the underlying data of an interface.
// As the reflect.Value's interfaceData method is deprecated,
// it may be broken in any Go release.
Expand All @@ -42,6 +44,7 @@ type interfaceData struct {
}

var typeOfInterface = reflect.TypeOf((*interface{})(nil)).Elem()

// forceClearROFlag clears all RO flags in v to make v accessible.
// It's a hack based on the fact that InterfaceData is always available on RO data.
// This hack can be broken in any Go version.
Expand Down Expand Up @@ -79,7 +82,6 @@ func parseReflectValue(v reflect.Value) interfaceData {
return *(*interfaceData)(ptr)
}


func roleResolveCloneFn(refs map[string]*lib.Role, permutations map[lib.SymmetricValue][]lib.SymmetricValue, alt int) func(allocator *clone.Allocator, old reflect.Value, new reflect.Value) {
return func(allocator *clone.Allocator, old, new reflect.Value) {

Expand Down
23 changes: 12 additions & 11 deletions modelchecker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ import (
"encoding/json"
ast "fizz/proto"
"fmt"
"github.com/fizzbee-io/fizzbee/lib"
"github.com/jayaprabhakar/go-clone"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
"go.starlark.net/syntax"
"google.golang.org/protobuf/proto"
"log"
"maps"
"math/rand"
Expand All @@ -36,6 +30,13 @@ import (
"strings"
"sync"
"time"

"github.com/fizzbee-io/fizzbee/lib"
"github.com/huandu/go-clone"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
"go.starlark.net/syntax"
"google.golang.org/protobuf/proto"
)

// DefType is a custom enum-like type
Expand Down Expand Up @@ -1545,8 +1546,8 @@ func (p *Processor) ExceedsActionCountLimits(action *ast.Action, statProcess *Pr
concurrentStats[name]++
nameParts := strings.Split(name, ".")
if len(nameParts) > 1 && rootFrame.obj != nil {
concurrentStats[nameParts[0] + "#." + nameParts[1]]++
concurrentStats[rootFrame.obj.RefStringShort() + "." + nameParts[1]]++
concurrentStats[nameParts[0]+"#."+nameParts[1]]++
concurrentStats[rootFrame.obj.RefStringShort()+"."+nameParts[1]]++
}
}
//fmt.Println("Concurrent stats", concurrentStats, actionName, concurrentStats[actionName], p.config.ActionOptions[actionName])
Expand All @@ -1561,9 +1562,9 @@ func (p *Processor) ExceedsActionCountLimits(action *ast.Action, statProcess *Pr
if role == nil {
return false
}
if p.config.ActionOptions[role.Name + "#." + action.Name] != nil {
perRoleActionLimit := p.config.ActionOptions[role.Name + "#." + action.Name].MaxActions
perRoleActionConcurrency := p.config.ActionOptions[role.Name + "#." + action.Name].GetMaxConcurrentActions()
if p.config.ActionOptions[role.Name+"#."+action.Name] != nil {
perRoleActionLimit := p.config.ActionOptions[role.Name+"#."+action.Name].MaxActions
perRoleActionConcurrency := p.config.ActionOptions[role.Name+"#."+action.Name].GetMaxConcurrentActions()
//fmt.Println("Per role action limit", role.Name + "#." + action.Name, perRoleActionLimit)
if int(perRoleActionLimit) > 0 && statProcess.Stats.Counts[actionName] >= int(perRoleActionLimit) {
return true
Expand Down
2 changes: 1 addition & 1 deletion parser/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@my_deps//:requirements.bzl", "requirement")
load("@pypi//:requirements.bzl", "requirement")

py_library(
name = "fizz",
Expand Down
2 changes: 1 addition & 1 deletion performance/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@my_deps//:requirements.bzl", "requirement")
load("@pypi//:requirements.bzl", "requirement")

py_library(
name = "performance",
Expand Down
4 changes: 2 additions & 2 deletions proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@rules_go//go:def.bzl", "go_library")
load("@rules_go//proto:def.bzl", "go_proto_library")
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")

proto_library(
Expand Down