Skip to content

Instantly share code, notes, and snippets.

@meteorcloudy
Last active February 1, 2021 09:54
Show Gist options
  • Save meteorcloudy/ab6537261859757db372167f212f34a1 to your computer and use it in GitHub Desktop.
Save meteorcloudy/ab6537261859757db372167f212f34a1 to your computer and use it in GitHub Desktop.
1. bzlmod outputs a lock file and a bzl file that includes all the repo rules (instead of the whole WORKSPACE file).
2. Users who want their projects work across platforms integrate bzlmod in WORKSPACE with a native workspace rule (no repository_ctx needed)
3. Users who want to check in dependencies, use bzlmod as an external tool. Check in the generated lock file and bzl file, and load the bzl file in WORKSPACE.
4. Users who want to build on different platforms AND check in dependencies use bzlmod as an external tool and maintain multiple lock files and bzl files.
# Scenario 1
# I just want my project to build on all machines and platforms.
WORKSPACE:
```
pkgmgr_repo(
name = "bzlmod",
watch_files = ["MODULE.bazel"],
watch_envs = ["FOO", "BAR"],
resolve_command = "bzlmod resolve",
)
loads("@bzlmod//:bzlmod_deps.bzl", "bzlmod_deps")
bzlmod_deps()
# More deps in old way
...
```
# Scenario 2
# My company has project X, we want fully deterministic build and remote caching/execution, all developers build on same dev environment (Same platform and setup on developers' workstations).
$ bzlmod resolve
$ git add bzlmod.lock bzlmod_deps.bzl
WORKSPACE:
```
load("//:bzlmod_deps.bzl", "bzlmod_deps")
bzlmod_deps()
```
# Scenario 3
# Similar to 2, but project X has to build on Linux, macOS, and Windows.
On Linux:
$ bzlmod resolve --platform_name_suffix=linux
$ git add bzlmod.linux.lock bzlmod_deps.linux.bzl
On Mac:
$ bzlmod resolve --platform_name_suffix=macos
$ git add bzlmod.macos.lock bzlmod_deps.macos.bzl
On Windows:
> bzlmod resolve --platform_name_suffix=windows
> git add bzlmod.windows.lock bzlmod_deps.windows.bzl
In the bzlmod_deps.bzl:
```
load("//:bzlmod_deps.linux.bzl", "bzlmod_deps_linux")
load("//:bzlmod_deps.macos.bzl", "bzlmod_deps_macos")
load("//:bzlmod_deps.windows.bzl", "bzlmod_deps_windows")
if is_linux:
bzlmod_deps = bzlmod_deps_linux
else if is_macos:
bzlmod_deps = bzlmod_deps_macos
else if is_windows:
bzlmod_deps = bzlmod_deps_windows
else:
bzlmod_deps = None
# How to implement the platform check in WORKSPACE?
```
In the WORKSPACE:
```
load("//:bzlmod_deps.bzl", "bzlmod_deps")
bzlmod_deps()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment