This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,17 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "cd test-project && bazel build", | ||
"type": "shell", | ||
"group": "build", | ||
"presentation": { | ||
"reveal": "silent" | ||
}, | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains 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,24 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "hello-lib", | ||
srcs = ["hello-lib.cc"], | ||
hdrs = ["hello-lib.h"], | ||
) | ||
|
||
cc_binary( | ||
name = "hello-world", | ||
srcs = ["hello-world.cc"], | ||
deps = [":hello-lib"], | ||
) | ||
|
||
cc_test( | ||
name = "hello-test", | ||
srcs = ["hello-world.cc"], | ||
deps = [":hello-lib"], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
) |
This file contains 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 = "hello_world") |
This file contains 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,22 @@ | ||
#include "./hello-lib.h" | ||
|
||
#include <iostream> | ||
|
||
using std::cout; | ||
using std::endl; | ||
using std::string; | ||
|
||
namespace hello | ||
{ | ||
|
||
HelloLib::HelloLib(const string &greeting) | ||
: greeting_(new string(greeting)) | ||
{ | ||
} | ||
|
||
void HelloLib::greet(const string &thing) | ||
{ | ||
cout << *greeting_ << " " << thing << endl; | ||
} | ||
|
||
} // namespace hello |
This file contains 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,23 @@ | ||
#ifndef EXAMPLES_CPP_HELLO_LIB_H_ | ||
#define EXAMPLES_CPP_HELLO_LIB_H_ | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
namespace hello | ||
{ | ||
|
||
class HelloLib | ||
{ | ||
public: | ||
explicit HelloLib(const std::string &greeting); | ||
|
||
void greet(const std::string &thing); | ||
|
||
private: | ||
std::unique_ptr<const std::string> greeting_; | ||
}; | ||
|
||
} // namespace hello | ||
|
||
#endif // EXAMPLES_CPP_HELLO_LIB_H_ |
This file contains 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,28 @@ | ||
#include "./hello-lib.h" | ||
|
||
#include <string> | ||
|
||
using hello::HelloLib; | ||
using std::string; | ||
|
||
/** | ||
* This prints "Hello world". If it is run with arguments, it will use the first | ||
* argument instead of "world". Build and run //examples/cpp:hello-world to see | ||
* this program in action. | ||
* | ||
* This file does double-duty as a "test." It is a cc_binary, so it can also be | ||
* compiled as a cc_test and Bazel will decide on whether it passed or failed | ||
* based on exit code (which is always 0 here, so the test "passes"). See | ||
* hello-fail.cc for an example of making a test fail. | ||
*/ | ||
int main(int argc, char **argv) | ||
{ | ||
HelloLib lib("Hello"); | ||
string thing = "world"; | ||
if (argc > 1) | ||
{ | ||
thing = argv[1]; | ||
} | ||
lib.greet(thing); | ||
return 0; | ||
} |