Skip to content

A demo of trouble I'm having trying to get bzlmod and go to play nicely.

Notifications You must be signed in to change notification settings

bdleitner/golang_bzlmod_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BzlMod + Golang Demo

This repo contains projects that demo the difficulties/errors I'm seeing when trying to get started with bzlmod and golang. Each subfolder here is its own project (in my local system, I have separate Goland projects for each one).

  • greetings - a simple module intended for use inside hello
  • hello - a module that has an external, local depdency on greetings
  • simpleproto - A simple module that uses go_proto_library but doesn't depend on the golang proto package and its external dependency.
  • protoexp - An example that does depend on the external proto package.
  • cgo - An example of bazel build not being able to find symbols in a library that uses cgo.
  • cgoimport - An example of not being able to use an external library that uses cgo due to "undefined symbols." Note: I found this issue before trying the cgo demo directly and this was the inspiration for that.

I've been trying to migrate my existing messy Golang code library from plain bazel to use bzlmod.

I found the rules_go bzlmod reference and was trying to use that as a tutorial. I don' thave much experience with modules using go.mod, so at first I was avoiding it and just using my local regsitry to point at the different workspaces. This worked mostly* ok until I finally had some external dependencies.

  • "mostly" - Goland would report on an import from a different workspace that build constraints eliminated all go files from the foreign package, even though I'm not using build constraints anywhere... at least I never set any up.

So next I decided to take the plunge and use the recommended tooling to work with go modules. But that didn't work as I wasn't able to get things to build correctly: bazel build would fail saying that the dependent module didn't have the right package.

That led me to some searches on how to use modules more generally, and so I found this tutorial. So I figured I should be able to use that but modify it to use bzlmod.

So I created the greetings and hello modules to test drive that. See the hello README for the results there.

Then, later, I decided that maybe if I couldn't get "local" external dependencies to work, maybe if I could get normal ones to work I could just have one monolithic golang project. It's not what I'd like, but it could work. I ran into trouble with the first time I needed an external depdency.

About

A demo of trouble I'm having trying to get bzlmod and go to play nicely.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published