-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add support for Bazel #2505
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
Merged
Merged
Add support for Bazel #2505
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build --symlink_prefix=/ # Out of source build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 4.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| cc_library( | ||
| name = "fmt", | ||
| srcs = [ | ||
| #"src/fmt.cc", # No C++ module support | ||
| "src/format.cc", | ||
| "src/os.cc", | ||
| ], | ||
| hdrs = [ | ||
| "include/fmt/args.h", | ||
| "include/fmt/chrono.h", | ||
| "include/fmt/color.h", | ||
| "include/fmt/compile.h", | ||
| "include/fmt/core.h", | ||
| "include/fmt/format.h", | ||
| "include/fmt/format-inl.h", | ||
| "include/fmt/locale.h", | ||
| "include/fmt/os.h", | ||
| "include/fmt/ostream.h", | ||
| "include/fmt/printf.h", | ||
| "include/fmt/ranges.h", | ||
| "include/fmt/xchar.h", | ||
|
Vertexwahn marked this conversation as resolved.
|
||
| ], | ||
| includes = [ | ||
| "include", | ||
| "src", | ||
| ], | ||
| strip_include_prefix = "include", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Bazel support | ||
|
|
||
| Bazel is an open-source build tool. | ||
| More information about Bazel can be found [here](https://bazel.build/). | ||
|
|
||
| ## Using the fmt repository with Bazel | ||
|
|
||
| Even though the {fmt} repository does not contain a `WORKSPACE` file in its root directory, | ||
| there is an easy approach to use the {fmt} repository with Bazel out of the box. | ||
| This is demonstrated in the following example. | ||
|
|
||
| Add to your `WORKSPACE` file: | ||
|
|
||
| ```python | ||
| load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") | ||
|
|
||
| # Fetch all files from fmt including the BUILD file `support/bazel/BUILD.bazel` | ||
| new_git_repository( | ||
| name = "fmt_workaround", | ||
| branch = "master", | ||
| remote = "https://github.com/fmtlib/fmt/", | ||
| build_file_content = "# Empty build file on purpose" | ||
| ) | ||
|
|
||
| # Now the BUILD file `support/bazel/BUILD.bazel` can be used: | ||
| new_git_repository( | ||
| name = "fmt", | ||
| branch = "master", | ||
| remote = "https://github.com/fmtlib/fmt/", | ||
| build_file = "@fmt_workaround//:support/bazel/BUILD.bazel" | ||
| ) | ||
| ``` | ||
|
|
||
| Create a `BUILD.bazel` file and add a dependency to {fmt}: | ||
|
|
||
| ```python | ||
| cc_binary( # Build a binary | ||
| name = "Demo", # Name of the binary | ||
| srcs = ["main.cpp"], # List of files - we only have main.cpp | ||
| deps = ["@fmt//:fmt"], # Depend on fmt | ||
| ) | ||
| ``` | ||
|
|
||
| Make use of {fmt} in `main.cpp`: | ||
|
|
||
| ```C++ | ||
| #include "fmt/core.h" | ||
|
|
||
| int main() { | ||
| fmt::print("The answer is {}.\n", 42); | ||
| } | ||
| ``` | ||
|
|
||
| The expected output of this example is `The answer is 42`. | ||
|
|
||
| ## Bazelize fmt | ||
|
|
||
| First downloading a build file and then making use of it can be considered as a bit unclean, nevertheless, it works. | ||
|
|
||
| A cleaner Bazel solution would be to move the `WORKSPACE` and `BUILD` files to the root folder of the {fmt} Git repository. | ||
|
|
||
| In favor of keeping the {fmt} project directory clean, those files were not added to the project root directory. | ||
|
|
||
| If you do not like this, you can fork this repository and move the files `BUILD.bazel`, `WORKSPACE.bazel`, `.bazelrc`, and `.bazelversion` from this folder (`support/bazel`) to the root folder of this project. | ||
|
|
||
| This way {fmt} gets bazelized and can be used in your Bazel builds. | ||
|
|
||
| **Example** | ||
|
|
||
| Create a `WORKSPACE.bazel` file with the following content: | ||
|
|
||
| ```python | ||
| load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
|
||
| # Fetch bazelized fmt | ||
| git_repository( | ||
| name = "fmt", | ||
| branch = "bazel-support", # A copy of master where BUILD.bazel, WORKSPACE.bazel, .bazelrc and .bazelversion are moved to root | ||
| remote = "https://github.com/<user_or_organisation>/fmt", # replace <user_or_organisation> by a valid account | ||
| ) | ||
| ``` | ||
|
|
||
| Create a `BUILD.bazel` file and add a dependency to {fmt} (same as above). | ||
|
|
||
| Make use of {fmt} in `main.cpp` (same as above). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| workspace(name = "fmt") | ||
|
Vertexwahn marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.