-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from andyjgf/bazexample
Add a bazel-built example.
- Loading branch information
Showing
15 changed files
with
238 additions
and
2 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
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,33 @@ | ||
# Bazel Example | ||
|
||
This directory shows an example of using LibCbor in a project that builds with Bazel. | ||
|
||
## Compile | ||
|
||
To build the project: | ||
|
||
```shell | ||
bazel build src:all | ||
``` | ||
|
||
## Test | ||
|
||
To test the code: | ||
|
||
```shell | ||
bazel test src:all | ||
``` | ||
|
||
## Run | ||
|
||
To run the demo: | ||
|
||
```shell | ||
bazel run src:hello | ||
``` | ||
|
||
or | ||
|
||
```shell | ||
bazel-bin/src/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,21 @@ | ||
workspace(name = "libcbor_bazel_example") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
# Google Test | ||
http_archive( | ||
name = "gtest", | ||
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91", | ||
strip_prefix = "googletest-release-1.10.0", | ||
url = "https://github.com/google/googletest/archive/release-1.10.0.zip", | ||
) | ||
|
||
# libcbor | ||
http_archive( | ||
name = "libcbor", | ||
build_file = "//third_party:libcbor.BUILD", | ||
sha256 = "dd04ea1a7df484217058d389e027e7a0143a4f245aa18a9f89a5dd3e1a4fcc9a", | ||
strip_prefix = "libcbor-0.8.0", | ||
urls = ["https://github.com/PJK/libcbor/archive/refs/tags/v0.8.0.zip"], | ||
) | ||
|
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,46 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
||
cc_library( | ||
name = "src", | ||
srcs = [ | ||
"hello.cc", | ||
], | ||
hdrs = [ | ||
"hello.h", | ||
], | ||
visibility = [ | ||
"//src:__pkg__", | ||
], | ||
deps = [ | ||
"@libcbor//:cbor", | ||
], | ||
) | ||
|
||
cc_test( | ||
name = "tests", | ||
size = "small", | ||
srcs = [ | ||
"hello_test.cc", | ||
], | ||
visibility = [ | ||
"//visibility:private", | ||
], | ||
deps = [ | ||
":src", | ||
"@gtest//:gtest_main", | ||
"@libcbor//:cbor", | ||
], | ||
) | ||
|
||
|
||
cc_binary( | ||
name = "hello", | ||
srcs = [ | ||
"main.cc", | ||
], | ||
deps = [ | ||
":src", | ||
], | ||
) | ||
|
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,8 @@ | ||
#include "src/hello.h" | ||
|
||
#include "cbor.h" | ||
|
||
uint8_t cbor_version() { | ||
return cbor_major_version; | ||
} | ||
|
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,8 @@ | ||
#ifndef HELLO_H_ | ||
#define HELLO_H_ | ||
|
||
#include <cstdint> | ||
|
||
uint8_t cbor_version(); | ||
|
||
#endif // HELLO_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,10 @@ | ||
#include "src/hello.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
class HelloTest : public ::testing::Test {}; | ||
|
||
TEST_F(HelloTest, CborVersion) { | ||
EXPECT_EQ(cbor_version(), 0); | ||
} | ||
|
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,9 @@ | ||
#include "src/hello.h" | ||
|
||
#include <stdio.h> | ||
|
||
int main() { | ||
printf("Hello, v=%d\n", cbor_version()); | ||
return 0; | ||
} | ||
|
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 @@ | ||
exports_files(["libcbor.BUILD"]) |
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,19 @@ | ||
cc_library( | ||
name = "cbor", | ||
srcs = glob([ | ||
"src/**/*.h", | ||
"src/**/*.c", | ||
|
||
]), | ||
deps = [ | ||
"@libcbor_bazel_example//third_party/libcbor:config", | ||
], | ||
hdrs = [ | ||
"src/cbor.h", | ||
], | ||
includes = [ | ||
"src", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
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,11 @@ | ||
cc_library( | ||
name = "config", | ||
hdrs = [ | ||
"cbor/cbor_export.h", | ||
"cbor/configuration.h", | ||
], | ||
includes = [ | ||
"./", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
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,42 @@ | ||
|
||
#ifndef CBOR_EXPORT_H | ||
#define CBOR_EXPORT_H | ||
|
||
#ifdef CBOR_STATIC_DEFINE | ||
#define CBOR_EXPORT | ||
#define CBOR_NO_EXPORT | ||
#else | ||
#ifndef CBOR_EXPORT | ||
#ifdef cbor_EXPORTS | ||
/* We are building this library */ | ||
#define CBOR_EXPORT | ||
#else | ||
/* We are using this library */ | ||
#define CBOR_EXPORT | ||
#endif | ||
#endif | ||
|
||
#ifndef CBOR_NO_EXPORT | ||
#define CBOR_NO_EXPORT | ||
#endif | ||
#endif | ||
|
||
#ifndef CBOR_DEPRECATED | ||
#define CBOR_DEPRECATED __attribute__((__deprecated__)) | ||
#endif | ||
|
||
#ifndef CBOR_DEPRECATED_EXPORT | ||
#define CBOR_DEPRECATED_EXPORT CBOR_EXPORT CBOR_DEPRECATED | ||
#endif | ||
|
||
#ifndef CBOR_DEPRECATED_NO_EXPORT | ||
#define CBOR_DEPRECATED_NO_EXPORT CBOR_NO_EXPORT CBOR_DEPRECATED | ||
#endif | ||
|
||
#if 0 /* DEFINE_NO_DEPRECATED */ | ||
#ifndef CBOR_NO_DEPRECATED | ||
#define CBOR_NO_DEPRECATED | ||
#endif | ||
#endif | ||
|
||
#endif /* CBOR_EXPORT_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,16 @@ | ||
#ifndef LIBCBOR_CONFIGURATION_H | ||
#define LIBCBOR_CONFIGURATION_H | ||
|
||
#define CBOR_MAJOR_VERSION 0 | ||
#define CBOR_MINOR_VERSION 8 | ||
#define CBOR_PATCH_VERSION 0 | ||
|
||
#define CBOR_CUSTOM_ALLOC 1 | ||
#define CBOR_BUFFER_GROWTH 2 | ||
#define CBOR_MAX_STACK_SIZE 2048 | ||
#define CBOR_PRETTY_PRINTER 1 | ||
|
||
#define CBOR_RESTRICT_SPECIFIER restrict | ||
#define CBOR_INLINE_SPECIFIER | ||
|
||
#endif // LIBCBOR_CONFIGURATION_H |