-
Notifications
You must be signed in to change notification settings - Fork 12
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
implement bazel as build system #568
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this was generated using gazelle, which is very convenient to work with especially for Go repos (@lunaris didn't find it as nice for python).
There's a few commands that are useful to know for bazel:
bazel build //...
- builds the whole repo, and leaves the artifacts in abazel-bin
directory.bazel test //...
- run all the tests. That's probably the most convenient command for this repo at all times, but we can specify subparts of the repo as well, e.g.bazel test //pkg/pulumiyaml/codegen
to run only the codegen testsbazel run //:gazelle
- re-runs gazelle, and updates the BUILD files. This is most useful when new files are added or removed.bazel run //:gazelle-update-repos
- this has to be run after updating the dependencies in the go.mod file, and it will update all the dependencies bazel sees (those are specified specially in thedeps.bzl
file, separate fromgo.mod
andgo.sum
, this command can essentially be thought of as "sync go.mod to deps.bzl")
@@ -0,0 +1,58 @@ | |||
diff --git a/dh/x25519/BUILD.bazel b/dh/x25519/BUILD.bazel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cloudflare library doesn't compile correctly with the bazel build files it generations, so it needs this little patch to build.
@@ -2,51 +2,52 @@ module github.com/pulumi/pulumi-yaml | |||
|
|||
go 1.19 | |||
|
|||
replace github.com/hashicorp/vault/api v1.8.2 => github.com/hashicorp/vault/api v1.9.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github.com/hashicorp/vault/api v1.8.2 doesn't compile correctly, v1.9.0 has the fixes.
@@ -2,51 +2,52 @@ module github.com/pulumi/pulumi-yaml | |||
|
|||
go 1.19 | |||
|
|||
replace github.com/hashicorp/vault/api v1.8.2 => github.com/hashicorp/vault/api v1.9.0 | |||
|
|||
replace google.golang.org/protobuf v1.33.0 => google.golang.org/protobuf v1.31.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most awkward think imho about this whole PR. The protobuf 1.33.0 library causes a circular dependency, so we need to downgrade here.
go.mod
Outdated
github.com/pulumi/pulumi/pkg/v3 v3.112.1-0.20240415121624-fc23f9bb0851 | ||
github.com/pulumi/pulumi/sdk/v3 v3.112.1-0.20240415121624-fc23f9bb0851 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just waiting until v3.114.0 gets released, which includes pulumi/pulumi#15936, which is necessary for the tests to work.
@@ -29,11 +28,11 @@ resources: | |||
assert.False(t, diags.HasErrors()) | |||
|
|||
got := plugins | |||
want := autogold.Want("test-plugins", []Plugin{{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autogold
librarry doesn't work with bazel. I don't feel like its usage is crucial anywhere we have it, the couple of places we're using it are barely worth having the extra dependency, especially because this shouldn't change frequently anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:'(
I love snapshot testing. Why does this not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the same reason this change is needed: #568 (comment)
Bazel creates a separate directory structure with symlinks to the original files to run the tests. So autogold
can't copy the file back to the repo. Note that we can still work the whole PULUMI_ACCEPT
thing work via just running the tests via the normal Go tooling, just the autogold
library wants to doesn't like the symlinks even when it's not supposed to change anything for some reason.
@@ -409,10 +429,12 @@ outputs: | |||
func TestAssetOrArchive(t *testing.T) { | |||
t.Parallel() | |||
|
|||
const text = `name: test-yaml | |||
file := createTestFile(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel symlinks all files to its own directory structure, to be able to know the exact inputs for each build. In this particular case, if we have a symlink pulumi-yaml tries to follow it, and then realizes that it's outside of the directory we're working in, and errors out. We're generating a test file here instead, which seems no worse than relying on the readme here.
@@ -51,7 +57,7 @@ for s in "${schemas[@]}"; do | |||
URL="${URL//_VERSION_/${VERSION}}" | |||
|
|||
|
|||
FILEPATH="pkg/pulumiyaml/testing/test/testdata/${NAME}-${VERSION}.json" | |||
FILEPATH="${dir}pkg/pulumiyaml/testing/test/testdata/${NAME}-${VERSION}.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are not generated in the source tree anymore, but in the bazel directory structure, and thus we need to allow bazel to tell us where that is. The script will still work as it is.
Use bazel as build system. Right now it's working side by side with the old Makefiles, and we're adding an extra CI job to run the builds. Eventually this can completely replace the Makefile based builds.
name = "examples", | ||
srcs = glob(["examples/**"]), | ||
visibility = ["//visibility:public"], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these filegroup
s? Apologies if I'm missing where they are used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, these are used as testdata (examples
here: https://github.com/pulumi/pulumi-yaml/pull/568/files/3faa6f2aa177fbe335417c7e28e361a950ecff86#diff-4f92936bcd4ef2a410b5b8690f0ce55344be249565741c2e27e63dab4c18e76cR31, README
and go_mod
here: https://github.com/pulumi/pulumi-yaml/pull/568/files/3faa6f2aa177fbe335417c7e28e361a950ecff86#diff-c980a768eafaa33a15061ead8b5880713599b0d408b918e930b94464611e6086R61)
MODULE.bazel
Outdated
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. | ||
# | ||
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 | ||
############################################################################### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably delete this comment and leave the file empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✔️
|
||
load("@rules_python//python:repositories.bzl", "py_repositories") | ||
|
||
py_repositories() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is rules_python
being used in this workspace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used by protobuf apparently. If I remove this protobuf complains about not being able to find python rules. Not sure why exactly that is and it doesn't specify it itself.
build/0001-cloudflare.patch
Outdated
"table.go", | ||
+ "//math/fp25519:fp_amd64.h", | ||
], | ||
+ cgo = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff here is quite large - does this reenable CGO_ENABLED writ large? Can we avoid that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CGO_ENABLED writ large
Not sure what you mean with this?
This enables CGO for this library. I don't know Go tooling enough to know whether that transitively enables it in the dependent libraries though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just trying to page in why this was needed in the first place, it's just that gazelle (which also generates build files for external dependencies) just doesn't deal with the CGO structure of this particular dependency properly. The library needs to be build with CGO either way, so that shouldn't change anything here I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand this - this library requires CGO but the rest of the binary build won't?
Maybe I don't understand how that could work with Go.
I do think we should not regress and switch to CGO_ENABLED builds, it makes cross compilation much more challenging and as Go developers say, CGO is not go. There are downsides to CGO_ENABLED=1, and we finally extricated ourselves from that a year or so ago. Going back will lead to surprises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually turns out the cgo = True
was not actually needed, and I just copy-pasta'd too much stuff from the internet 😅
I do think this needs a little bit of additional patching to make it work on non-linux platforms, but that should be fairly straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As someone who hacks on multiple Pulumi repos frequently, my biggest concern is that this could make that more difficult if I currently use Go Workspaces. It seems like we'd need to keep the makefile and have two build systems to make that work.
Similar to that though, this appears to tightly couple bazel files to source filenames in this and other repos - that seems really tough to keep in sync. Is there a way to use wildcards or some mechanism so that adding new source files to packages in Pulumi YAML and others doesn't affect Bazel? Or if those src files are not tightly coupled, do we need to commit them?
go_library( | ||
name = "pulumiyaml", | ||
srcs = [ | ||
"analyser.go", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to more loosely couple this? It seems strange to require this here. Or, if these files are auto generated (by Gazelle?): should they be committed or gitignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel does support glob
so e.g. srcs = glob(["**/*.go"])
could be used here. Currently these are I believe generated by Gazelle, so I expect it's a choice of "do we want to maintain BUILD.bazel
files ourselves" (use glob
, don't use Gazelle) or "do we want to try and pretend we're 'just writing Go' and use Gazelle to generate BUILD.bazel
files".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could still use glob
s, gazelle will actually support that just fine and not overwrite it, it's pretty smart that way! Similarly, I had to adjust the data
passed to tests in a few places. So the build files are mostly auto-generated, but they need to be tweaked by hand, because we are not always following the standard convention, so gazelle can't generate that for you.
In a way I didn't bother with globs, exactly because I expect it's easiest to just use Gazelle to write these build files for us. This is an extra command to run, but that seems like a worthy tradeoff for having faster and correct builds
I'm really curious what your workflow for this is! Do you have a One of the major advantages of Bazel (not necessarily in this repo, but once we have more repos set up with it) is that it supports multiple languages. E.g. currently |
Yeah, I use a go.work file in a parent directory to all of my GitHub packages - though I will sometimes need to set
And as a result, everything I expect works in my dev tools, including (importantly) running go-to-definition, tests, process debugging. I can |
This will continue working with or without the makefiles. There's no changes in the Go tooling here, and I expect us to be able to continue running tests outside of the build system similar to how that's currently possible. In fact Gazelle expects the repo to follow the Go conventions to work, so there's no issue here. The only difference would be here:
|
That's a relief and I appreciate your humoring my questions! Just want to make sure I understand the limitations, if any. Re: make install changing, it sounds like, however, for end to end testing - building Pulumi YAML and Pulumi CLI using my workspace source - this might not work as expected? Or I would need to learn the "bazel way" to link together multiple modules from source? |
For sure, I definitely don't want to break anyones workflow, or at the very least make sure there's an easy transition.
Ah interesting, I hadn't considered building it that way tbh. I don't think this would work out of the box as it does right now, but before we consider removing the |
Yeah, it's very common - because of Pulumi's distributed system nature - that we need to make cross-cutting changes to the Go Pulumi/Pulumi SDK module that affect both the engine and a plugin. |
Use bazel as build system. Right now it's working side by side with the old Makefiles, and we're adding an extra CI job to run the builds. Eventually this can completely replace the Makefile based builds.
(I'll comment inline on some of the changes required for this)