Skip to content
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

Migrate to Bzlmod #626

Merged
merged 1 commit into from
Jan 28, 2024
Merged

Conversation

aaronmondal
Copy link
Member

@aaronmondal aaronmondal commented Jan 23, 2024

The new builds bootstrap the crate_universe binary which increases compatibility with various platforms.

New supported builds:

  • Native Bazel on MacOS
  • Nix-wrapped Cargo fon MacOS

In addition, a new --config=linux_zig was added which allows building nativelink with a more hermetic (but not perfectly hermetic) toolchain on systems that can't use the LRE toolchains. The zig-cc toolchain runs a lot slower than the LRE toolchains but is more similar to the LRE toolchain and at least somewhat reduces variation between compilers.

This commit is somewhat of a regression in terms of hermeticity and reproducibility. The bzlmod migration moved the Cargo.Bazel.lock file to an autogenerated MODULE.bazel.lock, but we have to gitignore that file for now since rules_rust currently doesn't create the same lockfiles on Linux and MacOS.


This change is Reviewable

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nativelink-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 28, 2024 1:53am

Copy link
Collaborator

Wow. I did not expect this one so quickly.

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@MarcusSorealheis +@adam-singer +@allada

CC @blakehatch @kubevalet it could be interesting to see how the toolchains in .bazelrc are set up. Essentially, the build uses whatever it finds on your system locally (no configuration, default behavior) but if you pass --config=linux_zig or --config=lre it switches over to a specific toolchain. Ultimately a goal is to have all our supported platforms mapped out with fully hermetic and remote-exec compatible toolchains and then to enable BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 globally in .bazelrc.

Reviewable status: 0 of 3 LGTMs obtained (waiting on @adam-singer, @allada, and @MarcusSorealheis)

Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 41 of 43 files at r1, all commit messages.
Reviewable status: 0 of 3 LGTMs obtained (waiting on @allada and @MarcusSorealheis)


local-remote-execution/rbe-configs-gen.nix line 4 at r1 (raw file):

pkgs.buildGoModule rec {
  pname = "bazel-toolchains";
  version = "5.1.3-rc1";

do we want to depend on an rc here or is this auto generated code we might not control?


tools/rules_rust_deduplicate_sysroot.diff line 12 at r1 (raw file):

+    if not toolchain._incompatible_no_rustc_sysroot_env:
+        env["SYSROOT"] = toolchain.sysroot
+    env["DYLD_LIBRARY_PATH"] = toolchain.sysroot + "/lib"

Hard to tell is this env always set or just set on mac? I think its only a mac respected env variable. Did these rules patches come from the upstream PR thats not merged into rules_rust?

Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the quick tl'dr for someone to test this on mac, would bazel test //... be a good smoke screen when pulling down this patch?

Reviewable status: 0 of 3 LGTMs obtained (waiting on @allada and @MarcusSorealheis)

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 LGTMs obtained (waiting on @adam-singer, @allada, and @MarcusSorealheis)


.github/workflows/native-bazel.yaml line 59 at r1 (raw file):

What is the quick tl'dr for someone to test this on mac, would bazel test //... be a good smoke screen when pulling down this patch?

Yes. This is the CI workflow that tests it. Note that this only works using a native toolchain but not in a nix shell (that would be tested in the nix-bazel workflow instead).


local-remote-execution/rbe-configs-gen.nix line 4 at r1 (raw file):

Previously, adam-singer (Adam Singer) wrote…

do we want to depend on an rc here or is this auto generated code we might not control?

This version includes changes to the java toolchains with Bazel 7. Between 5.1.2 and this ´rc´are just six commits bazelbuild/bazel-toolchains@v5.1.2...v5.1.3-rc1

Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronmondal worked for me out of the box!
:lgtm:

Reviewed 2 of 43 files at r1.
Reviewable status: 1 of 3 LGTMs obtained (waiting on @allada and @MarcusSorealheis)

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 LGTMs obtained, and pending CI: Analyze (javascript-typescript), Analyze (python), Bazel Dev / ubuntu-22.04, Cargo Dev / macos-13, Cargo Dev / ubuntu-22.04, Local / ubuntu-22.04, Remote / large-ubuntu-22.04, asan / ubuntu-22.04, docker-compose-compiles-nativelink (20.04), docker-compose-compiles-nativelink (22.04), integration-tests (20.04), integration-tests (22.04), macos-13, pre-commit-checks, publish-image, ubuntu-20.04, ubuntu-20.04 / stable, ubuntu-22.04, ubuntu-22.04 / stable, windows-2022 / stable (waiting on @allada and @MarcusSorealheis)


tools/rules_rust_deduplicate_sysroot.diff line 12 at r1 (raw file):

Previously, adam-singer (Adam Singer) wrote…

Hard to tell is this env always set or just set on mac? I think its only a mac respected env variable. Did these rules patches come from the upstream PR thats not merged into rules_rust?

This was bazelbuild/rules_rust#2422 with your added change for DYLD_LIBRARY_PATH. This actually doesn't seem to have any effect, so I changed it back to the original and added the sources of the patches to the MODULE.bazel.

@aaronmondal aaronmondal mentioned this pull request Jan 26, 2024
4 tasks
Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: 1 of 3 LGTMs obtained, and pending CI: asan / ubuntu-22.04 (waiting on @allada and @MarcusSorealheis)

Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 1 of 3 LGTMs obtained, and pending CI: asan / ubuntu-22.04 (waiting on @allada and @MarcusSorealheis)

Copy link
Member

@adam-singer adam-singer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 1 of 3 LGTMs obtained, and pending CI: asan / ubuntu-22.04 (waiting on @allada and @MarcusSorealheis)


.github/workflows/native-bazel.yaml line 59 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

What is the quick tl'dr for someone to test this on mac, would bazel test //... be a good smoke screen when pulling down this patch?

Yes. This is the CI workflow that tests it. Note that this only works using a native toolchain but not in a nix shell (that would be tested in the nix-bazel workflow instead).

sgtm, I'd say one impediment that gets to me is not being able to run the rust formatter or get the clippy rules checking, which I assume doesn't require nix? Getting past that for now is a huge win

Copy link
Member

@allada allada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 37 of 43 files at r1, 1 of 2 files at r2.
Reviewable status: 1 of 3 LGTMs obtained, and pending CI: asan / ubuntu-22.04 (waiting on @MarcusSorealheis)


-- commits line 20 at r2:
Hmmm, should we push on rust_rules people to fix this and consider it blocking?

I'm not sure we should force people to run more complex bazel commands to get going.


.github/workflows/main.yml line 53 at r2 (raw file):

        docker run --rm --net=host -w /root/nativelink -v $PWD:/root/nativelink trace_machina/nativelink:builder sh -c ' \
          bazel clean && \
          bazel test --config=linux_zig //... \

nit: We should have at least one workflow not use zig.


local-remote-execution/MODULE.bazel line 12 at r2 (raw file):

bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "7.3.2")

nit: Why rules_java?


local-remote-execution/MODULE.bazel line 14 at r2 (raw file):

bazel_dep(name = "rules_java", version = "7.3.2")

# register_execution_platforms("//generated/config:platform")

nit: Should be removed?


tools/rules_rust_bindgen_linkopts.diff line 1 at r2 (raw file):

diff --git a/bindgen/private/bindgen.bzl b/bindgen/private/bindgen.bzl

Did we upstream this? We should reference the upstream PR if we did, and if not we should upstream it.


tools/rules_rust_deduplicate_sysroot.diff line 1 at r2 (raw file):

diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl

ditto.

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 LGTMs obtained, and pending CI: Analyze (javascript-typescript), Bazel Dev / ubuntu-22.04, Vercel, asan / ubuntu-22.04, docker-compose-compiles-nativelink (20.04), pre-commit-checks, publish-image, ubuntu-20.04 / stable (waiting on @allada and @MarcusSorealheis)


-- commits line 20 at r2:

Previously, allada (Nathan (Blaise) Bruer) wrote…

Hmmm, should we push on rust_rules people to fix this and consider it blocking?

I'm not sure we should force people to run more complex bazel commands to get going.

This actually simplifies the setup as the only command required for building is bazel build. The lockfile is autogenerated and the new approach obsoletes the CARGO_BAZEL_REPIN=1 commands for dependency updates.

I think rules_rust is aware of this, but it's apparently a nontrivial thing to fix. Once they do fix it we can add the lockfile back, but it'll be an invisible change for users.


local-remote-execution/MODULE.bazel line 12 at r2 (raw file):

Previously, allada (Nathan (Blaise) Bruer) wrote…

nit: Why rules_java?

This is similar to rules_cc. The java rules were originally built into Bazel, but are now superceded by rules_java. It's often not visible because most projects use the legacy builtin rules.


tools/rules_rust_bindgen_linkopts.diff line 1 at r2 (raw file):

Previously, allada (Nathan (Blaise) Bruer) wrote…

Did we upstream this? We should reference the upstream PR if we did, and if not we should upstream it.

This is from bazelbuild/rules_rust#2422

It's documented in the git_override for rules_rust in the MODULE.bazel file.


tools/rules_rust_deduplicate_sysroot.diff line 1 at r2 (raw file):

Previously, allada (Nathan (Blaise) Bruer) wrote…

ditto.

This is from bazelbuild/rules_rust#2428

It's documented in the git_override for rules_rust in the MODULE.bazel file.

Copy link
Member

@allada allada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: 2 of 3 LGTMs obtained (waiting on @MarcusSorealheis)


.github/workflows/native-bazel.yaml line 75 at r3 (raw file):

      fail-fast: false
      matrix:
        os: [ubuntu-20.04, ubuntu-22.04]

nit: Lets add 18.04.

cc: @chrisstaite-menlo , you should be happy about this, as it'll make 18.04 officially supported 😄


local-remote-execution/MODULE.bazel line 12 at r2 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

This is similar to rules_cc. The java rules were originally built into Bazel, but are now superceded by rules_java. It's often not visible because most projects use the legacy builtin rules.

Lets add a comment for that.

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 3 LGTMs obtained, and pending CI: Vercel, pre-commit-checks (waiting on @MarcusSorealheis)


.github/workflows/native-bazel.yaml line 75 at r3 (raw file):

Previously, allada (Nathan (Blaise) Bruer) wrote…

nit: Lets add 18.04.

cc: @chrisstaite-menlo , you should be happy about this, as it'll make 18.04 officially supported 😄

I tried to, but 18.04 isn't supported in GHA anymore. We need to set up self-hosted Ubuntu 18 runners if we want that.

The new builds bootstrap the crate_universe binary which increases
compatibility with various platforms.

New supported builds:

- Native Bazel on MacOS
- Nix-wrapped Cargo fon MacOS
- Native Bazel builds with zig-cc on Ubuntu 20.04 and 22.04

In addition, add a new `--config=linux_zig` which allows building
nativelink with a more hermetic (but not perfectly hermetic) toolchain
on systems that can't use the LRE toolchains. The zig-cc toolchain runs
a lot slower than the LRE toolchains but is more similar to the LRE
toolchain and at least somewhat reduces variation between compilers.

This commit is a slight regression in terms of hermeticity and
reproducibility. The bzlmod migration moved the Cargo.Bazel.lock file to
an autogenerated MODULE.bazel.lock, but we have to gitignore that file
for now since rules_rust currently doesn't create the same lockfiles on
Linux and MacOS.
Copy link
Member

@allada allada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: 2 of 3 LGTMs obtained, and pending CI: pre-commit-checks (waiting on @MarcusSorealheis)


-- commits line 2 at r4:
nit: This is not Breaking from what I can tell.

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 2 LGTMs obtained


-- commits line 2 at r4:

Previously, allada (Nathan (Blaise) Bruer) wrote…

nit: This is not Breaking from what I can tell.

True. I'll remove the [Breaking] when squash merging.

Copy link
Member Author

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissed @adam-singer from a discussion.
Reviewable status: :shipit: complete! 2 of 2 LGTMs obtained

@aaronmondal aaronmondal merged commit 2a89ce6 into TraceMachina:main Jan 28, 2024
25 checks passed
@aaronmondal aaronmondal changed the title [Breaking] Migrate to Bzlmod Migrate to Bzlmod Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants