From 9860f855f8895a477508ffc16a51a3a706848453 Mon Sep 17 00:00:00 2001 From: Naren Dasan Date: Tue, 12 Oct 2021 15:12:08 -0400 Subject: [PATCH] chore: example on how to use external trtorch as a dep Signed-off-by: Naren Dasan Signed-off-by: Naren Dasan --- BUILD | 2 +- bzl_def/BUILD | 81 ++++++++++++++++++++++++++++++++++++++++++--- bzl_def/BUILD.bazel | 6 ++++ bzl_def/BUILD.bzl | 79 ------------------------------------------- tests/util/BUILD | 20 +++++++++-- 5 files changed, 101 insertions(+), 87 deletions(-) create mode 100644 bzl_def/BUILD.bazel delete mode 100644 bzl_def/BUILD.bzl diff --git a/BUILD b/BUILD index 6e8fe1d1b3..805ee7c629 100644 --- a/BUILD +++ b/BUILD @@ -65,7 +65,7 @@ pkg_tar( name = "libtrtorch", srcs = [ "//:LICENSE", - "//bzl_def:BUILD.bzl", + "//bzl_def:BUILD", "//bzl_def:WORKSPACE" ], extension = "tar.gz", diff --git a/bzl_def/BUILD b/bzl_def/BUILD index e20e391a45..de5cb594ae 100644 --- a/bzl_def/BUILD +++ b/bzl_def/BUILD @@ -1,6 +1,79 @@ package(default_visibility = ["//visibility:public"]) -exports_files([ - "WORKSPACE", - "BUILD.bzl" -]) \ No newline at end of file +config_setting( + name = "aarch64_linux", + constraint_values = [ + "@platforms//cpu:aarch64", + "@platforms//os:linux", + ], +) + +config_setting( + name = "windows", + constraint_values = [ + "@platforms//os:windows", + ], +) + +cc_library( + name = "libtrtorch", + srcs = select({ + ":windows": [ + "lib/x64/trtorch.dll", + ], + "//conditions:default": [ + "lib/libtrtorch.so", + ], + }), + hdrs = glob([ + "include/**/*.h", + ]), + strip_include_prefix = "include", + includes = ["include/"] +) + +cc_library( + name = "libtrtorchrt", + srcs = select({ + ":windows": [ + "lib/x64/trtorchrt.dll" + ], + "//conditions:default": [ + "lib/libtrtorchrt.so" + ] + }) +) + +cc_library( + name = "libtrtorch_plugins", + srcs = select({ + ":windows": [ + "lib/x64/trtorch_plugins.dll" + ], + "//conditions:default": [ + "lib/libtrtorch_plugins.so" + ] + }), + hdrs = glob([ + "include/trtorch/core/plugins/**/*.h", + ]), + strip_include_prefix = "include", + includes = ["include/"] +) + +cc_library( + name = "trtorch_core_hdrs", + hdrs = glob([ + "include/trtorch/core/**/*.h" + ]), + strip_include_prefix = "include/trtorch", + includes = ["include/trtorch/"] +) + +# Alias for ease of use +cc_library( + name = "trtorch", + deps = [ + ":libtrtorch", + ] +) \ No newline at end of file diff --git a/bzl_def/BUILD.bazel b/bzl_def/BUILD.bazel new file mode 100644 index 0000000000..9dd0f59f6e --- /dev/null +++ b/bzl_def/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files([ + "WORKSPACE", + "BUILD" +]) \ No newline at end of file diff --git a/bzl_def/BUILD.bzl b/bzl_def/BUILD.bzl deleted file mode 100644 index e5419bf114..0000000000 --- a/bzl_def/BUILD.bzl +++ /dev/null @@ -1,79 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -config_setting( - name = "aarch64_linux", - constraint_values = [ - "@platforms//cpu:aarch64", - "@platforms//os:linux", - ], -) - -config_setting( - name = "windows", - constraint_values = [ - "@platforms//os:windows", - ], -) - -cc_library( - name = "libtrtorch", - srcs = select({ - ":windows": [ - "lib/x64/trtorch.dll", - ], - "//conditions:default": [ - "lib/libtrtorch.so", - ], - }), - hdrs = glob([ - "include/**/*.h", - ]), - strip_include_prefix = "include", - includes = ["include/"] -) - -cc_library( - name = "libtrtorchrt", - srcs = select({ - ":windows": [ - "lib/x64/trtorchrt.dll" - ], - "//conditions:default": [ - "lib/libtrtorchrt.so" - ] - }) -) - -cc_library( - name = "libtrtorch_plugins", - srcs = select({ - ":windows": [ - "lib/x64/trtorch_plugins.dll" - ], - "//conditions:default": [ - "lib/libtrtorch_plugins.so" - ] - }), - hdrs = glob([ - "include/trtorch/core/plugins/**/*.h", - ]), - strip_include_prefix = "include", - includes = ["include/"] -) - -cc_library( - name = "trtorch_core_hdrs", - hdrs = glob([ - "include/trtorch/core/**/*.h" - ]), - strip_include_prefix = "include", - includes = ["include/trtorch/"] -) - -# Alias for ease of use -cc_library( - name = "trtorch", - deps = [ - ":libtrtorch", - ] -) \ No newline at end of file diff --git a/tests/util/BUILD b/tests/util/BUILD index 6d2db65158..d3730e9c6a 100644 --- a/tests/util/BUILD +++ b/tests/util/BUILD @@ -7,6 +7,13 @@ config_setting( }, ) +config_setting( + name = "ci_build_testing", + values = { + "define": "trtorch_src=pre_built" + } +) + cc_library( name = "util", srcs = [ @@ -20,9 +27,6 @@ cc_library( "util.h", ], deps = [ - "//core/conversion", - "//core/util:prelude", - "//cpp:trtorch", "@tensorrt//:nvinfer", ] + select({ ":use_pre_cxx11_abi": [ @@ -33,5 +37,15 @@ cc_library( "@libtorch//:libtorch", "@libtorch//:caffe2", ], + }) + select({ + ":ci_build_testing": [ + "@trtorch//:trtorch", + "@trtorch//:trtorch_core_hdrs" + ], + "//conditions:default": [ + "//cpp:trtorch", + "//core/conversion", + "//core/util:prelude" + ] }), )