diff --git a/.bazelrc b/.bazelrc index deff2fa8a..8f70af802 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,9 +1,3 @@ -# Sadly, some Bazel rules we depend on have no support for bzlmod yet -# Here is an (incomplete) list of rules known to not support bzlmod. -# Please extend this list as you find more. -# - rules_nixpkgs: https://github.com/tweag/rules_nixpkgs/issues/181 -common --noenable_bzlmod - # Import bazelrc presets import %workspace%/bazel/bazelrc/bazel7.bazelrc import %workspace%/bazel/bazelrc/convenience.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel index b2443e4b5..6e09ef814 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,5 @@ exports_files([ - "WORKSPACE.bazel", + "WORKSPACE.bzlmod", ]) alias( diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..05e5c1465 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1 @@ +module(name = "constellation") diff --git a/WORKSPACE.bazel b/WORKSPACE.bzlmod similarity index 96% rename from WORKSPACE.bazel rename to WORKSPACE.bzlmod index 45eff59e0..aea2883be 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bzlmod @@ -1,5 +1,10 @@ workspace(name = "constellation") +# Sadly, some Bazel rules we depend on have no support for bzlmod yet +# Here is an (incomplete) list of rules known to not support bzlmod. +# Please extend this list as you find more. +# - rules_nixpkgs: https://github.com/tweag/rules_nixpkgs/issues/181 + load("//bazel/toolchains:skylib_deps.bzl", "skylib_deps") skylib_deps() @@ -179,7 +184,7 @@ go_register_toolchains() load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel") +gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bzlmod") # gazelle:repo bazel_gazelle diff --git a/bazel/ci/BUILD.bazel b/bazel/ci/BUILD.bazel index 44e1c89c2..10c926ef9 100644 --- a/bazel/ci/BUILD.bazel +++ b/bazel/ci/BUILD.bazel @@ -54,7 +54,7 @@ buildifier_test( no_sandbox = True, tags = ["no-remote-exec"], verbose = True, - workspace = "//:WORKSPACE.bazel", + workspace = "//:WORKSPACE.bzlmod", ) buildifier( diff --git a/bazel/toolchains/BUILD.bazel b/bazel/toolchains/BUILD.bazel index 5849b1b8b..55a19db8a 100644 --- a/bazel/toolchains/BUILD.bazel +++ b/bazel/toolchains/BUILD.bazel @@ -1 +1 @@ -"""This folder contains toolchain dependencies for the project. They are loaded by `WORKSPACE.bazel`.""" +"""This folder contains toolchain dependencies for the project. They are loaded by `WORKSPACE.bzlmod`.""" diff --git a/dev-docs/workflows/bump-go-version.md b/dev-docs/workflows/bump-go-version.md index 3ec607d17..9fe837af1 100644 --- a/dev-docs/workflows/bump-go-version.md +++ b/dev-docs/workflows/bump-go-version.md @@ -4,7 +4,7 @@ ## Steps -Replace "1.xx.x" with the new version in [WORKSPACE.bazel](/WORKSPACE.bazel): +Replace "1.xx.x" with the new version in [WORKSPACE.bzlmod](/WORKSPACE.bzlmod): ```starlark load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies") diff --git a/hack/bazel-deps-mirror/README.md b/hack/bazel-deps-mirror/README.md index 9aa5fb21e..354e506ab 100644 --- a/hack/bazel-deps-mirror/README.md +++ b/hack/bazel-deps-mirror/README.md @@ -2,7 +2,7 @@ This directory contains tooling to automatically mirror the dependencies of a Bazel project into the Constellation CDN at `https://cdn.confidential.cloud/`. -The tool searches for various rules in the WORKSPACE.bazel file and all loaded .bzl files. +The tool searches for various rules in the WORKSPACE.bzlmod file and all loaded .bzl files. It has the following commands: - check: checks if the dependencies all have a mirror URL and optionally checks if the mirror really returns the expected file diff --git a/hack/bazel-deps-mirror/internal/bazelfiles/files.go b/hack/bazel-deps-mirror/internal/bazelfiles/files.go index 468ff24ac..d1c32135d 100644 --- a/hack/bazel-deps-mirror/internal/bazelfiles/files.go +++ b/hack/bazel-deps-mirror/internal/bazelfiles/files.go @@ -53,12 +53,12 @@ func (h *Helper) FindFiles() ([]BazelFile, error) { return append(bzlFiles, workspaceFile), nil } -// findWorkspaceFile returns the path to the Bazel WORKSPACE.bazel file (or WORKSPACE if the former doesn't exist). +// findWorkspaceFile returns the path to the Bazel WORKSPACE.bzlmod file (or WORKSPACE if the former doesn't exist). func (h *Helper) findWorkspaceFile() (BazelFile, error) { - if _, err := h.fs.Stat("WORKSPACE.bazel"); err == nil { + if _, err := h.fs.Stat("WORKSPACE.bzlmod"); err == nil { return BazelFile{ - RelPath: "WORKSPACE.bazel", - AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bazel"), + RelPath: "WORKSPACE.bzlmod", + AbsPath: filepath.Join(h.workspaceRoot, "WORKSPACE.bzlmod"), Type: BazelFileTypeWorkspace, }, nil } @@ -151,7 +151,7 @@ type BazelFileType int const ( BazelFileTypeBzl = iota // BazelFileTypeBzl is a .bzl file - BazelFileTypeWorkspace // BazelFileTypeWorkspace is a WORKSPACE or WORKSPACE.bazel file + BazelFileTypeWorkspace // BazelFileTypeWorkspace is a WORKSPACE or WORKSPACE.bzlmod file ) // LookupEnv can be the real os.LookupEnv or a mock for testing. diff --git a/hack/bazel-deps-mirror/internal/bazelfiles/files_test.go b/hack/bazel-deps-mirror/internal/bazelfiles/files_test.go index c7d37770b..92cb1a0ae 100644 --- a/hack/bazel-deps-mirror/internal/bazelfiles/files_test.go +++ b/hack/bazel-deps-mirror/internal/bazelfiles/files_test.go @@ -42,22 +42,22 @@ func TestFindFiles(t *testing.T) { }, }, }, - "only WORKSPACE.bazel file": { - files: []string{"WORKSPACE.bazel"}, + "only WORKSPACE.bzlmod file": { + files: []string{"WORKSPACE.bzlmod"}, wantFiles: []BazelFile{ { - RelPath: "WORKSPACE.bazel", - AbsPath: "/WORKSPACE.bazel", + RelPath: "WORKSPACE.bzlmod", + AbsPath: "/WORKSPACE.bzlmod", Type: BazelFileTypeWorkspace, }, }, }, - "both WORKSPACE and WORKSPACE.bazel files": { - files: []string{"WORKSPACE", "WORKSPACE.bazel"}, + "both WORKSPACE and WORKSPACE.bzlmod files": { + files: []string{"WORKSPACE", "WORKSPACE.bzlmod"}, wantFiles: []BazelFile{ { - RelPath: "WORKSPACE.bazel", - AbsPath: "/WORKSPACE.bazel", + RelPath: "WORKSPACE.bzlmod", + AbsPath: "/WORKSPACE.bzlmod", Type: BazelFileTypeWorkspace, }, }, @@ -67,11 +67,11 @@ func TestFindFiles(t *testing.T) { wantErr: true, }, "all kinds": { - files: []string{"WORKSPACE", "WORKSPACE.bazel", "foo.bzl", "bar.bzl", "unused.txt", "folder/baz.bzl"}, + files: []string{"WORKSPACE", "WORKSPACE.bzlmod", "foo.bzl", "bar.bzl", "unused.txt", "folder/baz.bzl"}, wantFiles: []BazelFile{ { - RelPath: "WORKSPACE.bazel", - AbsPath: "/WORKSPACE.bazel", + RelPath: "WORKSPACE.bzlmod", + AbsPath: "/WORKSPACE.bzlmod", Type: BazelFileTypeWorkspace, }, { @@ -216,15 +216,15 @@ func TestDiff(t *testing.T) { assert := assert.New(t) require := require.New(t) fs := afero.NewMemMapFs() - err := afero.WriteFile(fs, "WORKSPACE.bazel", []byte(""), 0o644) + err := afero.WriteFile(fs, "WORKSPACE.bzlmod", []byte(""), 0o644) require.NoError(err) helper := Helper{ fs: fs, workspaceRoot: "/", } fileRef := BazelFile{ - RelPath: "WORKSPACE.bazel", - AbsPath: "/WORKSPACE.bazel", + RelPath: "WORKSPACE.bzlmod", + AbsPath: "/WORKSPACE.bzlmod", Type: BazelFileTypeWorkspace, } bf, err := helper.LoadFile(fileRef) @@ -247,10 +247,10 @@ func TestDiff(t *testing.T) { ) diff, err = helper.Diff(fileRef, bf) require.NoError(err) - assert.Equal("--- a/WORKSPACE.bazel\n+++ b/WORKSPACE.bazel\n@@ -1 +1 @@\n+workspace(name = \"foo\")\n", diff) + assert.Equal("--- a/WORKSPACE.bzlmod\n+++ b/WORKSPACE.bzlmod\n@@ -1 +1 @@\n+workspace(name = \"foo\")\n", diff) err = helper.WriteFile(fileRef, bf) require.NoError(err) - contents, err := afero.ReadFile(fs, "WORKSPACE.bazel") + contents, err := afero.ReadFile(fs, "WORKSPACE.bzlmod") assert.NoError(err) assert.Equal("workspace(name = \"foo\")\n", string(contents)) diff, err = helper.Diff(fileRef, bf)