{"id":15136890,"url":"https://github.com/release-candidate/cxx-buck2-conan-examples","last_synced_at":"2025-09-29T06:31:01.629Z","repository":{"id":204973710,"uuid":"712127834","full_name":"Release-Candidate/Cxx-Buck2-Conan-Examples","owner":"Release-Candidate","description":"A C++ example repository using Buck 2 with Conan (the C++ package manager) and scripts to generate a compile-commands.json.","archived":true,"fork":false,"pushed_at":"2024-07-26T08:16:04.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-27T06:42:12.405Z","etag":null,"topics":["buck","buck2","compile-commands","compile-commands-json","conan","cxx","example","examples"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Release-Candidate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-30T21:05:28.000Z","updated_at":"2024-07-26T08:16:18.000Z","dependencies_parsed_at":"2023-11-19T12:31:17.324Z","dependency_job_id":null,"html_url":"https://github.com/Release-Candidate/Cxx-Buck2-Conan-Examples","commit_stats":null,"previous_names":["release-candidate/cxx-buck2-examples","release-candidate/cxx-buck2-conan-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Release-Candidate%2FCxx-Buck2-Conan-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Release-Candidate%2FCxx-Buck2-Conan-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Release-Candidate%2FCxx-Buck2-Conan-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Release-Candidate%2FCxx-Buck2-Conan-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Release-Candidate","download_url":"https://codeload.github.com/Release-Candidate/Cxx-Buck2-Conan-Examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234597573,"owners_count":18857980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buck","buck2","compile-commands","compile-commands-json","conan","cxx","example","examples"],"created_at":"2024-09-26T06:41:42.168Z","updated_at":"2025-09-29T06:30:56.324Z","avatar_url":"https://github.com/Release-Candidate.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]\n\u003e This repositor has been moved to [Codeberg: Cxx-Buck2-Conan-Examples](https://codeberg.org/Release-Candidate/Cxx-Buck2-Conan-Examples)\n\n# Cxx-Buck2-Conan-Examples\n\nA C++ example repository using Buck 2 with Conan (the C++ package manager) and scripts to generate a single `./compile_commands.json` file.\n\n- [Installation](#installation)\n- [Using this Example](#using-this-example)\n  - [Available Targets](#available-targets)\n  - [Buck 2 Files](#buck-2-files)\n- [Converting an Existing or Generating a new C++ Project with Buck 2](#converting-an-existing-or-generating-a-new-c-project-with-buck-2)\n- [Other Buck 2 C++ Examples](#other-buck-2-c-examples)\n- [Buck 2 Examples for other Languages](#buck-2-examples-for-other-languages)\n- [Contributions](#contributions)\n- [License](#license)\n\n## Installation\n\nYou need the following:\n\n- Buck 2: [Buck2 Official Website](https://buck2.build/)\n- Conan 1 [GitHub Releases - Conan 1.6](https://github.com/conan-io/conan/releases/tag/1.61.0) - See [Buck 2 Issue](https://github.com/facebook/buck2/issues/469). On MacOS with Homebrew: `brew install conan@1`. **Warning**: Conan 2 does not work.\n- Python 3, Python 3.8 or newer.\n\nInstall Buck 2 like documented at [Buck 2 - Getting Started](https://buck2.build/docs/getting_started/).\n\n## Using this Example\n\n- Checkout the Buck 2 prelude containing the language rules: `git submodule update --init`\n- Run `buck2 run //:conan-update` to build the Conan packages and add them to Buck 2. An updated file [./third-party/BUCK](./third-party/BUCK) should be generated.\n- Now you should be able to build and run the example binary: `buck2 run //app:app`.\n- To generate a `compile_commands.json` file (needed for the C++ LSPs), run `buck2 build //:compile_commands`.\n\n### Available Targets\n\n- `buck2 clean` - Deletes all generated files and Conan packages.\n- `buck2 targets //...` - Lists all available targets, including all Conan packages.\n- `buck2 build :exe` - A alias for `buck2 build //app:app`, builds the executable [./app/main.cpp](./app/main.cpp). Buck 2 configuration [./app/BUCK](./app/BUCK)\n- `buck2 run :exe` - A alias for `buck2 run //app:app`, builds and runs the executable [./app/main.cpp](./app/main.cpp). Buck 2 configuration [./app/BUCK](./app/BUCK)\n- `buck2 build :test` - A alias for `buck2 build //test:test`, builds the tests in [./test/test_main.cpp](./test/test_main.cpp). Buck 2 configuration [./test/BUCK](./test/BUCK).\n- `buck2 test :test` - A alias for `buck2 test //test:test`, builds and runs the tests in [./test/test_main.cpp](./test/test_main.cpp). Buck 2 configuration [./test/BUCK](./test/BUCK).\n- `buck2 run :test` - A alias for `buck2 run //test:test`, builds and runs the tests in [./test/test_main.cpp](./test/test_main.cpp). Buck 2 configuration [./test/BUCK](./test/BUCK). The difference to `buck2 test` is mostly in the output, `run` uses for example colored output.\n- `buck2 build :lib` - A alias for `buck2 build //lib:library`, builds the library in [./lib/lib.cpp](./lib/lib.cpp). Buck 2 configuration [./lib/BUCK](./lib/BUCK)\n- `buck2 run :conan-update` - Builds all Conan packages configured in [./conanfile.txt](./conanfile.txt). Buck 2 configuration in [./toolchains/BUCK](./toolchains/BUCK) and [./BUCK](./BUCK)\n- `buck2 build :compile_commands` - Generates the file `./compile_commands.json`, needed for LSPs. The actual python scripts and Buck 2 configuration is located in [./concat_compile_cmds/](./concat_compile_cmds/), the list of targets to add to `./compile_commands.json` is located in the Buck 2 configuration file [./BUCK](./BUCK):\n\n  ```python\n  concat_compile_cmds(\n    name=\"compile_commands\",\n    files=[\n        \"//app:app[full-compilation-database]\",\n        \"//lib:library[full-compilation-database]\",\n        \"//test:test[full-compilation-database]\",\n    ],\n  )\n  ```\n\n### Buck 2 Files\n\n- [./.buckroot](./.buckroot) - A empty file to mark the BUck 2 root. The root directory of all Buck 2 projects, not just a single one. Generated by `buck2 init`.\n- [./.buckconfig](./.buckconfig) - The general Buck 2 configuration. Generated by `buck2 init`. Set the execution platform to the default one of the prelude.\n\n  ```ini\n  [build]\n  execution_platforms = prelude//platforms:default\n  ```\n\n- [./BUCK](./BUCK) - Main Buck 2 configuration, holds the aliases, the Conan rules and the configuration for the generation of `./compile_commands.json`. You have to manually edit this.\n- [./toolchains/BUCK](./toolchains/BUCK) - Configuration of the Buck 2 toolchains - Python, C++ and Conan. You have to manually edit this.\n- [./concat_compile_cmds/](./concat_compile_cmds/) - Python script and Buck2 configuration to generate the file `./compile_commands.json`. Just copy that in your own project.\n- [./third-party/BUCK](./third-party/BUCK) - Autogenerated by `buck2 run :conan-update`. Do not edit!\n- [./lib/BUCK](./lib/BUCK) - The library's configuration. You have to manually create that.\n- [./app/BUCK](./app/BUCK) - Configuration of the executable. You have to manually create that.\n- [./test/BUCK](./test/BUCK) - Test configuration. You have to manually create that.\n\n## Converting an Existing or Generating a new C++ Project with Buck 2\n\n1. Initialize the project by running `buck2 init --git`\n2. Set the execution platform in [./.buckconfig](./.buckconfig) to the default one of the prelude.\n\n    ```ini\n    [build]\n    execution_platforms = prelude//platforms:default\n    ```\n\n3. Generate a `./conanfile.txt` containing your dependencies.\n4. Edit the files [./toolchains/BUCK](./toolchains/BUCK) and [./BUCK](./BUCK) to include the C++, Python and Conan toolchains.\n5. Add sources and `BUCK` files. Like [./lib/BUCK](./lib/BUCK), [./app/BUCK](./app/BUCK) and [./test/BUCK](./test/BUCK).\n6. Copy the directory [./concat_compile_cmds/](./concat_compile_cmds/) to your project and configure it in [./toolchains/BUCK](./toolchains/BUCK) and [./BUCK](./BUCK) to be able to generate a `./compile_commands.json` file in your root directory.\n7. Run `buck2 run :conan-update` to install and configure the Conan packages for use with Buck 2. Generates the files [./third-party/BUCK](./third-party/BUCK) and [./conan.lock](./conan.lock).\n8. Run `buck2 build :compile_commands` to generate the file `./compile_commands.json` for use with your LSP (like `clangd`).\n\n## Other Buck 2 C++ Examples\n\n- I have also written an example repository using vcpkg as package manager: [Cxx-Buck2-vcpkg-Examples](https://github.com/Release-Candidate/Cxx-Buck2-vcpkg-Examples)\n- The official examples: [Facebook: Buck 2 C++ Examples](https://github.com/facebook/buck2/tree/main/examples/with_prelude/cpp)\n- The official Conan examples: [Facebook: Buck 2 C++ Conan Examples](https://github.com/facebook/buck2/tree/main/examples/toolchains/conan_toolchain)\n- Rust and C++ interop examples [Interop Between C++ and Rust](https://github.com/dtolnay/cxx)\n\n## Buck 2 Examples for other Languages\n\nI've also made examples for OCaml: [OCaml-Buck-2-Examples](https://github.com/Release-Candidate/OCaml-Buck-2-Examples).\n\n## Contributions\n\nIf you want to add tips or tricks on using Buck 2, examples, a link to other examples, blog or forum posts, or found an error, please open an issue or pull request with your changes.\n\n## License\n\nThese examples are licensed under the MIT license. See file [./LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelease-candidate%2Fcxx-buck2-conan-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frelease-candidate%2Fcxx-buck2-conan-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelease-candidate%2Fcxx-buck2-conan-examples/lists"}