Skip to content

bazel_8: init at 8.1.1#362414

Closed
boltzmannrain wants to merge 1 commit intoNixOS:masterfrom
boltzmannrain:bazel_8_rc
Closed

bazel_8: init at 8.1.1#362414
boltzmannrain wants to merge 1 commit intoNixOS:masterfrom
boltzmannrain:bazel_8_rc

Conversation

@boltzmannrain
Copy link
Contributor

@boltzmannrain boltzmannrain commented Dec 6, 2024

Started with copying bazel_7 and adapted it, notable changes:

  • bazelDeps now builds on Darwin in sandbox=true which was previously failing on power management tweaks
  • using lndir -silent for less build logs
  • had to disable module_deps feature to avoid getting .. does not depend on a module exporting .. errors on clang/macos importing intrinsics
  • on macos adding -fno-aligned-allocation on sdk <10.13 to avoid build error saying it isn't supported on <10.13
  • placing under pkgs/by-name to pass CI, but still calling from pkgs/top-level/all-packages.nix as not sure how to pass darwin sdk and other settings in by-name way

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Dec 6, 2024
@boltzmannrain

This comment was marked as outdated.

@ofborg ofborg bot added the 8.has: package (new) This PR adds a new package label Dec 7, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Dec 7, 2024
@boltzmannrain boltzmannrain changed the title bazel_8: init at 8.0.0rc7 bazel_8: init at 8.0.0rc8 Dec 8, 2024
@boltzmannrain

This comment was marked as outdated.

@github-actions github-actions bot removed 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Dec 8, 2024
@boltzmannrain

This comment was marked as outdated.

@boltzmannrain

This comment was marked as outdated.

@ofborg ofborg bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Dec 9, 2024
@boltzmannrain boltzmannrain force-pushed the bazel_8_rc branch 2 times, most recently from 2840557 to b6ecb11 Compare December 10, 2024 23:50
@github-actions github-actions bot removed 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Dec 10, 2024
@nix-owners nix-owners bot requested review from infinisil and philiptaron January 19, 2025 13:26
ci/OWNERS Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Let's not burden people with more pings unless they confirm being okay with it. @Profpatsch do you even still want to help maintain Bazel? If not, you should probably be removed from here.

And independent of whether @Profpatsch stays listed here, I'm suggesting you add yourself @boltzmannrain, since you've done so much great Bazel maintenance recently :D

@philiptaron philiptaron requested a review from a team January 23, 2025 13:53
@timothyklim
Copy link
Contributor

Since PR created, bazel updated to https://github.com/bazelbuild/bazel/releases/tag/8.1.1

@seh
Copy link

seh commented Mar 5, 2025

The description includes the following item:

had to disable module_deps feature to avoid getting "... does not depend on a module exporting ..." errors on clang/macos importing intrinsics

Where does that occur within the current patch?

@seh
Copy link

seh commented Mar 5, 2025

Where does that occur within the current patch?

Oh, perhaps you meant module_maps, which occurs within the pkgs/by-name/ba/bazel_8/package.nix file .

Copy link

Choose a reason for hiding this comment

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

I found that for what's been ailing me trying to build the Abseil library within Bazel on macOS, just including --host_features=-module_maps in my .bazelrc finally got it all to work.

Thank you so much, Dmitry!

@github-actions github-actions bot removed the 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions label Mar 5, 2025
@boltzmannrain boltzmannrain changed the title bazel_8: init at 8.0.1 bazel_8: init at 8.1.1 Mar 5, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Mar 5, 2025
@boltzmannrain
Copy link
Contributor Author

boltzmannrain commented Mar 6, 2025

Updated to 8.1.1, removed ci/OWNERS change, applied couple more build workarounds that showed up. Darwin builds have a new unaddressed -faligned-allocation (opposite flag is already added, but maybe not in all contexts) (fixed)

@timothyklim
Copy link
Contributor

Can it be merged before 8.2.0?

@philiptaron
Copy link
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 362414


x86_64-darwin

✅ 1 package built:
  • bazel_8

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

I read through this PR as a committer who

a. doesn't use Bazel
b. doesn't know Java that well
c. is just looking to unblock what looks like a stuck PR

So please bear that in mind.

I have a couple big pieces of feedback that would have made it much easier to say "merge immediately".

  1. Splitting the mega-derivation into chunks, each of which was callPackaged from the main one. That makes it possible for me to say "yeah, that checks out" in chunks, rather than trying to keep the whole 600+ Nix derivation in my head as I'm reading it.
  2. Use of patches throughout, so that all of the sed calls were reviewable through seeing them in context. Yes, this will be bigger in terms of bytes. Trying to figure out what a multi-line sed call is going to do is just super hard.
  3. Use of the new Darwin SDK and interaction with recent developments there. More broadly, a lot of this derivation is dedicated to changing Bazel behavior on Darwin, and I found myself wondering whether it was overfitting on a stdenv that no longer is recommended.

There are lots of smaller things I commented on as a read through this PR, but those were the big ones.

I don't actually know if any of that is actually blocking, because as previously stated, I'm just here trying to unstick a PR without traction.

makeWrapper,
writeTextFile,
writeScript,
substituteAll,
Copy link
Contributor

Choose a reason for hiding this comment

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

use replaceVars instead (#237216)

Comment on lines +489 to +492
(substituteAll {
src = ./strict_action_env.patch;
strictActionEnvPatch = defaultShellPath;
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(substituteAll {
src = ./strict_action_env.patch;
strictActionEnvPatch = defaultShellPath;
})
(replaceVars ./strict_action_env.patch {
strictActionEnvPatch = defaultShellPath;
})

Comment on lines +496 to +499
(substituteAll {
src = ./bazel_rc.patch;
bazelSystemBazelRCPath = bazelRC;
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(substituteAll {
src = ./bazel_rc.patch;
bazelSystemBazelRCPath = bazelRC;
})
(replaceVars ./bazel_rc.patch {
bazelSystemBazelRCPath = bazelRC;
})

bazel_self = bazel_7;
};

bazel_8 = darwin.apple_sdk_11_0.callPackage ../by-name/ba/bazel_8/package.nix {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed now @NixOS/darwin-core? I think not...

Comment on lines +110 to +159
# Bootstrap an existing Bazel so we can vendor deps with vendor mode
bazelBootstrap = stdenv.mkDerivation rec {
name = "bazelBootstrap";

src =
{
x86_64-linux = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${bootstrapVersion}/bazel_nojdk-${bootstrapVersion}-linux-x86_64";
hash = "sha256-KLejW8XcVQ3xD+kP9EGCRrODmHZwX7Sq3etdrVBNXHI=";
};
aarch64-linux = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${bootstrapVersion}/bazel_nojdk-${bootstrapVersion}-linux-arm64";
hash = "sha256-+4GTKurt1KBkdyfC2hOLI31gBDOm1wTn91+kDX1di9M=";
};
x86_64-darwin = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${bootstrapVersion}/bazel-${bootstrapVersion}-darwin-x86_64";
hash = "sha256-MsqLv4ZssUGQv7AZzhrEp9YbjLs/B3ETeXTo0OXN8es=";
};
aarch64-darwin = fetchurl {
url = "https://github.com/bazelbuild/bazel/releases/download/${bootstrapVersion}/bazel-${bootstrapVersion}-darwin-arm64";
hash = "sha256-0QrGSIVQxSEa7SAIT0Dft39jZ+IpsVoc8ocFeUHZMys=";
};
}
.${stdenv.hostPlatform.system};

nativeBuildInputs = defaultShellUtils;
buildInputs = [
stdenv.cc.cc
] ++ lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook;

dontUnpack = true;
dontPatch = true;
dontBuild = true;
dontStrip = true;
installPhase = ''
runHook preInstall

mkdir -p $out/bin
install -Dm755 $src $out/bin/bazel

runHook postInstall
'';

postFixup = ''
wrapProgram $out/bin/bazel \
--prefix PATH : ${lib.makeBinPath nativeBuildInputs}
'';

meta.sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to extract this to its own package:

bazelBootstrap = callPackage ./bootstrap.nix { inherit whatever };

}

# Also build parser_deploy.jar with bootstrap bazel
# TODO: Turn into a proper patch
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd really appreciate this. Sed is great for very targeted fixes, but this wide-scale rework is better as a patch, or a separate derivation.

Comment on lines +628 to +631
# reconstruct the now patched builtins_bzl.zip
pushd src/main/java/com/google/devtools/build/lib/bazel/rules/builtins_bzl_zip &>/dev/null
zip ../builtins_bzl.zip $(find builtins_bzl -type f) >/dev/null
rm -rf builtins_bzl
Copy link
Contributor

Choose a reason for hiding this comment

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

This made me think that making a separate derivation for builtins_bzl would work and clarify this mega derivation.

# $out/bin/bazel-{version}-{os_arch} The binary _must_ exist with this
# naming if your project contains a .bazelversion file.
cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel
versionned_bazel="$out/bin/bazel-${version}-${system}-${arch}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
versionned_bazel="$out/bin/bazel-${version}-${system}-${arch}"
versioned_bazel="$out/bin/bazel-${version}-${system}-${arch}"

minor typo

Comment on lines +817 to +820
# The string literal specifying the path to the bazel-rc file is sometimes
# stored non-contiguously in the binary due to gcc optimisations, which leads
# Nix to miss the hash when scanning for dependencies
echo "${bazelRC}" >> $out/nix-support/depends
Copy link
Contributor

Choose a reason for hiding this comment

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

That's pretty spooky!

Comment on lines +830 to +831
# TODO add some tests to cover basic functionality, and also tests for enableNixHacks=true (buildBazelPackage tests)
# tests = ...
Copy link
Contributor

Choose a reason for hiding this comment

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

@boltzmannrain
Copy link
Contributor Author

Suggestions make sense to me 👍 But will need some time to implement. Also looks like 8.0.1->8.1.1 bump broke enableNixHacks patch and buildBazelPackage compatibility, will see how to fix and make it work with say bazelbuild/examples repo which'd also serve as a test. Maybe will need to implement vendor flow used in bazel_8 build for buildBazelPackage

@hzeller
Copy link
Contributor

hzeller commented Mar 26, 2025

FWIW, I tested 8.1.1 from this PR on two of projects I maintain ( bant and verible), both of which are compatible with a wide range of bazel versions from 6.5.0 to 8.1.1.

  • One thing I noticed: the enableNixHacks patch does not apply cleanly, so this PR currently only builds in the configuration without. So currently using bazel_8 when building nix packages does not work as nix-package building is enabling that hack. So only compiled my projects locally with a fresh 8.1.1 build ( cd my_project; /nix/store/nyc8b16lkh434bqbmnb51ipwl392irkq-bazel-8.1.1/bin/bazel build -c opt ... )
  • Projects that use 8.1.x seem to implicitly upgrade rules_cc to some newer version, or start using rules_cc to run the compiler. In any case, that rules_cc is not new enough to contain the patch that makes them nix-compatible ( shebang: changed scripts shebang to better support systems like bsd and nixos bazelbuild/rules_cc#306 ) which is not in a released version yet.

So I can only use 8.1.1 from this PR on these projects if I force upgrading to a working rules_cc version by adding the following to my projects' MODULE.bazel

bazel_dep(name = "rules_cc", version = "0.1.1")
git_override(
    module_name = "rules_cc",
    commit = "d74915024017250e46d95e91a3defc34174effe0",  # get commit of rules_cc PR 306
    remote = "https://github.com/bazelbuild/rules_cc",
)

With that, both bant and verible build.

I wonder if in the 8.1.1 somewhere has its MODULE.bazel that loads some older rules_cc, and maybe we can patch it up to contain that override for it to work ?

@hzeller
Copy link
Contributor

hzeller commented Mar 26, 2025

Uh, looking through the bazel 8.1.1 source code to see what rules_cc they use ... I only see references to somewhat ancient ones (also not sure with is implicitly used when bazel is run on a project)

bazel[release-8.1.1]$ rg rules_cc.*version
src/MODULE.tools:bazel_dep(name = "rules_cc", version = "0.0.17")
src/test/py/bazel/bazel_windows_test.py:            'bazel_dep(name = "rules_cc", version = "0.0.12")',
src/test/py/bazel/launcher_test.py:            'bazel_dep(name = "rules_cc", version = "0.0.12")',
src/test/py/bazel/testdata/runfiles_test/MODULE.bazel.mock:bazel_dep(name = "rules_cc", version = "0.0.9")
src/test/py/bazel/bazel_windows_cpp_test.py:            'bazel_dep(name = "rules_cc", version = "0.0.12")',
site/en/external/module.md:bazel_dep(name = "rules_cc", version = "0.0.1")
site/en/external/overview.md:bazel_dep(name = "rules_cc", version = "0.0.1")
MODULE.bazel:bazel_dep(name = "rules_cc", version = "0.0.17")

... not sure if my suggestion to upgrade rules_cc to something newer than 0.1.1 is feasible if it is so far off.

@hzeller
Copy link
Contributor

hzeller commented Mar 30, 2025

... not sure if my suggestion to upgrade rules_cc to something newer than 0.1.1 is feasible if it is so far off.

I am convinced now this is not something we should work around in bazel 8. Bazel 8 actually just introduces a minimal rules_cc and that is fine. Other projects might require a newer rules_cc because they depend on other things that pull in a rules_cc that has not the fix yet. So I think nothing to block this PR, it is up to the projects compiling things with bazel 8+ to fix that.

So LGTM to me.

@boltzmannrain
Copy link
Contributor Author

Marking as draft for now, will probably create a new one after refactoring and making tests work

@IanMcShane
Copy link

Super excited about this PR. Thanks for the effort!

@boltzmannrain
Copy link
Contributor Author

Bazel 8.2.1 is much easier to bootstrap-build, so hope to open a new improved PR soon

@boltzmannrain
Copy link
Contributor Author

Draft for 8.2.1 #400941 I will be refactoring and cleaning it up a fair bit but big-picture is settled for now

@boltzmannrain
Copy link
Contributor Author

8.2.1 PR supersedes 8.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants