I have found several important things with Bazel and the GS registry that I thought that I should share here. There’s still a lot that I haven’t figured out and some that I am not sure of yet, but it’s better than I have found so far. Using this and GST/NVDS based code I’ve been able to create some very functional components for Graph Composer.
/opt/nvidia/graph-composer/extension-dev and specifically /opt/nvidia/graph-composer/extension-dev/build have pretty significant readmes, comments, and code structures that allowed me to figure this out… This is the first time that I have worked with bazel and I’m old, so don’t flame me too bad… :)
- Add a section to the WORKSPACE like below to downloads and include the extension headers directly.:
graph_nvidia_extension(
name = "NvDsInterfaceExt",
version = "1.0.0",
)
and to the BUILD file
graph_cc_extension(
...
srcs = [
"**ExtensionName**.cpp",
"**ComponentName1**.cpp",
"**ComponentName2**.cpp",
...
],
hdrs = [
"**ComponentName1**.hpp",
"**ComponentName2**.hpp",
...
],
deps = [
...
"@NvDsInterfaceExt",
...
],
...
)
...
register_extension(
...
ngc_dependencies = {
...
"NvDsInterfaceExt": "1.0.0",
...
},
...
)
- To add external libraries add a section to WORKSPACE like:
new_local_repository(
name = "gstreamer",
path = "/usr/include/gstreamer-1.0/",
build_file = "third_party/gstreamer.BUILD",
)
Then add a file like gstreamer.BUILD (or whatever) to a third_party directory directly under the directory containing the WORKSPACE:
cc_library(
name = "gstreamer",
hdrs = glob(["**/*.h"]),
deps = [],
includes = ["",],
visibility = ["//visibility:public"],
)
(**extension_root**
/third_party/gstreamer.BUILD where **extension root**
is the directory with the WORKSPACE file)
and to the BUILD file
...
register_extension(
...
ngc_dependencies = {
...
"@gstreamer",
...
},
...
)
- To include deepstream add a section to WORKSPACE like:
new_local_repository(
name = "DeepStream",
path = "/opt/nvidia/deepstream/deepstream-6.1/sources/",
build_file = "third_party/DeepStream.BUILD",
)
and create a **extension_root**
/third_party/DeepStream.BUILD with content like:
cc_library(
name = "DeepStream",
hdrs = glob(["**/*.h"]),
deps = [],
includes = ["includes/",],
visibility = ["//visibility:public"],
)
- To add a platform shared library: (the best way that I can figure out) first create a local repository for the headers and each platform type in the WORKSPACE (glib-2.0/include/glibconfig.h is different for the different platforms and the libglib-2.0.so ships with the platform image):
new_local_repository(
name = "glib",
path = "/usr/include/glib-2.0/",
build_file = "third_party/glib.BUILD",
)
new_local_repository(
name = "x86_64",
path = "/usr/lib/x86_64-linux-gnu/",
build_file = "third_party/config.BUILD",
)
new_local_repository(
name = "aarch64",
path = "/home/***Your User***/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_XAVIER_NX_TARGETS/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu/",
build_file = "third_party/config.BUILD",
)
then create a something like this as a config.BUILD:
cc_library(
name = "config",
hdrs = glob(["**/*.h"]),
deps = [":glibso"],
includes = ["glib-2.0/include/",],
visibility = ["//visibility:public"],
)
cc_import(
name = "glibso",
interface_library = "libglib-2.0.so",
system_provided = 1,
)
and something like this for the glib.BUILD:
cc_library(
name = "glib",
hdrs = glob(["**/*.h"]),
deps = select({
"@com_extension_dev//build:platform_x86_64": ["@x86_64//:config",],
"@com_extension_dev//build:platform_jetson": ["@aarch64//:config",],
}),
includes = [""],
visibility = ["//visibility:public"],
)
- Sample Directory Structure:
Directory Structure for above examples:
[ExtensionName]
extensions
[ExtensionName]
BUILD
[ExtensionName].cpp
[ComponentName1].h
[ComponentName1].c
[ComponentName2].h
[ComponentName2].c
third_party
config.BUILD
DeepStream.BUILD
glib.BUILD
gstreamer.BUILD
- Sample WORKSPACE (redacted):
_workspace_name = "**YourExtensionName**"
workspace(name = _workspace_name)
local_repository(
name = "com_extension_dev",
path = "/opt/nvidia/graph-composer/extension-dev"
)
load(
"@com_extension_dev//build:graph_extension.bzl",
"graph_nvidia_extension",
)
load("@com_extension_dev//build/toolchain:toolchain.bzl", "toolchain_configure")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
toolchain_configure(name = "toolchain")
new_git_repository(
name = "yaml-cpp",
build_file = "@com_extension_dev//build:third_party/yaml-cpp.BUILD",
commit = "9a3624205e8774953ef18f57067b3426c1c5ada6",
remote = "https://github.com/jbeder/yaml-cpp.git",
shallow_since = "1569430560 -0700",
)
http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
)
graph_nvidia_extension(
name = "StandardExtension",
version = "2.0.0",
)
graph_nvidia_extension(
name = "MultimediaExtension",
version = "2.0.0",
)
graph_nvidia_extension(
name = "NvDsBaseExt",
version = "1.0.0",
)
graph_nvidia_extension(
name = "NvDsInterfaceExt",
version = "1.0.0",
)
new_local_repository(
name = "gstreamer",
path = "/usr/include/gstreamer-1.0/",
build_file = "third_party/gstreamer.BUILD",
)
new_local_repository(
name = "glib",
path = "/usr/include/glib-2.0/",
build_file = "third_party/glib.BUILD",
)
new_local_repository(
name = "x86_64",
path = "/usr/lib/x86_64-linux-gnu/",
build_file = "third_party/config.BUILD",
)
new_local_repository(
name = "aarch64",
path = "/home/**your user**/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_XAVIER_NX_TARGETS/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu/",
build_file = "third_party/config.BUILD",
)
new_local_repository(
name = "DeepStream",
path = "/opt/nvidia/deepstream/deepstream-6.1/sources/",
build_file = "third_party/DeepStream.BUILD",
)
- Sample BUILD File (redacted):
load("@com_extension_dev//build:graph_extension.bzl", "graph_cc_extension")
load("@com_extension_dev//build:registry.bzl", "register_extension")
exports_files(["LICENSE"])
graph_cc_extension(
name = "**YourExtensionName**",
srcs = [
"**ExtensionName**.cpp",
"**ComponentName1**.cpp",
"**ComponentName2**.cpp",
...
],
hdrs = [
"**ComponentName1**.hpp",
"**ComponentName2**.hpp",
...
],
deps = [
"@StandardExtension",
"@NvDsBaseExt",
"@NvDsInterfaceExt",
"@DeepStream",
"@glib",
"@gstreamer",
] ,
copts = [
],
)
register_extension(
name = "register_**YourExtensionName**_ext",
badges = [""],
extension = "PmsiDsInsightExt",
labels = [
"something",
"something else",
],
license = "LICENSE",
license_file = ":LICENSE",
ngc_dependencies = {
"StandardExtension": "2.0.0",
"MultimediaExtension": "2.0.0",
"NvDsBaseExt": "1.0.0",
"NvDsInterfaceExt": "1.0.0",
},
priority = "1",
git_repository = "",
url = "www.example.com",
uuid = "**YourUUID**",
version = "1.0.0",
visibility = ["//visibility:public"],
)