File tree Expand file tree Collapse file tree 7 files changed +114
-1
lines changed Expand file tree Collapse file tree 7 files changed +114
-1
lines changed Original file line number Diff line number Diff line change
1
+ package (default_visibility = ["//visibility:public" ])
2
+
3
+ cc_binary (
4
+ name = "main" ,
5
+ srcs = ["main.cc" ],
6
+ deps = [
7
+ ":hello_world" ,
8
+ ],
9
+ )
10
+
11
+ cc_library (
12
+ name = "hello_world" ,
13
+ srcs = [
14
+ "hello_world.cc" ,
15
+ ],
16
+ hdrs = [
17
+ "hello_world.h" ,
18
+ ],
19
+ deps = [
20
+ ],
21
+ )
22
+
23
+ cc_test (
24
+ name = "hello_world_test" ,
25
+ srcs = [
26
+ "hello_world_test.cc" ,
27
+ ],
28
+ deps = [
29
+ ":hello_world" ,
30
+ "@com_google_googletest//:gtest_main" ,
31
+ ],
32
+ )
Original file line number Diff line number Diff line change 1
- # bazel_cpp_example
1
+ # Bazel C++ Example
2
+
3
+ Simple example to demonstrate how to use [ Bazel] ( https://bazel.build ) with C++.
Original file line number Diff line number Diff line change
1
+ # Bazel toolchains
2
+ http_archive (
3
+ name = "bazel_toolchains" ,
4
+ urls = [
5
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/r324073.tar.gz" ,
6
+ "https://github.com/bazelbuild/bazel-toolchains/archive/r324073.tar.gz" ,
7
+ ],
8
+ strip_prefix = "bazel-toolchains-r324073" ,
9
+ sha256 = "71548c0d6cd53eddebbde4fa9962f5395e82645fb9992719e0890505b177f245" ,
10
+ )
11
+
12
+ # GoogleTest/GoogleMock framework. Used by most unit-tests.
13
+ http_archive (
14
+ name = "com_google_googletest" ,
15
+ urls = ["https://github.com/google/googletest/archive/master.zip" ],
16
+ strip_prefix = "googletest-master" ,
17
+ )
18
+
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+
3
+ #include " hello_world.h"
4
+
5
+ namespace {
6
+ const char * message = " Hello World!" ;
7
+ }
8
+
9
+ namespace hello_world {
10
+
11
+ HelloWorld::HelloWorld () {}
12
+
13
+ std::string HelloWorld::Message () {
14
+ return message;
15
+ }
16
+
17
+ } // namespace hello_world
Original file line number Diff line number Diff line change
1
+ #ifndef HELLO_WORLD_H_
2
+ #define HELLO_WORLD_H_
3
+
4
+ #include < string>
5
+
6
+ namespace hello_world {
7
+
8
+ // HelloWorld is a simple class.
9
+ class HelloWorld {
10
+ public:
11
+ // HelloWorld constructor.
12
+ HelloWorld ();
13
+
14
+ // Message returns a Hello World message.
15
+ std::string Message ();
16
+ };
17
+
18
+ } // namespace hello_world
19
+
20
+ #endif // HELLO_WORLD_H_
Original file line number Diff line number Diff line change
1
+ #include " hello_world.h"
2
+
3
+ #include < iostream>
4
+
5
+ #include " gtest/gtest.h"
6
+
7
+ namespace {
8
+
9
+ TEST (HelloWorld, Message) {
10
+ auto msg = hello_world::HelloWorld ().Message ();
11
+ EXPECT_EQ (msg, " Hello World!" );
12
+ }
13
+
14
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ #include " hello_world.h"
4
+
5
+ int main (int argc, char ** argv) {
6
+ auto msg = hello_world::HelloWorld ().Message ();
7
+ std::cout << " stdout: " << msg << std::endl;
8
+ std::cerr << " stderr: " << msg << std::endl;
9
+ return 0 ;
10
+ }
You can’t perform that action at this time.
0 commit comments