Gazelle is VERY helpful. Here are helpful links to use it
- Updating build files from go.mod file: https://github.com/bazelbuild/bazel-gazelle#update-repos
From a mod file:
bazel run //:gazelle -- update-repos -from_file=04_bazel_java2go_starlark_dlls/go.mod
Install a package
go get github.com/golang/protobuf/proto
go get github.com/golang/protobuf/proto@vX.Y.Z
- Dynamically linked libraries seem like a great way to do interprocess communication
- The types available for transferring data in between are primitive. It might be good to use protbufs and use file descriptors to transfer data in between
- protobufs and strings seem like a greate way to transfer data. The domain is shared
You have to run gazelle without update repos for it to work with generating build files bazel run //:gazelle
.
You have to run gazelle with the repos option to update the dependencies automagically bazel run //:gazelle -- update-repos -from_file=go.mod
.
The golang server is slow sometimes it looks like. Give it a second to quit throwing a tantrum and it will probably correct its deps.
Domain driven development is what golang suggests (but not needed, you can structure your project however).
go get google.golang.org/protobuf/proto
is the way to import protobufs...
Autogenerated build files > not autogenerated build files :) BUT, it's okay if some folders aren't autogenerated. You can fix them yourself. Gazelle will help as much as it can.
DELETE GENERATED BUILD FILES IF YOU CHANGE THE DIR NAME, gazelle won't fix these it looks like
Helpful example for protos in java and go: https://github.com/protocolbuffers/protobuf/blob/master/examples/addressbook.proto
Remove the third party folder from the bazells repo, not necessary... Is more like baggage.
Apparently there are a few issues with incorporating bazel with golang, particularly bazel doesn't recognize generated proto files from bazel
It may be worth just using the protoc command to generate protofiles. It's more easy to type. A command similar to protoc --proto_path=IMPORT_PATH --cpp_out=DST_DIR --java_out=DST_DIR --python_out=DST_DIR --go_out=DST_DIR --ruby_out=DST_DIR --objc_out=DST_DIR --csharp_out=DST_DIR path/to/file.proto
could be added to a shell script. Maybe gen.sh. This might need to remove the bazel gazelle autogen rules. More info here
Left off here
- Maybe setup a new project with bare bones simplicity. One directory, flat structure, simple proto file, generate the files using protoc.
- Spin up two programs, java client and server, communicate between the two.
Could possibly switch over to go to make an LSP? https://pkg.go.dev/github.com/sourcegraph/go-lsp
# The shared libs
go_library(
name = "bridge",
srcs = [
"hello.go",
],
importpath = "github.com/josiahsrc/bazel_playground/04_bazel_java2go_starlark_dlls/lib",
)
# This is a statically linked binary and can be referenced with archive.cc
go_binary(
name = "archive",
cgo = True,
embed = [
":bridge",
],
linkmode = "c-archive",
)