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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

bant: init at 0.1.5 #314680

Closed
wants to merge 1 commit into from
Closed

Conversation

hzeller
Copy link
Contributor

@hzeller hzeller commented May 25, 2024

Description of changes

From the README : Utility to support projects using the bazel build system, in particular C++ projects.

  • Cleaning up BUILD files by adding missing, and removing superflous, dependencies.
  • Extract interesting project information such as the dependency graph, headers provided by which libraries ....

Upstream v0.1.5 Release Notes

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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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.

@hzeller
Copy link
Contributor Author

hzeller commented May 26, 2024

This is a little tool I wrote that helps exploring bazel projects and also provides some dependency cleaning features.

However it seems to not work well to build as package on nix. I suspect this is because I am using bzlmod ?

Observed

  • Even after the fixed derivation of all dependencies has been determined, bazel still seems to want to talk to the bazel repository and errors such as Error accessing registry https://bcr.bazel.build/: Unknown host: bcr.bazel.build show up after switching to sandboxing.
  • In general, the fixed derivation hash seems to be different on different platforms. Not only between platforms (CI shows difference between aarch64 and x86_64 Linux), but as well on the same platform: the CI has a different hash for x86_64 than even my own x86_64 machine at home.
  • I even removed one of the not really needed dependencies in a patch, as you see in the commit, but also no difference (edit: now removed that again as it was not influencing the issue)

Are bzlmod projects not well-supported currently ?
Sending to @aherrmann for review as you have a good knowledge of both Nix and Bazel.

@hzeller hzeller requested a review from aherrmann May 26, 2024 05:13
@hzeller hzeller force-pushed the feature-20240525-bant-init branch from 65040fd to a59bb58 Compare May 27, 2024 17:14
@hzeller hzeller changed the title bant: init at 0.1.1 bant: init at 0.1.3 May 27, 2024
@hzeller hzeller force-pushed the feature-20240525-bant-init branch from a59bb58 to d61a801 Compare May 27, 2024 20:34
@hzeller
Copy link
Contributor Author

hzeller commented Jun 9, 2024

Maybe folks from @NixOS/bazel know some way to get this unstuck ?

@hzeller hzeller force-pushed the feature-20240525-bant-init branch from d61a801 to 97aaa76 Compare June 19, 2024 22:27
@hzeller hzeller changed the title bant: init at 0.1.3 bant: init at 0.1.5 Jun 19, 2024
@hzeller
Copy link
Contributor Author

hzeller commented Jun 19, 2024

New bant release came out in the meantime, changed to version 0.1.5

This can be made work with something @lromor has been working on: if the external bzlmod repository is bulit as fixed derivation, it can be passed to bazel with it not attempting to download the registry again after the build-phase:

lromor@ea780ca

Something like that would probably need to go into build-bazel-package, maybe with an override for the user to change the desired revision of the bazel-central-registry ? Leonardo, I think it would be good to create a pull request for nixpkgs changing the build-bazel-package and have the @NixOS/bazel maintainers review and help refine it.

(I could compile this PR when I patched in @lromor 's change to build-bazel-package)

@lromor
Copy link
Contributor

lromor commented Jun 23, 2024

For now I'll prepare a PR that uses overrideAttrs to add these changes as least invasive solution.

@lromor
Copy link
Contributor

lromor commented Jun 24, 2024

@hzeller , I found a simpler way:

{
  lib,
  stdenv,
  buildBazelPackage,
  fetchFromGitHub,
  bazel_6,
  jdk,
  git,
}:

let
  registry = stdenv.mkDerivation {
    name = "bazel-central-registry";
    dontBuild = true;
    src = fetchFromGitHub {
      owner = "bazelbuild";
      repo = "bazel-central-registry";
      rev = "1c729c2775715fd98f0f948a512eb173213250da";
      hash = "sha256-1iaDDM8/v8KCOUjPgLUtZVta7rMzwlIK//cCoLUrb/s=";
    };
    installPhase = ''
       cp -r $src $out
    '';
  };
in buildBazelPackage rec {
  pname = "bant";
  version = "0.1.5";

  src = fetchFromGitHub {
    owner = "hzeller";
    repo = "bant";
    rev = "v${version}";
    hash = "sha256-3xGAznR/IHQHY1ISqmU8NxI90Pl57cdYeRDeLVh9L08=";
  };

  bazelFlags = ["--registry" "file://${registry}"];

  postPatch = ''
    patchShebangs scripts/create-workspace-status.sh
  '';

  fetchAttrs = {
    sha256 = "sha256-ACJqybpHoMSg2ApGWkIyhdAQjIhb8gxUdo8SuWJvTNE=";
  };

  nativeBuildInputs = [
    jdk
    git
  ];
  bazel = bazel_6;

  bazelBuildFlags = [ "-c opt" ];
  bazelTestTargets = [ "//..." ];
  bazelTargets = [ "//bant:bant" ];

  buildAttrs = {
    installPhase = ''
      install -D --strip bazel-bin/bant/bant "$out/bin/bant"
    '';
  };

  meta = with lib; {
    description = "Bazel/Build Analysis and Navigation Tool";
    homepage = "http://bant.build/";
    license = licenses.asl20;
    maintainers = with maintainers; [ hzeller ];
    platforms = platforms.all;
  };
}

Note that I need a different hash, not sure why.

@hzeller
Copy link
Contributor Author

hzeller commented Jun 25, 2024

Perfect, thanks @lromor ! I think you should create a fresh bant pull request with your bazel compile improvements, then I retract this PR.

@hzeller
Copy link
Contributor Author

hzeller commented Jun 25, 2024

Chatted offline with @lromor : he'll prepare a nixpkgs pull request that includes the bazel registry as part of the derivation.
Closing this one.

@hzeller hzeller closed this Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants