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

Package request: buck2 #226677

Closed
nickgerace opened this issue Apr 17, 2023 · 7 comments
Closed

Package request: buck2 #226677

nickgerace opened this issue Apr 17, 2023 · 7 comments
Labels
0.kind: packaging request Request for a new package to be added

Comments

@nickgerace
Copy link
Contributor

nickgerace commented Apr 17, 2023

Project description

"Buck2, a large scale, fast, reliable, and extensible build tool developed and used by Meta. Buck2 supports a variety of languages on many platforms.

Buck2's core is written in Rust. Starlark, which is a deterministic, immutable dialect of Python, is used to extend the Buck2 build system, enabling Buck2 to be language-agnostic. With Starlark, users can define their own custom rules.

Buck2 leverages the Bazel spec of Remote Build Execution as the primary means of parallelization and caching, which increases the importance of idempotency (no matter how many times an operation is performed, it yields the same result) and hermeticity (code is sealed off from the world), giving the right results, reliably.

Buck2 multi-language support includes C++, Python, Java, Go, Rust, Erlang, OCaml, and more."

-- https://buck2.build/docs/

Metadata

Additional Notes

It's worth noting that buck2 appears to be updating off the latest branch with a re-created git tag upon each "release". It may be the case that buck2 doesn't make sense to be in nixpkgs right now, but perhaps folks have ideas on what it could look like to update buck2 automatically.

EDIT (17 Apr 2023): I suspect the package will go in pkgs/development/tools/build-managers. It's also worth adding the following note from the source URL's README...

"Build uses prebuilt protoc binary from protoc-bin-vendored crate. If these binaries to do not work on your machine (for example, when building for NixOS), path to protoc binary and protobuf include path can be specified via BUCK2_BUILD_PROTOC and BUCK2_BUILD_PROTOC_INCLUDE environment variables."

@nickgerace nickgerace added the 0.kind: packaging request Request for a new package to be added label Apr 17, 2023
@divanorama
Copy link
Contributor

Didn't try it out myself, but this may work https://github.com/thoughtpolice/buck2-nix/blob/main/buck/nix/buck2/default.nix

@nickgerace
Copy link
Contributor Author

I'm getting close to publishing a PR actually :) Should be up soon.

@nickgerace
Copy link
Contributor Author

Update: adding packaging to the upstream flake may be the best idea for now.

Either nixpkgs will need to support Rust-based packages with nightly toolchains (unlikely and for good reasons!) or buck2 will need to be buildable, and intentionally so, not as a hack, with stable Rust (linked issue: facebook/buck2#265). The good news is that caching solutions exist and @thoughtpolice's work in buck2-nix should provide a good bluepoint for where to start with an upstream contribution.

Full Context: #232471 (comment)

Fortunately, reindeer likely will not have the same issue being included in nixpkgs, so I am authoring a PR to add reindeer (issue: #232693).

si-bors-ng bot added a commit to systeminit/si that referenced this issue May 22, 2023
2234: Add reindeer to our nix flake (ENG-1463) r=nickgerace a=nickgerace

## Relevant Issues and PRs

- `buck2` with stable Rust: facebook/buck2#265
- `buck2` package request in nixpkgs: NixOS/nixpkgs#226677
- `buck2` PR for nixpkgs (closed due to inability to add it): NixOS/nixpkgs#232471
- `reindeer` package request in nixpkgs: NixOS/nixpkgs#232693
- `reindeer` PR for nixpkgs (merged): 
NixOS/nixpkgs#232699

## GIF

<img src="https://media4.giphy.com/media/7NTs0UJDuYz0k/giphy.gif"/>

Co-authored-by: Nick Gerace <nick@systeminit.com>
@thoughtpolice
Copy link
Member

thoughtpolice commented Jun 29, 2023

As of yesterday, I have a flake available on my buck2 fork that you can use to consume the buck2 binary in your downstream projects easily. For now, consider this a simple workaround. I plan on semi-regular-kinda-ish updating it and rebasing on trunk, and eventually contributing it upstream; see also facebook/buck2#308

Flake usage is easy. Something like the following should work where you can use b2 or buck2.packages."${system}".buck2 inside your flake outputs to refer to it, and you can put it in your devShells environment, etc:

{
  description = "Buck2 demo";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    buck2.url = "github:thoughtpolice/buck2";
  };

  outputs = { self, nixpkgs, flake-utils, buck2 }:
    flake-utils.lib.eachDefaultSystem (system:
      let b2 = buck2.packages."${system}".buck2;
      in ...
    );
}

You can also get a binary in your $PATH with nix profile install github:thoughtpolice/buck2

@thoughtpolice
Copy link
Member

thoughtpolice commented Jul 13, 2023

As of #243148, there are now buck2 binaries, thanks to the Meta team doing releases! They can be updated every two weeks easily. So that means you don't need a Flake, cache, or any expensive build steps.

Please let me know if the binary doesn't work for you; I've done some light testing on NixOS, and it seems to work fine in a normal nix shell environment; if things are broken somehow, we can pull it or figure something out.

@thoughtpolice
Copy link
Member

Two side notes:

  • I will probably migrate the flake to a new repository, so that I don't have to keep my main development fork clean at the moment.
  • We can probably close this now, I think.

@nickgerace
Copy link
Contributor Author

Thanks for the help @thoughtpolice! I believe #243148 does close this issue since buck2 is now in nixpkgs. Great work and thank you again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: packaging request Request for a new package to be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants