Skip to content

Commit 9ea575d

Browse files
[bazel] Simple bazel project (conan-io#123)
* Added Bazel example with fmt * Added comments. Readme * Updated link * Only Linux * simpler example
1 parent a587eec commit 9ea575d

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ tutorial/versioning/revisions/intro/chat/*
6565
tutorial/versioning/revisions/intro/hello/*
6666
examples/libraries/tensorflow-lite/pose-estimation/pose-estimation
6767
examples/libraries/imgui/introduction/bindings
68+
69+
# Bazel files
70+
bazel-*

examples/tools/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919
### [tools.autotools](autotools)
2020

2121
- Build a [Autotools project](autotools/autotoolstoolchain/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/autotools/autotools_toolchain/build_project_autotools_toolchain.rst)
22+
23+
### [tools.google](google)
24+
25+
- Build a [Bazel project](bazel/bazeltoolchain/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_project.rst)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
load("@//conan:dependencies.bzl", "load_conan_dependencies")
2+
load_conan_dependencies()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[requires]
2+
fmt/10.1.1
3+
4+
[generators]
5+
BazelDeps
6+
BazelToolchain
7+
8+
[layout]
9+
bazel_layout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
3+
cc_binary(
4+
name = "demo",
5+
srcs = ["demo.cpp"],
6+
deps = [
7+
"@fmt//:fmt"
8+
],
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <cstdlib>
2+
#include <fmt/core.h>
3+
4+
int main() {
5+
fmt::print("{} - The C++ Package Manager!\n", "Conan");
6+
return EXIT_SUCCESS;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import platform
2+
import shutil
3+
4+
from test.examples_tools import run
5+
6+
# ############# Example ################
7+
print("\n- Use the BazelToolchain and BazelDeps generators -\n")
8+
9+
if platform.system() != "Linux":
10+
print(f"SKIPPED TEST BECAUSE BAZEL IS NOT INSTALLED IN {platform.system()} PLATFORM YET.")
11+
exit(0)
12+
13+
output = run("bazel --version")
14+
15+
try:
16+
print("\n- Conan installing all the files into the build folder -\n")
17+
run("conan install . --build=missing")
18+
print("\n- Running bazel build command to compile the demo bazel target -\n")
19+
run("bazel --bazelrc=./conan/conan_bzl.rc build --config=conan-config //main:demo")
20+
print("\n- Running the application 'demo' created -\n")
21+
run("./bazel-bin/main/demo")
22+
finally:
23+
# Remove all the bazel symlinks and clean its cache
24+
run("bazel clean")
25+
shutil.rmtree("conan", ignore_errors=True)

0 commit comments

Comments
 (0)