From 009dd0239c6539001a46b9cff7d84e1db3dbd734 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Wed, 19 Feb 2020 22:27:18 -0500 Subject: [PATCH 01/18] begin stealing deploy script from 971, we need to change it to work with python binaries as well --- tools/BUILD | 7 +++++++ tools/deploy.bzl | 39 +++++++++++++++++++++++++++++++++++++++ tools/deploy.py | 0 3 files changed, 46 insertions(+) create mode 100644 tools/BUILD create mode 100644 tools/deploy.bzl create mode 100644 tools/deploy.py diff --git a/tools/BUILD b/tools/BUILD new file mode 100644 index 0000000..fa6aa32 --- /dev/null +++ b/tools/BUILD @@ -0,0 +1,7 @@ +from __future__ import print_function + +import sys +import subprocess +import re +import os + diff --git a/tools/deploy.bzl b/tools/deploy.bzl new file mode 100644 index 0000000..ea0e05e --- /dev/null +++ b/tools/deploy.bzl @@ -0,0 +1,39 @@ +def _deploy_impl(ctx): + all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist] + ctx.file_action( + output = ctx.outputs.executable, + executable = True, + content = '\n'.join([ + '#!/bin/bash', + 'set -e', + 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, + ] + ['%s %s --dirs %s -- %s "$@"' % ( + ctx.executable._downloader.short_path, + ' '.join([src.short_path for src in d.downloader_srcs]), + d.downloader_dir, + ctx.attr.default_target) for d in ctx.attr.dirs] + [ + 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, + ' '.join([src.short_path for src in all_files]), + ctx.attr.default_target), + ]), + ) + + ctx.file_action( + output = ctx.outputs._startlist, + content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n', + ) + + to_download = [ctx.outputs._startlist] + to_download += all_files + for d in ctx.attr.dirs: + to_download += d.downloader_srcs + + return struct( + runfiles = ctx.runfiles( + files = to_download + ctx.files._downloader, + transitive_files = ctx.attr._downloader.default_runfiles.files, + collect_data = True, + collect_default = True, + ), + files = depset([ctx.outputs.executable]), + ) diff --git a/tools/deploy.py b/tools/deploy.py new file mode 100644 index 0000000..e69de29 From 53f9fa3b63b6d288f610cc7f57ce2cbcbdad6491 Mon Sep 17 00:00:00 2001 From: Connor Worley Date: Thu, 20 Feb 2020 09:12:53 -0800 Subject: [PATCH 02/18] WIP wpi_artifact --- WORKSPACE | 372 +++++++++++++++------------- bazel/wpilib_artifact.bzl | 120 +++++++++ third_party/roborio_toolchain/BUILD | 2 +- 3 files changed, 320 insertions(+), 174 deletions(-) create mode 100644 bazel/wpilib_artifact.bzl diff --git a/WORKSPACE b/WORKSPACE index b965540..202b566 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -89,179 +89,205 @@ cc_library( ) """ -http_archive( - name = "wpilibc_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "wpilibc", - build_file = "//third_party/wpilibsuite:wpilibc.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "hal_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "hal", - build_file = "//third_party/wpilibsuite:hal.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "wpiutil_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "wpiutil", - build_file = "//third_party/wpilibsuite:wpiutil.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "ntcore_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "ntcore", - build_file = "//third_party/wpilibsuite:ntcore.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "cameraserver_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "cameraserver", - build_file = "//third_party/wpilibsuite:cameraserver.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "cscore_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "cscore", - build_file = "//third_party/wpilibsuite:cscore.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_api_cpp_hdrs", - build_file_content = hdrs_content, - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_api_cpp", - build_file = "//third_party/ctre/phoenix:api_cpp.BUILD", - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_core_hdrs", - build_file_content = hdrs_content, - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-headers.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_core", - build_file = "//third_party/ctre/phoenix:core.BUILD", - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_cci_hdrs", - build_file_content = hdrs_content, - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-headers.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_cci", - build_file = "//third_party/ctre/phoenix:cci.BUILD", - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_wpiapi_cpp_hdrs", - build_file_content = hdrs_content, - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ctre_phoenix_wpiapi_cpp", - build_file = "//third_party/ctre/phoenix:wpiapi_cpp.BUILD", - urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_netcomm_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-headers.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_netcomm", - build_file = "//third_party/ni_libraries:netcomm.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_chipobject_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-headers.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_chipobject", - build_file = "//third_party/ni_libraries:chipobject.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_runtime", - build_file = "//third_party/ni_libraries:runtime.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/runtime/{0}/runtime-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_visa_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-headers.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "ni_libraries_visa", - build_file = "//third_party/ni_libraries:visa.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -) - -http_archive( - name = "opencv_hdrs", - build_file_content = hdrs_content, - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-headers.zip".format(OPEN_CV_VERSION)], -) - -http_archive( - name = "opencv", - build_file = "//third_party/wpilibsuite:opencv.BUILD", - urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-linuxathenastatic.zip".format(OPEN_CV_VERSION)], -) +load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact") + +wpilib_artifact( + name = "wpilibc-cpp", + version = "2020.3.1", + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc", + config_settings={ + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "osxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:osx", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + } +) + +# http_archive( +# name = "wpilibc_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "wpilibc", +# build_file = "//third_party/wpilibsuite:wpilibc.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "hal_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "hal", +# build_file = "//third_party/wpilibsuite:hal.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "wpiutil_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "wpiutil", +# build_file = "//third_party/wpilibsuite:wpiutil.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "ntcore_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "ntcore", +# build_file = "//third_party/wpilibsuite:ntcore.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "cameraserver_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "cameraserver", +# build_file = "//third_party/wpilibsuite:cameraserver.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "cscore_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "cscore", +# build_file = "//third_party/wpilibsuite:cscore.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_api_cpp_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_api_cpp", +# build_file = "//third_party/ctre/phoenix:api_cpp.BUILD", +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_core_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-headers.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_core", +# build_file = "//third_party/ctre/phoenix:core.BUILD", +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_cci_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-headers.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_cci", +# build_file = "//third_party/ctre/phoenix:cci.BUILD", +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_wpiapi_cpp_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ctre_phoenix_wpiapi_cpp", +# build_file = "//third_party/ctre/phoenix:wpiapi_cpp.BUILD", +# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_netcomm_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-headers.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_netcomm", +# build_file = "//third_party/ni_libraries:netcomm.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-linuxathena.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_chipobject_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-headers.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_chipobject", +# build_file = "//third_party/ni_libraries:chipobject.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-linuxathena.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_runtime", +# build_file = "//third_party/ni_libraries:runtime.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/runtime/{0}/runtime-{0}-linuxathena.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_visa_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-headers.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "ni_libraries_visa", +# build_file = "//third_party/ni_libraries:visa.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-linuxathena.zip".format(NI_LIB_VERSION)], +# ) + +# http_archive( +# name = "opencv_hdrs", +# build_file_content = hdrs_content, +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-headers.zip".format(OPEN_CV_VERSION)], +# ) + +# http_archive( +# name = "opencv", +# build_file = "//third_party/wpilibsuite:opencv.BUILD", +# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-linuxathenastatic.zip".format(OPEN_CV_VERSION)], +# ) http_archive( name = "bazel_gazelle", diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl new file mode 100644 index 0000000..8b95783 --- /dev/null +++ b/bazel/wpilib_artifact.bzl @@ -0,0 +1,120 @@ +load( + "@bazel_tools//tools/build_defs/repo:utils.bzl", + "update_attrs", + "workspace_and_buildfile", +) + + +_wpilib_artifact_attrs = { + "version": attr.string(mandatory=True), + "base_url": attr.string(mandatory=True), + "config_settings": attr.string_list_dict(), + "deps": attr.string_list(), + + "has_hdrs": attr.bool(default=True), + "hdrs_sha256": attr.string(), + + "has_shared": attr.bool(default=True), +# "shared_sha256": attr.string(), + + "has_static": attr.bool(default=True), +# "static_sha256": attr.string(), + +# "has_debug": attr.bool(default=True), +# "debug_sha256": attr.string(), +} + +HEADER_BUILD_FILE_CONTENT = """ +cc_library( + name = "hdrs", + hdrs = glob([ + "hdrs/**/*.h", + "hdrs/**/*.inc", + "hdrs/**/*.inl", + ]), + includes = ["."], +) +""" + +def _wpilib_artifact_impl(ctx): + updated_attrs = {} + + output_build_file_content = "" + + if ctx.attr.has_hdrs: + hdrs_url = "{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( + base_url=ctx.attr.base_url, + name=ctx.attr.name, + version=ctx.attr.version, + ) + updated_attrs["hdrs_sha256"] = ctx.download_and_extract( + hdrs_url, + "hdrs", + ).sha256 + output_build_file_content += HEADER_BUILD_FILE_CONTENT + + for config_setting_name, config_setting_constraint_values in ctx.attr.config_settings.items(): + output_build_file_content += """ +config_setting( + name = "{config_setting_name}", + constraint_values = [{config_setting_constraint_values}], +) +""".format( + config_setting_name=config_setting_name, + config_setting_constraint_values=", ".join([ + "\"{}\"".format(config_setting_constraint_value) + for config_setting_constraint_value + in config_setting_constraint_values + ]), +) + + if ctx.attr.has_shared: + shared_url = "{base_url}/{name}/{version}/{name}-{version}-{config_setting_name}.zip".format( + base_url=ctx.attr.base_url, + name=ctx.attr.name, + version=ctx.attr.version, + config_setting_name=config_setting_name, + ) + ctx.download_and_extract( + shared_url, + "{config_setting_name}_shared".format(config_setting_name=config_setting_name), + ) + output_build_file_content += """ +cc_library( + name = "{config_setting_name}_shared", + srcs = glob([ + "{config_setting_name}_shared/**/*.so", + "{config_setting_name}_shared/**/*.so.*", + ]), +) +""".format(config_setting_name=config_setting_name) + + if ctx.attr.has_static: + static_url = "{base_url}/{name}/{version}/{name}-{version}-{config_setting_name}.zip".format( + base_url=ctx.attr.base_url, + name=ctx.attr.name, + version=ctx.attr.version, + config_setting_name=config_setting_name, + ) + ctx.download_and_extract( + static_url, + "{config_setting_name}_static".format(config_setting_name=config_setting_name), + ) + output_build_file_content += """ +cc_library( + name = "{config_setting_name}_static", + srcs = glob([ + "{config_setting_name}_static/**/*.a", + ]), +) +""".format(config_setting_name=config_setting_name) + + + + ctx.file("BUILD", output_build_file_content) + return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), updated_attrs) + +wpilib_artifact = repository_rule( + implementation = _wpilib_artifact_impl, + attrs = _wpilib_artifact_attrs, +) diff --git a/third_party/roborio_toolchain/BUILD b/third_party/roborio_toolchain/BUILD index 333a149..43682d8 100755 --- a/third_party/roborio_toolchain/BUILD +++ b/third_party/roborio_toolchain/BUILD @@ -80,7 +80,7 @@ toolchain( name = "roborio_toolchain_darwin", exec_compatible_with = [ "@platforms//cpu:x86_64", - "@platforms//os:macos", + "@platforms//os:osx", ], target_compatible_with = [ "@platforms//cpu:armv7", From b5e05f37f062affbc66573ded0ca099ab603850b Mon Sep 17 00:00:00 2001 From: Connor Worley Date: Thu, 20 Feb 2020 11:34:45 -0800 Subject: [PATCH 03/18] Working multiplatform wpilib artifacts --- WORKSPACE | 401 ++++++++++++--------- bazel/wpilib_artifact.bzl | 88 +++-- src/BUILD | 6 +- third_party/ctre/phoenix/BUILD | 0 third_party/ctre/phoenix/api_cpp.BUILD | 12 - third_party/ctre/phoenix/cci.BUILD | 11 - third_party/ctre/phoenix/core.BUILD | 10 - third_party/ctre/phoenix/wpiapi_cpp.BUILD | 10 - third_party/ni_libraries/BUILD | 0 third_party/ni_libraries/chipobject.BUILD | 11 - third_party/ni_libraries/netcomm.BUILD | 12 - third_party/ni_libraries/runtime.BUILD | 78 ---- third_party/ni_libraries/visa.BUILD | 10 - third_party/wpilibsuite/BUILD | 0 third_party/wpilibsuite/cameraserver.BUILD | 11 - third_party/wpilibsuite/cscore.BUILD | 12 - third_party/wpilibsuite/hal.BUILD | 13 - third_party/wpilibsuite/ntcore.BUILD | 11 - third_party/wpilibsuite/opencv.BUILD | 10 - third_party/wpilibsuite/wpilibc.BUILD | 14 - third_party/wpilibsuite/wpiutil.BUILD | 11 - 21 files changed, 288 insertions(+), 443 deletions(-) delete mode 100755 third_party/ctre/phoenix/BUILD delete mode 100755 third_party/ctre/phoenix/api_cpp.BUILD delete mode 100755 third_party/ctre/phoenix/cci.BUILD delete mode 100755 third_party/ctre/phoenix/core.BUILD delete mode 100755 third_party/ctre/phoenix/wpiapi_cpp.BUILD delete mode 100755 third_party/ni_libraries/BUILD delete mode 100755 third_party/ni_libraries/chipobject.BUILD delete mode 100755 third_party/ni_libraries/netcomm.BUILD delete mode 100755 third_party/ni_libraries/runtime.BUILD delete mode 100755 third_party/ni_libraries/visa.BUILD delete mode 100755 third_party/wpilibsuite/BUILD delete mode 100755 third_party/wpilibsuite/cameraserver.BUILD delete mode 100755 third_party/wpilibsuite/cscore.BUILD delete mode 100755 third_party/wpilibsuite/hal.BUILD delete mode 100755 third_party/wpilibsuite/ntcore.BUILD delete mode 100755 third_party/wpilibsuite/opencv.BUILD delete mode 100755 third_party/wpilibsuite/wpilibc.BUILD delete mode 100755 third_party/wpilibsuite/wpiutil.BUILD diff --git a/WORKSPACE b/WORKSPACE index 202b566..825f009 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -91,18 +91,120 @@ cc_library( load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact") +common_variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "osxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:osx", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], +} + wpilib_artifact( name = "wpilibc-cpp", - version = "2020.3.1", + version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc", - config_settings={ + variants = common_variants, + deps = [ + "@cameraserver-cpp//:cameraserver-cpp", + "@hal-cpp//:hal-cpp", + "@netcomm//:netcomm", + "@ntcore-cpp//:ntcore-cpp", + ], +) + +wpilib_artifact( + name = "hal-cpp", + version = WPILIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal", + variants = common_variants, + deps = [ + "@visa//:visa", + "@wpiutil-cpp//:wpiutil-cpp", + ], +) + +wpilib_artifact( + name = "wpiutil-cpp", + version = WPILIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil", + variants = common_variants, +) + +wpilib_artifact( + name = "ntcore-cpp", + version = WPILIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore", + variants = common_variants, + deps = [ + "@wpiutil-cpp//:wpiutil-cpp", + ], +) + +wpilib_artifact( + name = "cameraserver-cpp", + version = WPILIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver", + variants = common_variants, + deps = [ + "@cscore-cpp//:cscore-cpp", + ], +) + +wpilib_artifact( + name = "cscore-cpp", + version = WPILIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore", + variants = common_variants, + deps = [ + "@opencv-cpp//:opencv-cpp", + "@wpiutil-cpp//:wpiutil-cpp", + ], +) + +wpilib_artifact( + name = "api-cpp", + version = CTRE_LIB_VERSION, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { "linuxathena": [ "@platforms//cpu:armv7", "@platforms//os:linux", ], - "osxx86-64": [ + "linuxx86-64": [ "@platforms//cpu:x86_64", - "@platforms//os:osx", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + deps = [ + "@cci//:cci", + "@wpiapi-cpp//:wpiapi-cpp", + ], +) + +wpilib_artifact( + name = "core", + version = CTRE_LIB_VERSION, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", ], "linuxx86-64": [ "@platforms//cpu:x86_64", @@ -112,182 +214,125 @@ wpilib_artifact( "@platforms//cpu:x86_64", "@platforms//os:windows", ], - } + }, + has_shared=False, ) -# http_archive( -# name = "wpilibc_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "wpilibc", -# build_file = "//third_party/wpilibsuite:wpilibc.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc/wpilibc-cpp/{0}/wpilibc-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "hal_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "hal", -# build_file = "//third_party/wpilibsuite:hal.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal/hal-cpp/{0}/hal-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "wpiutil_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "wpiutil", -# build_file = "//third_party/wpilibsuite:wpiutil.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil/wpiutil-cpp/{0}/wpiutil-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "ntcore_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "ntcore", -# build_file = "//third_party/wpilibsuite:ntcore.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore/ntcore-cpp/{0}/ntcore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "cameraserver_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "cameraserver", -# build_file = "//third_party/wpilibsuite:cameraserver.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver/cameraserver-cpp/{0}/cameraserver-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "cscore_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-headers.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "cscore", -# build_file = "//third_party/wpilibsuite:cscore.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore/cscore-cpp/{0}/cscore-cpp-{0}-linuxathenastatic.zip".format(WPILIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_api_cpp_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_api_cpp", -# build_file = "//third_party/ctre/phoenix:api_cpp.BUILD", -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/api-cpp/{0}/api-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_core_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-headers.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_core", -# build_file = "//third_party/ctre/phoenix:core.BUILD", -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/core/{0}/core-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_cci_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-headers.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_cci", -# build_file = "//third_party/ctre/phoenix:cci.BUILD", -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/cci/{0}/cci-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_wpiapi_cpp_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-headers.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ctre_phoenix_wpiapi_cpp", -# build_file = "//third_party/ctre/phoenix:wpiapi_cpp.BUILD", -# urls = ["https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/wpiapi-cpp/{0}/wpiapi-cpp-{0}-linuxathenastatic.zip".format(CTRE_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_netcomm_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-headers.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_netcomm", -# build_file = "//third_party/ni_libraries:netcomm.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/netcomm/{0}/netcomm-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_chipobject_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-headers.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_chipobject", -# build_file = "//third_party/ni_libraries:chipobject.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/chipobject/{0}/chipobject-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_runtime", -# build_file = "//third_party/ni_libraries:runtime.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/runtime/{0}/runtime-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_visa_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-headers.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "ni_libraries_visa", -# build_file = "//third_party/ni_libraries:visa.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries/visa/{0}/visa-{0}-linuxathena.zip".format(NI_LIB_VERSION)], -# ) - -# http_archive( -# name = "opencv_hdrs", -# build_file_content = hdrs_content, -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-headers.zip".format(OPEN_CV_VERSION)], -# ) - -# http_archive( -# name = "opencv", -# build_file = "//third_party/wpilibsuite:opencv.BUILD", -# urls = ["https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv/opencv-cpp/{0}/opencv-cpp-{0}-linuxathenastatic.zip".format(OPEN_CV_VERSION)], -# ) +wpilib_artifact( + name = "cci", + version = CTRE_LIB_VERSION, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + deps = [ + "@core//:core", + ], +) + +wpilib_artifact( + name = "wpiapi-cpp", + version = CTRE_LIB_VERSION, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, +) + +wpilib_artifact( + name = "netcomm", + version = NI_LIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + + has_static=False, + deps = [ + "@chipobject//:chipobject", + "@runtime//:runtime", + ], +) + +wpilib_artifact( + name = "chipobject", + version = NI_LIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_static=False, + deps = [ + "@runtime//:runtime", + ], +) + +wpilib_artifact( + name = "runtime", + version = NI_LIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_hdrs=False, + has_static=False, + deps = [ + "@hal-cpp//:hal-cpp", + ], +) + +wpilib_artifact( + name = "visa", + version = NI_LIB_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_static=False, +) + +wpilib_artifact( + name = "opencv-cpp", + version = OPEN_CV_VERSION, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv", + variants = common_variants, +) http_archive( name = "bazel_gazelle", diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 8b95783..613beed 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -8,7 +8,7 @@ load( _wpilib_artifact_attrs = { "version": attr.string(mandatory=True), "base_url": attr.string(mandatory=True), - "config_settings": attr.string_list_dict(), + "variants": attr.string_list_dict(), "deps": attr.string_list(), "has_hdrs": attr.bool(default=True), @@ -32,7 +32,7 @@ cc_library( "hdrs/**/*.inc", "hdrs/**/*.inl", ]), - includes = ["."], + includes = ["hdrs"], ) """ @@ -53,66 +53,102 @@ def _wpilib_artifact_impl(ctx): ).sha256 output_build_file_content += HEADER_BUILD_FILE_CONTENT - for config_setting_name, config_setting_constraint_values in ctx.attr.config_settings.items(): + for variant_name, variant_constraint_values in ctx.attr.variants.items(): output_build_file_content += """ config_setting( - name = "{config_setting_name}", - constraint_values = [{config_setting_constraint_values}], + name = "{variant_name}_config", + constraint_values = [{variant_constraint_values}], ) """.format( - config_setting_name=config_setting_name, - config_setting_constraint_values=", ".join([ - "\"{}\"".format(config_setting_constraint_value) - for config_setting_constraint_value - in config_setting_constraint_values + variant_name=variant_name, + variant_constraint_values=", ".join([ + "\"{}\"".format(variant_constraint_value) + for variant_constraint_value + in variant_constraint_values ]), ) if ctx.attr.has_shared: - shared_url = "{base_url}/{name}/{version}/{name}-{version}-{config_setting_name}.zip".format( + shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( base_url=ctx.attr.base_url, name=ctx.attr.name, version=ctx.attr.version, - config_setting_name=config_setting_name, + variant_name=variant_name, ) ctx.download_and_extract( shared_url, - "{config_setting_name}_shared".format(config_setting_name=config_setting_name), + "{variant_name}_shared".format(variant_name=variant_name), ) output_build_file_content += """ cc_library( - name = "{config_setting_name}_shared", - srcs = glob([ - "{config_setting_name}_shared/**/*.so", - "{config_setting_name}_shared/**/*.so.*", - ]), + name = "{variant_name}_shared", + srcs = glob( + [ + "{variant_name}_shared/**/*.so", + "{variant_name}_shared/**/*.so.*", + ], + exclude = ["{variant_name}_shared/**/*.debug"], + ), ) -""".format(config_setting_name=config_setting_name) +""".format(variant_name=variant_name) if ctx.attr.has_static: - static_url = "{base_url}/{name}/{version}/{name}-{version}-{config_setting_name}.zip".format( + static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( base_url=ctx.attr.base_url, name=ctx.attr.name, version=ctx.attr.version, - config_setting_name=config_setting_name, + variant_name=variant_name, ) ctx.download_and_extract( static_url, - "{config_setting_name}_static".format(config_setting_name=config_setting_name), + "{variant_name}_static".format(variant_name=variant_name), ) output_build_file_content += """ cc_library( - name = "{config_setting_name}_static", + name = "{variant_name}_static", srcs = glob([ - "{config_setting_name}_static/**/*.a", + "{variant_name}_static/**/*.a", ]), ) -""".format(config_setting_name=config_setting_name) +""".format(variant_name=variant_name) + deps = "[]" + if ctx.attr.has_hdrs: + deps += "+ [\":hdrs\"]" + + if ctx.attr.has_shared: + deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ + "\":{variant_name}_config\": [\":{variant_name}_shared\"]".format(variant_name=variant_name) + for variant_name + in ctx.attr.variants.keys() + ])) + + if ctx.attr.has_static: + deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ + "\":{variant_name}_config\": [\":{variant_name}_static\"]".format(variant_name=variant_name) + for variant_name + in ctx.attr.variants.keys() + ])) + + deps += "+ [{}]".format(", ".join([ + "\"{dep}\"".format(dep=dep) + for dep in ctx.attr.deps + ])) + + output_build_file_content += """ +cc_library( + name = "{name}", + deps = {deps}, + visibility = ["//visibility:public"], +) +""".format( + name=ctx.attr.name, + deps=deps, +) ctx.file("BUILD", output_build_file_content) - return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), updated_attrs) + return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), {}) #updated_attrs) wpilib_artifact = repository_rule( implementation = _wpilib_artifact_impl, diff --git a/src/BUILD b/src/BUILD index 2ca14e0..5c720db 100644 --- a/src/BUILD +++ b/src/BUILD @@ -5,10 +5,10 @@ cc_binary( "main.cpp", "main.h", ], - copts = [], + copts = ["-std=c++17"], deps = [ - "@ctre_phoenix_api_cpp", + "@api-cpp", # ctre "@eigen", - "@wpilibc", + "@wpilibc-cpp", ], ) diff --git a/third_party/ctre/phoenix/BUILD b/third_party/ctre/phoenix/BUILD deleted file mode 100755 index e69de29..0000000 diff --git a/third_party/ctre/phoenix/api_cpp.BUILD b/third_party/ctre/phoenix/api_cpp.BUILD deleted file mode 100755 index 9551707..0000000 --- a/third_party/ctre/phoenix/api_cpp.BUILD +++ /dev/null @@ -1,12 +0,0 @@ -cc_library( - name = "ctre_phoenix_api_cpp", - srcs = [ - "linux/athena/static/libCTRE_Phoenix.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@ctre_phoenix_api_cpp_hdrs//:hdrs", - "@ctre_phoenix_cci", - "@ctre_phoenix_wpiapi_cpp", - ], -) diff --git a/third_party/ctre/phoenix/cci.BUILD b/third_party/ctre/phoenix/cci.BUILD deleted file mode 100755 index 67d4d5b..0000000 --- a/third_party/ctre/phoenix/cci.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -cc_library( - name = "ctre_phoenix_cci", - srcs = [ - "linux/athena/static/libCTRE_PhoenixCCI.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@ctre_phoenix_cci_hdrs//:hdrs", - "@ctre_phoenix_core", - ], -) diff --git a/third_party/ctre/phoenix/core.BUILD b/third_party/ctre/phoenix/core.BUILD deleted file mode 100755 index 13ae185..0000000 --- a/third_party/ctre/phoenix/core.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -cc_library( - name = "ctre_phoenix_core", - srcs = [ - "linux/athena/static/libCTRE_PhoenixCore.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@ctre_phoenix_core_hdrs//:hdrs", - ], -) diff --git a/third_party/ctre/phoenix/wpiapi_cpp.BUILD b/third_party/ctre/phoenix/wpiapi_cpp.BUILD deleted file mode 100755 index d381a8f..0000000 --- a/third_party/ctre/phoenix/wpiapi_cpp.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -cc_library( - name = "ctre_phoenix_wpiapi_cpp", - srcs = [ - "linux/athena/static/libCTRE_Phoenix_WPI.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@ctre_phoenix_wpiapi_cpp_hdrs//:hdrs", - ], -) diff --git a/third_party/ni_libraries/BUILD b/third_party/ni_libraries/BUILD deleted file mode 100755 index e69de29..0000000 diff --git a/third_party/ni_libraries/chipobject.BUILD b/third_party/ni_libraries/chipobject.BUILD deleted file mode 100755 index 54873b9..0000000 --- a/third_party/ni_libraries/chipobject.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -cc_library( - name = "ni_libraries_chipobject", - srcs = [ - "linux/athena/shared/libRoboRIO_FRC_ChipObject.so.20.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - "@ni_libraries_chipobject_hdrs//:hdrs", - "@ni_libraries_runtime//:ni_libraries_runtime_NiFpgaLv", - ], -) diff --git a/third_party/ni_libraries/netcomm.BUILD b/third_party/ni_libraries/netcomm.BUILD deleted file mode 100755 index b11c427..0000000 --- a/third_party/ni_libraries/netcomm.BUILD +++ /dev/null @@ -1,12 +0,0 @@ -cc_library( - name = "ni_libraries_netcomm", - srcs = [ - "linux/athena/shared/libFRC_NetworkCommunication.so.20.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - "@ni_libraries_chipobject", - "@ni_libraries_netcomm_hdrs//:hdrs", - "@ni_libraries_runtime//:ni_libraries_runtime_nirio_emb_can", - ], -) diff --git a/third_party/ni_libraries/runtime.BUILD b/third_party/ni_libraries/runtime.BUILD deleted file mode 100755 index 6b92458..0000000 --- a/third_party/ni_libraries/runtime.BUILD +++ /dev/null @@ -1,78 +0,0 @@ -cc_library( - name = "ni_libraries_runtime_nirio_emb_can", - srcs = [ - "linux/athena/shared/libnirio_emb_can.so.16.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - ":ni_libraries_runtime_ni_emb", - ], -) - -cc_library( - name = "ni_libraries_runtime_ni_emb", - srcs = [ - "linux/athena/shared/libni_emb.so.12.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - ":ni_libraries_runtime_ni_rtlog", - ], -) - -cc_library( - name = "ni_libraries_runtime_ni_rtlog", - srcs = [ - "linux/athena/shared/libni_rtlog.so.2.8.0", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "ni_libraries_runtime_NiFpgaLv", - srcs = [ - "linux/athena/shared/libNiFpgaLv.so.19.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - ":ni_libraries_runtime_NiFpga", - "@hal", - ], -) - -cc_library( - name = "ni_libraries_runtime_NiFpga", - srcs = [ - "linux/athena/shared/libNiFpga.so.19.0.0", - ], - visibility = ["//visibility:public"], - deps = [ - ":ni_libraries_runtime_NiRioSrv", - ":ni_libraries_runtime_niriodevenum", - ":ni_libraries_runtime_niriosession", - ], -) - -cc_library( - name = "ni_libraries_runtime_niriodevenum", - srcs = [ - "linux/athena/shared/libniriodevenum.so.19.0.0", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "ni_libraries_runtime_niriosession", - srcs = [ - "linux/athena/shared/libniriosession.so.18.0.0", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "ni_libraries_runtime_NiRioSrv", - srcs = [ - "linux/athena/shared/libNiRioSrv.so.19.0.0", - ], - visibility = ["//visibility:public"], -) diff --git a/third_party/ni_libraries/visa.BUILD b/third_party/ni_libraries/visa.BUILD deleted file mode 100755 index da2c459..0000000 --- a/third_party/ni_libraries/visa.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -cc_library( - name = "ni_libraries_visa", - srcs = [ - "linux/athena/shared/libvisa.so", - ], - visibility = ["//visibility:public"], - deps = [ - "@ni_libraries_visa_hdrs//:hdrs", - ], -) diff --git a/third_party/wpilibsuite/BUILD b/third_party/wpilibsuite/BUILD deleted file mode 100755 index e69de29..0000000 diff --git a/third_party/wpilibsuite/cameraserver.BUILD b/third_party/wpilibsuite/cameraserver.BUILD deleted file mode 100755 index d56e6a6..0000000 --- a/third_party/wpilibsuite/cameraserver.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -cc_library( - name = "cameraserver", - srcs = [ - "linux/athena/static/libcameraserver.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@cameraserver_hdrs//:hdrs", - "@cscore", - ], -) diff --git a/third_party/wpilibsuite/cscore.BUILD b/third_party/wpilibsuite/cscore.BUILD deleted file mode 100755 index 45c34cc..0000000 --- a/third_party/wpilibsuite/cscore.BUILD +++ /dev/null @@ -1,12 +0,0 @@ -cc_library( - name = "cscore", - srcs = [ - "linux/athena/static/libcscore.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@cscore_hdrs//:hdrs", - "@opencv", - "@wpiutil", - ], -) diff --git a/third_party/wpilibsuite/hal.BUILD b/third_party/wpilibsuite/hal.BUILD deleted file mode 100755 index f802211..0000000 --- a/third_party/wpilibsuite/hal.BUILD +++ /dev/null @@ -1,13 +0,0 @@ -cc_library( - name = "hal", - srcs = [ - "linux/athena/static/libwpiHal.a", - ], - linkopts = ["-lm"], - visibility = ["//visibility:public"], - deps = [ - "@hal_hdrs//:hdrs", - "@ni_libraries_visa", - "@wpiutil", - ], -) diff --git a/third_party/wpilibsuite/ntcore.BUILD b/third_party/wpilibsuite/ntcore.BUILD deleted file mode 100755 index 5652eca..0000000 --- a/third_party/wpilibsuite/ntcore.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -cc_library( - name = "ntcore", - srcs = [ - "linux/athena/static/libntcore.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@ntcore_hdrs//:hdrs", - "@wpiutil", - ], -) diff --git a/third_party/wpilibsuite/opencv.BUILD b/third_party/wpilibsuite/opencv.BUILD deleted file mode 100755 index 7e62e3a..0000000 --- a/third_party/wpilibsuite/opencv.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -cc_library( - name = "opencv", - srcs = [ - "linux/athena/static/libopencv347.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@opencv_hdrs//:hdrs", - ], -) diff --git a/third_party/wpilibsuite/wpilibc.BUILD b/third_party/wpilibsuite/wpilibc.BUILD deleted file mode 100755 index 1f724c3..0000000 --- a/third_party/wpilibsuite/wpilibc.BUILD +++ /dev/null @@ -1,14 +0,0 @@ -cc_library( - name = "wpilibc", - srcs = [ - "linux/athena/static/libwpilibc.a", - ], - visibility = ["//visibility:public"], - deps = [ - "@cameraserver", - "@hal", - "@ni_libraries_netcomm", - "@ntcore", - "@wpilibc_hdrs//:hdrs", - ], -) diff --git a/third_party/wpilibsuite/wpiutil.BUILD b/third_party/wpilibsuite/wpiutil.BUILD deleted file mode 100755 index 65e7037..0000000 --- a/third_party/wpilibsuite/wpiutil.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -cc_library( - name = "wpiutil", - srcs = [ - "linux/athena/static/libwpiutil.a", - ], - linkopts = ["-lpthread"], - visibility = ["//visibility:public"], - deps = [ - "@wpiutil_hdrs//:hdrs", - ], -) From a47031422db5eec501d108e1e76d94e5d35003f1 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Thu, 20 Feb 2020 16:22:23 -0500 Subject: [PATCH 04/18] added linkopts to wpilib_artifact rule --- WORKSPACE | 1 + bazel/wpilib_artifact.bzl | 3 +++ src/main.cpp | 2 ++ src/main.h | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 825f009..6120fa9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -191,6 +191,7 @@ wpilib_artifact( ], }, has_shared=False, + linkopts = ["-pthread"], deps = [ "@cci//:cci", "@wpiapi-cpp//:wpiapi-cpp", diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 613beed..392115e 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -10,6 +10,7 @@ _wpilib_artifact_attrs = { "base_url": attr.string(mandatory=True), "variants": attr.string_list_dict(), "deps": attr.string_list(), + "linkopts" : attr.string_list(), "has_hdrs": attr.bool(default=True), "hdrs_sha256": attr.string(), @@ -140,11 +141,13 @@ cc_library( cc_library( name = "{name}", deps = {deps}, + linkopts = {linkopts}, visibility = ["//visibility:public"], ) """.format( name=ctx.attr.name, deps=deps, + linkopts=ctx.attr.linkopts ) ctx.file("BUILD", output_build_file_content) diff --git a/src/main.cpp b/src/main.cpp index e325f1b..568f9f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,8 @@ #include +TalonSRX talon{1}; + int main() { std::cout << "Yeet" << std::endl; diff --git a/src/main.h b/src/main.h index 0e1e5d4..2d85962 100644 --- a/src/main.h +++ b/src/main.h @@ -2,4 +2,6 @@ #include -#include \ No newline at end of file +#include +#include "ctre/Phoenix.h" +#include "ctre/phoenix/motorcontrol/can/TalonSRX.h" \ No newline at end of file From f0441682a1301ac4eafd9a636f7e297f9311242a Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Thu, 20 Feb 2020 16:32:39 -0500 Subject: [PATCH 05/18] format --- src/main.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.h b/src/main.h index 2d85962..f005819 100644 --- a/src/main.h +++ b/src/main.h @@ -3,5 +3,6 @@ #include #include + #include "ctre/Phoenix.h" #include "ctre/phoenix/motorcontrol/can/TalonSRX.h" \ No newline at end of file From 3923a38a2325f8baeff051f46f4feb67c529a83b Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 03:50:13 -0500 Subject: [PATCH 06/18] macro works a little --- WORKSPACE | 32 +++--- bazel/wpilib_artifact.bzl | 215 +++++++++++++++++++++++++++++--------- 2 files changed, 179 insertions(+), 68 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 6120fa9..b07cbef 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -89,7 +89,7 @@ cc_library( ) """ -load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact") +load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact", "generate_wpilib_archives") common_variants = { "linuxathena": [ @@ -110,7 +110,7 @@ common_variants = { ], } -wpilib_artifact( +generate_wpilib_archives( name = "wpilibc-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc", @@ -123,7 +123,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "hal-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal", @@ -134,14 +134,14 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "wpiutil-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil", variants = common_variants, ) -wpilib_artifact( +generate_wpilib_archives( name = "ntcore-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore", @@ -151,7 +151,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "cameraserver-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver", @@ -161,7 +161,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "cscore-cpp", version = WPILIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore", @@ -172,7 +172,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "api-cpp", version = CTRE_LIB_VERSION, base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", @@ -198,7 +198,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "core", version = CTRE_LIB_VERSION, base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", @@ -219,7 +219,7 @@ wpilib_artifact( has_shared=False, ) -wpilib_artifact( +generate_wpilib_archives( name = "cci", version = CTRE_LIB_VERSION, base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", @@ -243,7 +243,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "wpiapi-cpp", version = CTRE_LIB_VERSION, base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", @@ -264,7 +264,7 @@ wpilib_artifact( has_shared=False, ) -wpilib_artifact( +generate_wpilib_archives( name = "netcomm", version = NI_LIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", @@ -282,7 +282,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "chipobject", version = NI_LIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", @@ -298,7 +298,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "runtime", version = NI_LIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", @@ -315,7 +315,7 @@ wpilib_artifact( ], ) -wpilib_artifact( +generate_wpilib_archives( name = "visa", version = NI_LIB_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", @@ -328,7 +328,7 @@ wpilib_artifact( has_static=False, ) -wpilib_artifact( +generate_wpilib_archives( name = "opencv-cpp", version = OPEN_CV_VERSION, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv", diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 392115e..5a03045 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -3,7 +3,88 @@ load( "update_attrs", "workspace_and_buildfile", ) +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +def generate_all_configs(variants = {}): + pass + +def generate_wpilib_archives(name, version, base_url, variants, has_hdrs=True, has_shared=True, has_static=True, deps=[], linkopts=[]): + hdrs_url="{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( + base_url=base_url, + name=name, + version=version, + ) + + if(has_hdrs): + build_file = """ +cc_library( + name = "{name}_hdrs", + hdrs = glob([ + "**/*.h", + "**/*.inc", + "**/*.inl", + ]), + includes = ["."], +) + """.format(name=name) + + http_archive( + name="{name}_hdrs".format(name=name), + urls=["{url}".format(url=hdrs_url)], + build_file_content="""{}""".format(build_file) + ) + for variant_name, variant_constraint_values in variants.items(): + if(has_shared): + shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( + base_url=base_url, + name=name, + version=version, + variant_name=variant_name, + ) + + build_file = """ +cc_library( + name = "{name}_{variant_name}_shared", + srcs = glob( + [ + "**/*.so", + "**/*.so.*", + ], + exclude = ["**/*.debug"], + ), + visibility=["//visibility:public"] +) + """.format(name=name, variant_name=variant_name) + + http_archive( + name="{name}_{variant_name}_shared".format(name=name, variant_name=variant_name), + urls = ["{url}".format(url=shared_url)], + build_file_content="""{}""".format(build_file) + ) + + if(has_static): + static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( + base_url=base_url, + name=name, + version=version, + variant_name=variant_name, + ) + + build_file = """ +cc_library( + name = "{name}_{variant_name}_static", + srcs = glob([ + "**/*.a", + ]), + visibility=["//visibility:public"] +) + """.format(name=name, variant_name=variant_name) + + http_archive( + name="{name}_{variant_name}_static".format(name=name, variant_name=variant_name), + urls = ["{url}".format(url=static_url)], + build_file_content="""{}""".format(build_file) + ) _wpilib_artifact_attrs = { "version": attr.string(mandatory=True), @@ -25,50 +106,61 @@ _wpilib_artifact_attrs = { # "debug_sha256": attr.string(), } -HEADER_BUILD_FILE_CONTENT = """ -cc_library( - name = "hdrs", - hdrs = glob([ - "hdrs/**/*.h", - "hdrs/**/*.inc", - "hdrs/**/*.inl", - ]), - includes = ["hdrs"], -) -""" - def _wpilib_artifact_impl(ctx): updated_attrs = {} + output_workspace_file_content = "" output_build_file_content = "" + output_workspace_file_content += "load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\") \n" + + # generate WORKSPACE + # config settings + for variant_name, variant_constraint_values in ctx.attr.variants.items(): + output_build_file_content += """ +config_setting( + name = "{variant_name}_config", + constraint_values = [{variant_constraint_values}], +) \n + """.format( + variant_name=variant_name, + variant_constraint_values = ", ".join([ + "\"{}\"".format(variant_constraint_value) + for variant_constraint_value + in variant_constraint_values + ]) + ) + + # generate headers rule if ctx.attr.has_hdrs: hdrs_url = "{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( base_url=ctx.attr.base_url, name=ctx.attr.name, version=ctx.attr.version, ) - updated_attrs["hdrs_sha256"] = ctx.download_and_extract( - hdrs_url, - "hdrs", - ).sha256 - output_build_file_content += HEADER_BUILD_FILE_CONTENT - - for variant_name, variant_constraint_values in ctx.attr.variants.items(): - output_build_file_content += """ -config_setting( - name = "{variant_name}_config", - constraint_values = [{variant_constraint_values}], -) -""".format( - variant_name=variant_name, - variant_constraint_values=", ".join([ - "\"{}\"".format(variant_constraint_value) - for variant_constraint_value - in variant_constraint_values + hdr = """ +cc_library( + name = "{}_hdrs", + hdrs = glob([ + "**/*.h", + "**/*.inc", + "**/*.inl", ]), + visibility=["//visibility:public"] ) +""".format(ctx.attr.name) + + output_workspace_file_content += """ +http_archive( + name="{name}_hdrs", + urls = ["{url}"], + build_file_content = \"\"\"{build_file_content}\"\"\" +) \n + """.format(name=ctx.attr.name, url=hdrs_url, build_file_content=hdr) + + # generate http archives for shared and static libraries + for variant_name, variant_constraint_values in ctx.attr.variants.items(): if ctx.attr.has_shared: shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( base_url=ctx.attr.base_url, @@ -76,23 +168,34 @@ config_setting( version=ctx.attr.version, variant_name=variant_name, ) - ctx.download_and_extract( - shared_url, - "{variant_name}_shared".format(variant_name=variant_name), - ) - output_build_file_content += """ + + build_file = """ cc_library( - name = "{variant_name}_shared", + name = "{name}_{variant_name}_shared", srcs = glob( [ - "{variant_name}_shared/**/*.so", - "{variant_name}_shared/**/*.so.*", + "**/*.so", + "**/*.so.*", ], - exclude = ["{variant_name}_shared/**/*.debug"], + exclude = ["**/*.debug"], ), + visibility=["//visibility:public"] ) -""".format(variant_name=variant_name) +""".format(name=ctx.attr.name,variant_name=variant_name) + output_workspace_file_content = """ +http_archive( + name = "{name}_{variant_name}_shared", + urls = ["{url}"], + build_file_content = \"\"\"{build_file_content}\"\"\" +) +""".format( + name=ctx.attr.name, + variant_name = variant_name, + url = shared_url, + build_file_content = build_file +) + if ctx.attr.has_static: static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( base_url=ctx.attr.base_url, @@ -100,34 +203,40 @@ cc_library( version=ctx.attr.version, variant_name=variant_name, ) - ctx.download_and_extract( - static_url, - "{variant_name}_static".format(variant_name=variant_name), - ) - output_build_file_content += """ + + build_file = """ cc_library( - name = "{variant_name}_static", + name = "{name}_{variant_name}_static", srcs = glob([ - "{variant_name}_static/**/*.a", + "**/*.a", ]), + visibility=["//visibility:public"] +) +""".format(name=ctx.attr.name, variant_name=variant_name) + + output_workspace_file_content += """ +http_archive( + name="{name}_{variant_name}_static", + urls = ["{url}"], + build_file_content = \"\"\"{build_file_content} \"\"\" ) -""".format(variant_name=variant_name) + """.format(name=ctx.attr.name, variant_name=variant_name, url=static_url, build_file_content=build_file) deps = "[]" if ctx.attr.has_hdrs: - deps += "+ [\":hdrs\"]" + deps += "+ [\"@{name}_hdrs\"]".format(name=ctx.attr.name) if ctx.attr.has_shared: deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ - "\":{variant_name}_config\": [\":{variant_name}_shared\"]".format(variant_name=variant_name) + "\":{variant_name}_config\": [\"@{name}_{variant_name}_shared\"]".format(name=ctx.attr.name,variant_name=variant_name) for variant_name in ctx.attr.variants.keys() ])) if ctx.attr.has_static: deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ - "\":{variant_name}_config\": [\":{variant_name}_static\"]".format(variant_name=variant_name) + "\":{variant_name}_config\": [\"@{name}_{variant_name}_static\"]".format(name=ctx.attr.name, variant_name=variant_name) for variant_name in ctx.attr.variants.keys() ])) @@ -149,8 +258,10 @@ cc_library( deps=deps, linkopts=ctx.attr.linkopts ) - + # print(output_workspace_file_content) + # print(output_build_file_content) ctx.file("BUILD", output_build_file_content) + ctx.file("WORKSPACE", output_workspace_file_content) return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), {}) #updated_attrs) wpilib_artifact = repository_rule( From bf92b502c8235de02a61e9169112bba82664fc00 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 11:30:23 -0500 Subject: [PATCH 07/18] finished macro, need to modify the artifact rule --- bazel/wpilib_artifact.bzl | 112 +++----------------------------------- 1 file changed, 9 insertions(+), 103 deletions(-) diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 5a03045..1a85f2d 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -5,9 +5,6 @@ load( ) load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -def generate_all_configs(variants = {}): - pass - def generate_wpilib_archives(name, version, base_url, variants, has_hdrs=True, has_shared=True, has_static=True, deps=[], linkopts=[]): hdrs_url="{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( base_url=base_url, @@ -85,10 +82,15 @@ cc_library( urls = ["{url}".format(url=static_url)], build_file_content="""{}""".format(build_file) ) + + wpilib_artifact( + name=name, + deps=deps, + linkopts=linkopts, + variants=variants + ) _wpilib_artifact_attrs = { - "version": attr.string(mandatory=True), - "base_url": attr.string(mandatory=True), "variants": attr.string_list_dict(), "deps": attr.string_list(), "linkopts" : attr.string_list(), @@ -109,12 +111,9 @@ _wpilib_artifact_attrs = { def _wpilib_artifact_impl(ctx): updated_attrs = {} - output_workspace_file_content = "" output_build_file_content = "" - output_workspace_file_content += "load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\") \n" - # generate WORKSPACE # config settings for variant_name, variant_constraint_values in ctx.attr.variants.items(): output_build_file_content += """ @@ -130,98 +129,7 @@ config_setting( in variant_constraint_values ]) ) - - # generate headers rule - if ctx.attr.has_hdrs: - hdrs_url = "{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( - base_url=ctx.attr.base_url, - name=ctx.attr.name, - version=ctx.attr.version, - ) - hdr = """ -cc_library( - name = "{}_hdrs", - hdrs = glob([ - "**/*.h", - "**/*.inc", - "**/*.inl", - ]), - visibility=["//visibility:public"] -) -""".format(ctx.attr.name) - - - output_workspace_file_content += """ -http_archive( - name="{name}_hdrs", - urls = ["{url}"], - build_file_content = \"\"\"{build_file_content}\"\"\" -) \n - """.format(name=ctx.attr.name, url=hdrs_url, build_file_content=hdr) - - # generate http archives for shared and static libraries - for variant_name, variant_constraint_values in ctx.attr.variants.items(): - if ctx.attr.has_shared: - shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( - base_url=ctx.attr.base_url, - name=ctx.attr.name, - version=ctx.attr.version, - variant_name=variant_name, - ) - - build_file = """ -cc_library( - name = "{name}_{variant_name}_shared", - srcs = glob( - [ - "**/*.so", - "**/*.so.*", - ], - exclude = ["**/*.debug"], - ), - visibility=["//visibility:public"] -) -""".format(name=ctx.attr.name,variant_name=variant_name) - - output_workspace_file_content = """ -http_archive( - name = "{name}_{variant_name}_shared", - urls = ["{url}"], - build_file_content = \"\"\"{build_file_content}\"\"\" -) -""".format( - name=ctx.attr.name, - variant_name = variant_name, - url = shared_url, - build_file_content = build_file -) - - if ctx.attr.has_static: - static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( - base_url=ctx.attr.base_url, - name=ctx.attr.name, - version=ctx.attr.version, - variant_name=variant_name, - ) - - build_file = """ -cc_library( - name = "{name}_{variant_name}_static", - srcs = glob([ - "**/*.a", - ]), - visibility=["//visibility:public"] -) -""".format(name=ctx.attr.name, variant_name=variant_name) - - output_workspace_file_content += """ -http_archive( - name="{name}_{variant_name}_static", - urls = ["{url}"], - build_file_content = \"\"\"{build_file_content} \"\"\" -) - """.format(name=ctx.attr.name, variant_name=variant_name, url=static_url, build_file_content=build_file) - + deps = "[]" if ctx.attr.has_hdrs: @@ -258,10 +166,8 @@ cc_library( deps=deps, linkopts=ctx.attr.linkopts ) - # print(output_workspace_file_content) - # print(output_build_file_content) + ctx.file("BUILD", output_build_file_content) - ctx.file("WORKSPACE", output_workspace_file_content) return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), {}) #updated_attrs) wpilib_artifact = repository_rule( From 37d02c598d173519a8564a12bd6b92fc653f224e Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 11:49:23 -0500 Subject: [PATCH 08/18] it WORKS --- bazel/wpilib_artifact.bzl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 1a85f2d..7b7cff9 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -22,14 +22,14 @@ cc_library( "**/*.inl", ]), includes = ["."], + visibility = ["//visibility:public"] ) """.format(name=name) http_archive( name="{name}_hdrs".format(name=name), urls=["{url}".format(url=hdrs_url)], - build_file_content="""{}""".format(build_file) - ) + build_file_content="""{}""".format(build_file) ) for variant_name, variant_constraint_values in variants.items(): if(has_shared): shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( @@ -59,6 +59,8 @@ cc_library( build_file_content="""{}""".format(build_file) ) + print("creating repoitory of name: {name}_{variant_name}_shared".format(name=name, variant_name=variant_name)) + if(has_static): static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( base_url=base_url, @@ -87,7 +89,10 @@ cc_library( name=name, deps=deps, linkopts=linkopts, - variants=variants + variants=variants, + has_hdrs=has_hdrs, + has_shared=has_shared, + has_static=has_static ) _wpilib_artifact_attrs = { From d8c5767f437264506e388d3a6da91219a4b4e315 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 14:24:42 -0500 Subject: [PATCH 09/18] made a deps macro to declutter WORKSPACE, deleted print statement --- WORKSPACE | 249 +------------------------------------- bazel/wpilib_artifact.bzl | 2 - bazel/wpilib_deps.bzl | 247 +++++++++++++++++++++++++++++++++++++ 3 files changed, 253 insertions(+), 245 deletions(-) create mode 100644 bazel/wpilib_deps.bzl diff --git a/WORKSPACE b/WORKSPACE index b07cbef..8db9e34 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -89,250 +89,13 @@ cc_library( ) """ -load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact", "generate_wpilib_archives") +load("//:bazel/wpilib_deps.bzl", "wpilib_deps") -common_variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - "osxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:osx", - ], - "linuxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - "windowsx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], -} - -generate_wpilib_archives( - name = "wpilibc-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc", - variants = common_variants, - deps = [ - "@cameraserver-cpp//:cameraserver-cpp", - "@hal-cpp//:hal-cpp", - "@netcomm//:netcomm", - "@ntcore-cpp//:ntcore-cpp", - ], -) - -generate_wpilib_archives( - name = "hal-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal", - variants = common_variants, - deps = [ - "@visa//:visa", - "@wpiutil-cpp//:wpiutil-cpp", - ], -) - -generate_wpilib_archives( - name = "wpiutil-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil", - variants = common_variants, -) - -generate_wpilib_archives( - name = "ntcore-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore", - variants = common_variants, - deps = [ - "@wpiutil-cpp//:wpiutil-cpp", - ], -) - -generate_wpilib_archives( - name = "cameraserver-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver", - variants = common_variants, - deps = [ - "@cscore-cpp//:cscore-cpp", - ], -) - -generate_wpilib_archives( - name = "cscore-cpp", - version = WPILIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore", - variants = common_variants, - deps = [ - "@opencv-cpp//:opencv-cpp", - "@wpiutil-cpp//:wpiutil-cpp", - ], -) - -generate_wpilib_archives( - name = "api-cpp", - version = CTRE_LIB_VERSION, - base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - "linuxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - "windowsx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - }, - has_shared=False, - linkopts = ["-pthread"], - deps = [ - "@cci//:cci", - "@wpiapi-cpp//:wpiapi-cpp", - ], -) - -generate_wpilib_archives( - name = "core", - version = CTRE_LIB_VERSION, - base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - "linuxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - "windowsx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - }, - has_shared=False, -) - -generate_wpilib_archives( - name = "cci", - version = CTRE_LIB_VERSION, - base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - "linuxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - "windowsx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - }, - has_shared=False, - deps = [ - "@core//:core", - ], -) - -generate_wpilib_archives( - name = "wpiapi-cpp", - version = CTRE_LIB_VERSION, - base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - "linuxx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - "windowsx86-64": [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - }, - has_shared=False, -) - -generate_wpilib_archives( - name = "netcomm", - version = NI_LIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - }, - - has_static=False, - deps = [ - "@chipobject//:chipobject", - "@runtime//:runtime", - ], -) - -generate_wpilib_archives( - name = "chipobject", - version = NI_LIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - }, - has_static=False, - deps = [ - "@runtime//:runtime", - ], -) - -generate_wpilib_archives( - name = "runtime", - version = NI_LIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - }, - has_hdrs=False, - has_static=False, - deps = [ - "@hal-cpp//:hal-cpp", - ], -) - -generate_wpilib_archives( - name = "visa", - version = NI_LIB_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", - variants = { - "linuxathena": [ - "@platforms//cpu:armv7", - "@platforms//os:linux", - ], - }, - has_static=False, -) - -generate_wpilib_archives( - name = "opencv-cpp", - version = OPEN_CV_VERSION, - base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv", - variants = common_variants, +wpilib_deps( + wpilib_version=WPILIB_VERSION, + ctre_version=CTRE_LIB_VERSION, + ni_version=NI_LIB_VERSION, + opencv_version=OPEN_CV_VERSION ) http_archive( diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 7b7cff9..26ad402 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -59,8 +59,6 @@ cc_library( build_file_content="""{}""".format(build_file) ) - print("creating repoitory of name: {name}_{variant_name}_shared".format(name=name, variant_name=variant_name)) - if(has_static): static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( base_url=base_url, diff --git a/bazel/wpilib_deps.bzl b/bazel/wpilib_deps.bzl new file mode 100644 index 0000000..7804076 --- /dev/null +++ b/bazel/wpilib_deps.bzl @@ -0,0 +1,247 @@ +load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact", "generate_wpilib_archives") + +def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): + common_variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "osxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:osx", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + } + + + generate_wpilib_archives( + name = "wpilibc-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpilibc", + variants = common_variants, + deps = [ + "@cameraserver-cpp//:cameraserver-cpp", + "@hal-cpp//:hal-cpp", + "@netcomm//:netcomm", + "@ntcore-cpp//:ntcore-cpp", + ], + ) + + generate_wpilib_archives( + name = "hal-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/hal", + variants = common_variants, + deps = [ + "@visa//:visa", + "@wpiutil-cpp//:wpiutil-cpp", + ], + ) + + generate_wpilib_archives( + name = "wpiutil-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/wpiutil", + variants = common_variants, + ) + + generate_wpilib_archives( + name = "ntcore-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ntcore", + variants = common_variants, + deps = [ + "@wpiutil-cpp//:wpiutil-cpp", + ], + ) + + generate_wpilib_archives( + name = "cameraserver-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cameraserver", + variants = common_variants, + deps = [ + "@cscore-cpp//:cscore-cpp", + ], + ) + + generate_wpilib_archives( + name = "cscore-cpp", + version = wpilib_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/cscore", + variants = common_variants, + deps = [ + "@opencv-cpp//:opencv-cpp", + "@wpiutil-cpp//:wpiutil-cpp", + ], + ) + + generate_wpilib_archives( + name = "api-cpp", + version = ctre_version, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + linkopts = ["-pthread"], + deps = [ + "@cci//:cci", + "@wpiapi-cpp//:wpiapi-cpp", + ], + ) + + generate_wpilib_archives( + name = "core", + version = ctre_version, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + ) + + generate_wpilib_archives( + name = "cci", + version = ctre_version, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + deps = [ + "@core//:core", + ], + ) + + generate_wpilib_archives( + name = "wpiapi-cpp", + version = ctre_version, + base_url = "https://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + "linuxx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + "windowsx86-64": [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + ], + }, + has_shared=False, + ) + + generate_wpilib_archives( + name = "netcomm", + version = ni_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + + has_static=False, + deps = [ + "@chipobject//:chipobject", + "@runtime//:runtime", + ], + ) + + generate_wpilib_archives( + name = "chipobject", + version = ni_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_static=False, + deps = [ + "@runtime//:runtime", + ], + ) + + generate_wpilib_archives( + name = "runtime", + version = ni_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_hdrs=False, + has_static=False, + deps = [ + "@hal-cpp//:hal-cpp", + ], + ) + + generate_wpilib_archives( + name = "visa", + version = ni_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/ni-libraries", + variants = { + "linuxathena": [ + "@platforms//cpu:armv7", + "@platforms//os:linux", + ], + }, + has_static=False, + ) + + generate_wpilib_archives( + name = "opencv-cpp", + version = opencv_version, + base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv", + variants = common_variants, + ) \ No newline at end of file From 31f802841e134f9ce2cb1fa084d8e511c1542be7 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 14:32:35 -0500 Subject: [PATCH 10/18] buildifier format --- WORKSPACE | 8 +-- bazel/wpilib_artifact.bzl | 128 ++++++++++++++++++-------------------- bazel/wpilib_deps.bzl | 24 ++++--- src/BUILD | 2 +- 4 files changed, 77 insertions(+), 85 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 8db9e34..e4b8aeb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -92,10 +92,10 @@ cc_library( load("//:bazel/wpilib_deps.bzl", "wpilib_deps") wpilib_deps( - wpilib_version=WPILIB_VERSION, - ctre_version=CTRE_LIB_VERSION, - ni_version=NI_LIB_VERSION, - opencv_version=OPEN_CV_VERSION + ctre_version = CTRE_LIB_VERSION, + ni_version = NI_LIB_VERSION, + opencv_version = OPEN_CV_VERSION, + wpilib_version = WPILIB_VERSION, ) http_archive( diff --git a/bazel/wpilib_artifact.bzl b/bazel/wpilib_artifact.bzl index 26ad402..eba9a94 100644 --- a/bazel/wpilib_artifact.bzl +++ b/bazel/wpilib_artifact.bzl @@ -5,14 +5,14 @@ load( ) load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -def generate_wpilib_archives(name, version, base_url, variants, has_hdrs=True, has_shared=True, has_static=True, deps=[], linkopts=[]): - hdrs_url="{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( - base_url=base_url, - name=name, - version=version, +def generate_wpilib_archives(name, version, base_url, variants, has_hdrs = True, has_shared = True, has_static = True, deps = [], linkopts = []): + hdrs_url = "{base_url}/{name}/{version}/{name}-{version}-headers.zip".format( + base_url = base_url, + name = name, + version = version, ) - - if(has_hdrs): + + if (has_hdrs): build_file = """ cc_library( name = "{name}_hdrs", @@ -24,19 +24,20 @@ cc_library( includes = ["."], visibility = ["//visibility:public"] ) - """.format(name=name) + """.format(name = name) http_archive( - name="{name}_hdrs".format(name=name), - urls=["{url}".format(url=hdrs_url)], - build_file_content="""{}""".format(build_file) ) + name = "{name}_hdrs".format(name = name), + urls = ["{url}".format(url = hdrs_url)], + build_file_content = """{}""".format(build_file), + ) for variant_name, variant_constraint_values in variants.items(): - if(has_shared): + if (has_shared): shared_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}.zip".format( - base_url=base_url, - name=name, - version=version, - variant_name=variant_name, + base_url = base_url, + name = name, + version = version, + variant_name = variant_name, ) build_file = """ @@ -51,20 +52,20 @@ cc_library( ), visibility=["//visibility:public"] ) - """.format(name=name, variant_name=variant_name) + """.format(name = name, variant_name = variant_name) http_archive( - name="{name}_{variant_name}_shared".format(name=name, variant_name=variant_name), - urls = ["{url}".format(url=shared_url)], - build_file_content="""{}""".format(build_file) + name = "{name}_{variant_name}_shared".format(name = name, variant_name = variant_name), + urls = ["{url}".format(url = shared_url)], + build_file_content = """{}""".format(build_file), ) - if(has_static): + if (has_static): static_url = "{base_url}/{name}/{version}/{name}-{version}-{variant_name}static.zip".format( - base_url=base_url, - name=name, - version=version, - variant_name=variant_name, + base_url = base_url, + name = name, + version = version, + variant_name = variant_name, ) build_file = """ @@ -75,40 +76,37 @@ cc_library( ]), visibility=["//visibility:public"] ) - """.format(name=name, variant_name=variant_name) + """.format(name = name, variant_name = variant_name) http_archive( - name="{name}_{variant_name}_static".format(name=name, variant_name=variant_name), - urls = ["{url}".format(url=static_url)], - build_file_content="""{}""".format(build_file) + name = "{name}_{variant_name}_static".format(name = name, variant_name = variant_name), + urls = ["{url}".format(url = static_url)], + build_file_content = """{}""".format(build_file), ) - + wpilib_artifact( - name=name, - deps=deps, - linkopts=linkopts, - variants=variants, - has_hdrs=has_hdrs, - has_shared=has_shared, - has_static=has_static + name = name, + deps = deps, + linkopts = linkopts, + variants = variants, + has_hdrs = has_hdrs, + has_shared = has_shared, + has_static = has_static, ) _wpilib_artifact_attrs = { "variants": attr.string_list_dict(), "deps": attr.string_list(), - "linkopts" : attr.string_list(), - - "has_hdrs": attr.bool(default=True), + "linkopts": attr.string_list(), + "has_hdrs": attr.bool(default = True), "hdrs_sha256": attr.string(), + "has_shared": attr.bool(default = True), + # "shared_sha256": attr.string(), + "has_static": attr.bool(default = True), + # "static_sha256": attr.string(), - "has_shared": attr.bool(default=True), -# "shared_sha256": attr.string(), - - "has_static": attr.bool(default=True), -# "static_sha256": attr.string(), - -# "has_debug": attr.bool(default=True), -# "debug_sha256": attr.string(), + # "has_debug": attr.bool(default=True), + # "debug_sha256": attr.string(), } def _wpilib_artifact_impl(ctx): @@ -116,7 +114,6 @@ def _wpilib_artifact_impl(ctx): output_build_file_content = "" - # config settings for variant_name, variant_constraint_values in ctx.attr.variants.items(): output_build_file_content += """ @@ -125,35 +122,32 @@ config_setting( constraint_values = [{variant_constraint_values}], ) \n """.format( - variant_name=variant_name, + variant_name = variant_name, variant_constraint_values = ", ".join([ "\"{}\"".format(variant_constraint_value) - for variant_constraint_value - in variant_constraint_values - ]) + for variant_constraint_value in variant_constraint_values + ]), ) - + deps = "[]" if ctx.attr.has_hdrs: - deps += "+ [\"@{name}_hdrs\"]".format(name=ctx.attr.name) + deps += "+ [\"@{name}_hdrs\"]".format(name = ctx.attr.name) if ctx.attr.has_shared: deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ - "\":{variant_name}_config\": [\"@{name}_{variant_name}_shared\"]".format(name=ctx.attr.name,variant_name=variant_name) - for variant_name - in ctx.attr.variants.keys() + "\":{variant_name}_config\": [\"@{name}_{variant_name}_shared\"]".format(name = ctx.attr.name, variant_name = variant_name) + for variant_name in ctx.attr.variants.keys() ])) if ctx.attr.has_static: deps += " + select({{{}, \"//conditions:default\": []}})".format(", ".join([ - "\":{variant_name}_config\": [\"@{name}_{variant_name}_static\"]".format(name=ctx.attr.name, variant_name=variant_name) - for variant_name - in ctx.attr.variants.keys() + "\":{variant_name}_config\": [\"@{name}_{variant_name}_static\"]".format(name = ctx.attr.name, variant_name = variant_name) + for variant_name in ctx.attr.variants.keys() ])) deps += "+ [{}]".format(", ".join([ - "\"{dep}\"".format(dep=dep) + "\"{dep}\"".format(dep = dep) for dep in ctx.attr.deps ])) @@ -165,13 +159,13 @@ cc_library( visibility = ["//visibility:public"], ) """.format( - name=ctx.attr.name, - deps=deps, - linkopts=ctx.attr.linkopts -) + name = ctx.attr.name, + deps = deps, + linkopts = ctx.attr.linkopts, + ) ctx.file("BUILD", output_build_file_content) - return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), {}) #updated_attrs) + return update_attrs(ctx.attr, _wpilib_artifact_attrs.keys(), {}) #updated_attrs) wpilib_artifact = repository_rule( implementation = _wpilib_artifact_impl, diff --git a/bazel/wpilib_deps.bzl b/bazel/wpilib_deps.bzl index 7804076..22bad61 100644 --- a/bazel/wpilib_deps.bzl +++ b/bazel/wpilib_deps.bzl @@ -1,4 +1,4 @@ -load("//:bazel/wpilib_artifact.bzl", "wpilib_artifact", "generate_wpilib_archives") +load("//:bazel/wpilib_artifact.bzl", "generate_wpilib_archives", "wpilib_artifact") def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): common_variants = { @@ -20,7 +20,6 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): ], } - generate_wpilib_archives( name = "wpilibc-cpp", version = wpilib_version, @@ -101,7 +100,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:windows", ], }, - has_shared=False, + has_shared = False, linkopts = ["-pthread"], deps = [ "@cci//:cci", @@ -127,7 +126,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:windows", ], }, - has_shared=False, + has_shared = False, ) generate_wpilib_archives( @@ -148,7 +147,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:windows", ], }, - has_shared=False, + has_shared = False, deps = [ "@core//:core", ], @@ -172,7 +171,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:windows", ], }, - has_shared=False, + has_shared = False, ) generate_wpilib_archives( @@ -185,8 +184,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:linux", ], }, - - has_static=False, + has_static = False, deps = [ "@chipobject//:chipobject", "@runtime//:runtime", @@ -203,7 +201,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:linux", ], }, - has_static=False, + has_static = False, deps = [ "@runtime//:runtime", ], @@ -219,8 +217,8 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:linux", ], }, - has_hdrs=False, - has_static=False, + has_hdrs = False, + has_static = False, deps = [ "@hal-cpp//:hal-cpp", ], @@ -236,7 +234,7 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): "@platforms//os:linux", ], }, - has_static=False, + has_static = False, ) generate_wpilib_archives( @@ -244,4 +242,4 @@ def wpilib_deps(wpilib_version, ctre_version, ni_version, opencv_version): version = opencv_version, base_url = "https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/frc2020/opencv", variants = common_variants, - ) \ No newline at end of file + ) diff --git a/src/BUILD b/src/BUILD index 5c720db..3495bc7 100644 --- a/src/BUILD +++ b/src/BUILD @@ -7,7 +7,7 @@ cc_binary( ], copts = ["-std=c++17"], deps = [ - "@api-cpp", # ctre + "@api-cpp", # ctre "@eigen", "@wpilibc-cpp", ], From 37e4a5ddc4269649e5fed53b2c0fff65d25059c9 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Sun, 23 Feb 2020 18:16:49 -0500 Subject: [PATCH 11/18] fixed files --- tools/BUILD | 7 ------- tools/deploy.bzl | 46 ++++++++++------------------------------------ 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/tools/BUILD b/tools/BUILD index fa6aa32..e69de29 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -1,7 +0,0 @@ -from __future__ import print_function - -import sys -import subprocess -import re -import os - diff --git a/tools/deploy.bzl b/tools/deploy.bzl index ea0e05e..2844377 100644 --- a/tools/deploy.bzl +++ b/tools/deploy.bzl @@ -1,39 +1,13 @@ -def _deploy_impl(ctx): - all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist] - ctx.file_action( - output = ctx.outputs.executable, - executable = True, - content = '\n'.join([ - '#!/bin/bash', - 'set -e', - 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, - ] + ['%s %s --dirs %s -- %s "$@"' % ( - ctx.executable._downloader.short_path, - ' '.join([src.short_path for src in d.downloader_srcs]), - d.downloader_dir, - ctx.attr.default_target) for d in ctx.attr.dirs] + [ - 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, - ' '.join([src.short_path for src in all_files]), - ctx.attr.default_target), - ]), - ) - ctx.file_action( - output = ctx.outputs._startlist, - content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n', - ) - to_download = [ctx.outputs._startlist] - to_download += all_files - for d in ctx.attr.dirs: - to_download += d.downloader_srcs +_robot_deploy_attr = { - return struct( - runfiles = ctx.runfiles( - files = to_download + ctx.files._downloader, - transitive_files = ctx.attr._downloader.default_runfiles.files, - collect_data = True, - collect_default = True, - ), - files = depset([ctx.outputs.executable]), - ) +} + +def _robot_deploy_impl(ctx): + pass + +robot_deploy = repository_rule( + implementation=_robot_deploy_impl, + attrs=_robot_deploy_attr +) \ No newline at end of file From e77613260184f9c423be3902db43422a319371dc Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Mon, 24 Feb 2020 14:58:29 -0500 Subject: [PATCH 12/18] work on deploy script --- README.md | 4 +++ tools/deploy.bzl | 13 ------- tools/deploy/BUILD | 15 ++++++++ tools/deploy/deploy.bzl | 65 +++++++++++++++++++++++++++++++++++ tools/{ => deploy}/deploy.py | 0 tools/deploy/robotCommand | 1 + tools/deploy/setup_roborio.sh | 23 +++++++++++++ 7 files changed, 108 insertions(+), 13 deletions(-) delete mode 100644 tools/deploy.bzl create mode 100644 tools/deploy/BUILD create mode 100644 tools/deploy/deploy.bzl rename tools/{ => deploy}/deploy.py (100%) create mode 100755 tools/deploy/robotCommand create mode 100755 tools/deploy/setup_roborio.sh diff --git a/README.md b/README.md index db16f38..34edc34 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ IPC framework intended for use in First Robotics Competition using [ZeroMQ](http 5. ??? 6. Profit +## How to Deploy: +If your RoboRIO is not configured for our architecture, run `bazel run //tools/deploy:setup_roborio -- roborio-5419-frc.local` or whatever the host name/ip of the robot is. This will configure the rio to run our start script and not the default start script. In the future it will possibly configure other settings such as directories and symlinks. + +Build the directory with a `robot_deploy` rule inside in order to deploy (ex: `bazel build //src:robot --config=roborio`) ## Planned Features: - Full cross-compiler support (only roborio for now) diff --git a/tools/deploy.bzl b/tools/deploy.bzl deleted file mode 100644 index 2844377..0000000 --- a/tools/deploy.bzl +++ /dev/null @@ -1,13 +0,0 @@ - - -_robot_deploy_attr = { - -} - -def _robot_deploy_impl(ctx): - pass - -robot_deploy = repository_rule( - implementation=_robot_deploy_impl, - attrs=_robot_deploy_attr -) \ No newline at end of file diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD new file mode 100644 index 0000000..cdd612a --- /dev/null +++ b/tools/deploy/BUILD @@ -0,0 +1,15 @@ +filegroup( + name="rio_robot_command", + srcs= ["robotCommand"] +) + +sh_binary( + name = 'setup_roborio', + srcs = [ 'setup_roborio.sh' ], + visibility = [ '//visibility:public' ], + data = [ + ':rio_robot_command', + # '@arm_frc_linux_gnueabi_repo//:compiler_pieces', + ], +) + diff --git a/tools/deploy/deploy.bzl b/tools/deploy/deploy.bzl new file mode 100644 index 0000000..8a4ce69 --- /dev/null +++ b/tools/deploy/deploy.bzl @@ -0,0 +1,65 @@ + +_deploy_dir_attr = { + "srcs" : attr.label_list( + mandatory = True, + allow_files = True + ), + "dir" : attr.string( + mandatory= True + ) +} + +def _deploy_dir_impl(ctx): + return struct( + downloader_dir = ctx.attr.dir, + downloader_srcs = ctx.files.srcs + ) + +deploy_dir = rule( + attrs = _deploy_dir_attr, + implementation = _deploy_dir_impl +) + +_deploy_attr = { + "_downloader": attr.label( + executable = True, + cfg = "host", + default = Label("//tools:deploy") + ), + "start_srcs": attr.label_list( + mandatory = True, + allow_files = True, + ), + "srcs": attr.label_list( + mandatory = True, + allow_files = True + ), + "dirs" : attr.label_list( + mandatory = False, + providers = [ + "downloader_dir", + "downloader_srcs" + ] + ), + "deploy_location" : attr.string( + default = "roborio-5419-frc.local" + ) +} + +def _deploy_impl(ctx): + pass + +deploy = repository_rule( + implementation=_robot_deploy_impl, + executable=True, + attrs=_robot_deploy_attr +) + +def robot_deploy(start_binaries, binaries=[], dirs=None, default_target=[]): + deploy( + name="deploy", + start_srcs=start_binaries, + srcs=binaries, + dirs=dirs, + default_target= default_target, + ) \ No newline at end of file diff --git a/tools/deploy.py b/tools/deploy/deploy.py similarity index 100% rename from tools/deploy.py rename to tools/deploy/deploy.py diff --git a/tools/deploy/robotCommand b/tools/deploy/robotCommand new file mode 100755 index 0000000..7b726a7 --- /dev/null +++ b/tools/deploy/robotCommand @@ -0,0 +1 @@ +/home/admin/robot_code/starter.sh diff --git a/tools/deploy/setup_roborio.sh b/tools/deploy/setup_roborio.sh new file mode 100755 index 0000000..917d278 --- /dev/null +++ b/tools/deploy/setup_roborio.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -Eeuo pipefail + +if [ $# != 1 ]; +then + echo "# setup_robot.sh is used to configure a newly flashed roboRIO" + echo "" + echo "Usage: setup_roborio.sh 10.54.19.2" + echo "" + echo "# or if that does not work, try" + echo "" + echo "Usage: setup_roborio.sh roboRIO-5419-frc.local" + exit 1 +fi + +readonly ROBOT_HOSTNAME="$1" + +# This fails if the code isn't running. +ssh "admin@${ROBOT_HOSTNAME}" 'PATH="${PATH}":/usr/local/natinst/bin/ /usr/local/frc/bin/frcKillRobot.sh -r -t' || true + +echo "Deploying robotCommand startup script" +scp aos/config/robotCommand "admin@${ROBOT_HOSTNAME}:/home/lvuser/" \ No newline at end of file From d7fe535b887a2761c28ac179f07b047bf0ffce8d Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Mon, 24 Feb 2020 15:04:25 -0500 Subject: [PATCH 13/18] builifier format --- tools/deploy/BUILD | 19 ++++++++------- tools/deploy/deploy.bzl | 51 ++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD index cdd612a..d587dbb 100644 --- a/tools/deploy/BUILD +++ b/tools/deploy/BUILD @@ -1,15 +1,14 @@ filegroup( - name="rio_robot_command", - srcs= ["robotCommand"] + name = "rio_robot_command", + srcs = ["robotCommand"], ) sh_binary( - name = 'setup_roborio', - srcs = [ 'setup_roborio.sh' ], - visibility = [ '//visibility:public' ], - data = [ - ':rio_robot_command', - # '@arm_frc_linux_gnueabi_repo//:compiler_pieces', - ], + name = "setup_roborio", + srcs = ["setup_roborio.sh"], + data = [ + ":rio_robot_command", + # '@arm_frc_linux_gnueabi_repo//:compiler_pieces', + ], + visibility = ["//visibility:public"], ) - diff --git a/tools/deploy/deploy.bzl b/tools/deploy/deploy.bzl index 8a4ce69..dd4267a 100644 --- a/tools/deploy/deploy.bzl +++ b/tools/deploy/deploy.bzl @@ -1,30 +1,29 @@ - _deploy_dir_attr = { - "srcs" : attr.label_list( + "srcs": attr.label_list( + mandatory = True, + allow_files = True, + ), + "dir": attr.string( mandatory = True, - allow_files = True ), - "dir" : attr.string( - mandatory= True - ) } def _deploy_dir_impl(ctx): return struct( downloader_dir = ctx.attr.dir, - downloader_srcs = ctx.files.srcs + downloader_srcs = ctx.files.srcs, ) deploy_dir = rule( attrs = _deploy_dir_attr, - implementation = _deploy_dir_impl + implementation = _deploy_dir_impl, ) _deploy_attr = { "_downloader": attr.label( executable = True, cfg = "host", - default = Label("//tools:deploy") + default = Label("//tools:deploy"), ), "start_srcs": attr.label_list( mandatory = True, @@ -32,34 +31,34 @@ _deploy_attr = { ), "srcs": attr.label_list( mandatory = True, - allow_files = True + allow_files = True, ), - "dirs" : attr.label_list( + "dirs": attr.label_list( mandatory = False, providers = [ "downloader_dir", - "downloader_srcs" - ] + "downloader_srcs", + ], + ), + "deploy_location": attr.string( + default = "roborio-5419-frc.local", ), - "deploy_location" : attr.string( - default = "roborio-5419-frc.local" - ) } def _deploy_impl(ctx): pass deploy = repository_rule( - implementation=_robot_deploy_impl, - executable=True, - attrs=_robot_deploy_attr + implementation = _robot_deploy_impl, + executable = True, + attrs = _robot_deploy_attr, ) -def robot_deploy(start_binaries, binaries=[], dirs=None, default_target=[]): +def robot_deploy(start_binaries, binaries = [], dirs = None, default_target = []): deploy( - name="deploy", - start_srcs=start_binaries, - srcs=binaries, - dirs=dirs, - default_target= default_target, - ) \ No newline at end of file + name = "deploy", + start_srcs = start_binaries, + srcs = binaries, + dirs = dirs, + default_target = default_target, + ) From 7a2a661a3725d198bce9a16ac93814d55bd22f92 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Mon, 24 Feb 2020 19:01:34 -0500 Subject: [PATCH 14/18] more progress --- src/BUILD | 10 +++++- tools/deploy/BUILD | 8 +++++ tools/deploy/deploy.bzl | 69 ++++++++++++++++++++++++++++++---------- tools/deploy/deploy.py | 0 tools/deploy/deployer.py | 1 + 5 files changed, 71 insertions(+), 17 deletions(-) delete mode 100644 tools/deploy/deploy.py create mode 100644 tools/deploy/deployer.py diff --git a/src/BUILD b/src/BUILD index 3495bc7..b8af4f1 100644 --- a/src/BUILD +++ b/src/BUILD @@ -1,4 +1,5 @@ -# https://docs.bazel.build/versions/master/be/c-cpp.html#cc_binary +load("//tools/deploy:deploy.bzl", "robot_deploy") + cc_binary( name = "main", srcs = [ @@ -12,3 +13,10 @@ cc_binary( "@wpilibc-cpp", ], ) + +robot_deploy( + name = "main_deploy", + start_srcs=[":main"], + srcs = [], + deploy_location="roborio-5419-frc.local" +) diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD index d587dbb..f857265 100644 --- a/tools/deploy/BUILD +++ b/tools/deploy/BUILD @@ -3,6 +3,14 @@ filegroup( srcs = ["robotCommand"], ) +py_binary( + name="deployer", + srcs=[ + "deployer.py" + ], + visibility = ["//visibility:public"], +) + sh_binary( name = "setup_roborio", srcs = ["setup_roborio.sh"], diff --git a/tools/deploy/deploy.bzl b/tools/deploy/deploy.bzl index dd4267a..3d48cee 100644 --- a/tools/deploy/deploy.bzl +++ b/tools/deploy/deploy.bzl @@ -1,3 +1,9 @@ +load( + "@bazel_tools//tools/build_defs/repo:utils.bzl", + "update_attrs", + "workspace_and_buildfile", +) + _deploy_dir_attr = { "srcs": attr.label_list( mandatory = True, @@ -14,16 +20,16 @@ def _deploy_dir_impl(ctx): downloader_srcs = ctx.files.srcs, ) -deploy_dir = rule( +deploy_dir = repository_rule( attrs = _deploy_dir_attr, implementation = _deploy_dir_impl, ) -_deploy_attr = { +_robot_deploy_attr = { "_downloader": attr.label( executable = True, cfg = "host", - default = Label("//tools:deploy"), + default = Label("//tools/deploy:deployer"), ), "start_srcs": attr.label_list( mandatory = True, @@ -45,20 +51,51 @@ _deploy_attr = { ), } -def _deploy_impl(ctx): - pass +def _robot_deploy_impl(ctx): + all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist] + ctx.actions.write( + output=ctx.outputs.executable, + is_executable=True, + # im not sure what the code actually does here, well figure it out + content = '\n'.join([ + '#!/bin/bash', + 'set -e', + 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, + ] + ['%s %s --dirs %s -- %s "$@"' % ( + ctx.executable._downloader.short_path, + ' '.join([src.short_path for src in d.downloader_srcs]), + d.downloader_dir, + ctx.attr.deploy_location) for d in ctx.attr.dirs] + [ + 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, + ' '.join([src.short_path for src in all_files]), + ctx.attr.deploy_location), + ]), + ) + + ctx.actions.write( + output = ctx.outputs._startlist, + content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n', + ) + to_download = [ctx.outputs._startlist] + to_download += all_files + for d in ctx.attr.dirs: + to_download += d.downloader_srcs + + return struct( + runfiles = ctx.runfiles( + files = to_download + ctx.files._downloader, + transitive_files = ctx.attr._downloader.default_runfiles.files, + collect_data = True, + collect_default = True, + ), + files = depset([ctx.outputs.executable]), + ) -deploy = repository_rule( +robot_deploy = rule( implementation = _robot_deploy_impl, - executable = True, attrs = _robot_deploy_attr, + outputs = { + "_startlist": "%{name}.start_list.dir/start_list.txt", + }, + executable = True ) - -def robot_deploy(start_binaries, binaries = [], dirs = None, default_target = []): - deploy( - name = "deploy", - start_srcs = start_binaries, - srcs = binaries, - dirs = dirs, - default_target = default_target, - ) diff --git a/tools/deploy/deploy.py b/tools/deploy/deploy.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/deploy/deployer.py b/tools/deploy/deployer.py new file mode 100644 index 0000000..625241b --- /dev/null +++ b/tools/deploy/deployer.py @@ -0,0 +1 @@ +print("yeet") \ No newline at end of file From 3baaa4ca9d9721415fe0be39b682cc9d71d6eade Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Tue, 25 Feb 2020 13:02:09 -0500 Subject: [PATCH 15/18] updated readme, need to fix deploy script deps --- README.md | 2 +- src/BUILD | 5 ++- tools/deploy/BUILD | 2 + tools/deploy/deployer.py | 95 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34edc34..0228699 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ IPC framework intended for use in First Robotics Competition using [ZeroMQ](http ## How to Deploy: If your RoboRIO is not configured for our architecture, run `bazel run //tools/deploy:setup_roborio -- roborio-5419-frc.local` or whatever the host name/ip of the robot is. This will configure the rio to run our start script and not the default start script. In the future it will possibly configure other settings such as directories and symlinks. -Build the directory with a `robot_deploy` rule inside in order to deploy (ex: `bazel build //src:robot --config=roborio`) +Run the deploy rule as follows: `bazel run //src:main_deploy --config=roborio`. The script will ssh into the roborio, install needed packages (rysnc, ssl, python, etc) and then deploy the needed binaries. ## Planned Features: - Full cross-compiler support (only roborio for now) diff --git a/src/BUILD b/src/BUILD index b8af4f1..59eceb5 100644 --- a/src/BUILD +++ b/src/BUILD @@ -14,9 +14,12 @@ cc_binary( ], ) + +# waiting for https://github.com/bazelbuild/bazel/issues/3780 to be resolved robot_deploy( name = "main_deploy", start_srcs=[":main"], srcs = [], - deploy_location="roborio-5419-frc.local" + deploy_location="roborio-5419-frc.local", + # restricted_to=["//platforms:roborio"] ) diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD index f857265..97e374e 100644 --- a/tools/deploy/BUILD +++ b/tools/deploy/BUILD @@ -8,6 +8,8 @@ py_binary( srcs=[ "deployer.py" ], + deps = [ + ], visibility = ["//visibility:public"], ) diff --git a/tools/deploy/deployer.py b/tools/deploy/deployer.py index 625241b..e49ee5d 100644 --- a/tools/deploy/deployer.py +++ b/tools/deploy/deployer.py @@ -1 +1,94 @@ -print("yeet") \ No newline at end of file +# This file is run by shell scripts generated by the aos_downloader Skylark +# macro. Everything before the first -- is a hard-coded list of files to +# download. + +from __future__ import print_function + +import sys +import subprocess +import re +import os + + +def install(ssh_target, pkg): + """Installs a package from NI on the ssh target.""" + print("Installing", pkg) + PKG_URL = "http://download.ni.com/ni-linux-rt/feeds/2015/arm/ipk/cortexa9-vfpv3/" + pkg + subprocess.check_call(["wget", PKG_URL, "-O", pkg]) + try: + subprocess.check_call([ + "external/ssh/usr/bin/scp", "-S", "external/ssh/usr/bin/ssh", pkg, + ssh_target + ":/tmp/" + pkg + ]) + subprocess.check_call([ + "external/ssh/usr/bin/ssh", ssh_target, "opkg", "install", + "/tmp/" + pkg + ]) + subprocess.check_call( + ["external/ssh/usr/bin/ssh", ssh_target, "rm", "/tmp/" + pkg]) + finally: + subprocess.check_call(["rm", pkg]) + + +def main(argv): + args = argv[argv.index("--") + 1:] + + relative_dir = "" + recursive = False + + if "--dirs" in argv: + dirs_index = argv.index("--dirs") + srcs = argv[1:dirs_index] + relative_dir = argv[dirs_index + 1] + recursive = True + else: + srcs = argv[1:argv.index("--")] + + ROBORIO_TARGET_DIR = "/home/admin/robot_code" + ROBORIO_USER = "admin" + + target_dir = ROBORIO_TARGET_DIR + user = ROBORIO_USER + destination = args[-1] + + result = re.match("(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?", destination) + if not result: + print( + "Not sure how to parse destination \"%s\"!" % destination, + file=sys.stderr) + return 1 + if result.group(1): + user = result.group(1) + hostname = result.group(2) + if result.group(3): + target_dir = result.group(3) + + ssh_target = "%s@%s" % (user, hostname) + + rsync_cmd = ([ + "external/rsync/usr/bin/rsync", "-e", "external/ssh/usr/bin/ssh", "-c", + "-v", "-z", "--copy-links" + ] + srcs + ["%s:%s/%s" % (ssh_target, target_dir, relative_dir)]) + try: + subprocess.check_call(rsync_cmd) + except subprocess.CalledProcessError as e: + if e.returncode == 127: + print("Unconfigured roboRIO, installing rsync.") + install(ssh_target, "libattr1_2.4.47-r0.36_cortexa9-vfpv3.ipk") + install(ssh_target, "libacl1_2.2.52-r0.36_cortexa9-vfpv3.ipk") + install(ssh_target, "rsync_3.1.0-r0.7_cortexa9-vfpv3.ipk") + subprocess.check_call(rsync_cmd) + else: + raise e + + if not recursive: + subprocess.check_call( + ("external/ssh/usr/bin/ssh", ssh_target, "&&".join([ + "chmod u+s %s/starter_exe" % target_dir, + "echo \'Done moving new executables into place\'", + "bash -c \'sync && sync && sync\'", + ]))) + + +if __name__ == "__main__": + main(sys.argv) From 57e2f249d4933ad0dc082ebe7fc6bf314271872d Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Wed, 26 Feb 2020 13:11:19 -0500 Subject: [PATCH 16/18] updated readme, fixed issues with python script --- README.md | 12 +++++++----- tools/deploy/deployer.py | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0228699..4c3af6e 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,21 @@ IPC framework intended for use in First Robotics Competition using [ZeroMQ](http ## How to Build: 1. Clone the repository 2. Install [Bazel](https://bazel.build/) -3. If using Mac, follow [these](https://github.com/bazelbuild/sandboxfs/blob/master/INSTALL.md) instructions to install Sandboxfs +3. Follow [these](https://github.com/bazelbuild/sandboxfs/blob/master/INSTALL.md) instructions to install Sandboxfs 4. run `bazel build //... --config=roborio` to build the project 5. ??? 6. Profit ## How to Deploy: -If your RoboRIO is not configured for our architecture, run `bazel run //tools/deploy:setup_roborio -- roborio-5419-frc.local` or whatever the host name/ip of the robot is. This will configure the rio to run our start script and not the default start script. In the future it will possibly configure other settings such as directories and symlinks. +Make sure you have python3, scp, ssh, and sync available from your command line, otherwise the deploy script will not work. -Run the deploy rule as follows: `bazel run //src:main_deploy --config=roborio`. The script will ssh into the roborio, install needed packages (rysnc, ssl, python, etc) and then deploy the needed binaries. +If your RoboRIO is not configured for our architecture, run `bazel run //tools/deploy:setup_roborio -- roborio-5419-frc.local` with whatever the host name/ip of your robot is. This will configure the rio to run our start script and not the default start script. In the future it will possibly configure other settings such as directories and symlinks. + +Run the deploy rule as follows: `bazel run //src:main_deploy --config=roborio -c opt`. The script will ssh into the roborio, install needed packages (rysnc, ssl, python, etc) and then deploy the robot binaries. ## Planned Features: -- Full cross-compiler support (only roborio for now) -- Automated deploy script using Bazel + Python +- Full cross-compiler support (This is mostly working as of now) +- Automated deploy script using Bazel + Python (Written, but needs to be tested) - Full IPC communication with both C++ and Python APIs (More languages later?) - Fully unit-testable structure - Robust logging system diff --git a/tools/deploy/deployer.py b/tools/deploy/deployer.py index e49ee5d..90d4cb0 100644 --- a/tools/deploy/deployer.py +++ b/tools/deploy/deployer.py @@ -17,15 +17,15 @@ def install(ssh_target, pkg): subprocess.check_call(["wget", PKG_URL, "-O", pkg]) try: subprocess.check_call([ - "external/ssh/usr/bin/scp", "-S", "external/ssh/usr/bin/ssh", pkg, + "scp", "-S", "ssh", pkg, ssh_target + ":/tmp/" + pkg ]) subprocess.check_call([ - "external/ssh/usr/bin/ssh", ssh_target, "opkg", "install", + "ssh", ssh_target, "opkg", "install", "/tmp/" + pkg ]) subprocess.check_call( - ["external/ssh/usr/bin/ssh", ssh_target, "rm", "/tmp/" + pkg]) + ["ssh", ssh_target, "rm", "/tmp/" + pkg]) finally: subprocess.check_call(["rm", pkg]) @@ -66,7 +66,7 @@ def main(argv): ssh_target = "%s@%s" % (user, hostname) rsync_cmd = ([ - "external/rsync/usr/bin/rsync", "-e", "external/ssh/usr/bin/ssh", "-c", + "rsync", "-e", "ssh", "-c", "-v", "-z", "--copy-links" ] + srcs + ["%s:%s/%s" % (ssh_target, target_dir, relative_dir)]) try: @@ -83,7 +83,7 @@ def main(argv): if not recursive: subprocess.check_call( - ("external/ssh/usr/bin/ssh", ssh_target, "&&".join([ + ("ssh", ssh_target, "&&".join([ "chmod u+s %s/starter_exe" % target_dir, "echo \'Done moving new executables into place\'", "bash -c \'sync && sync && sync\'", From 2d84279a7c11df6fcca1e8004650a6ce0bf4dd60 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Wed, 26 Feb 2020 13:17:09 -0500 Subject: [PATCH 17/18] format and bug fixes --- src/BUILD | 5 ++--- tools/deploy/BUILD | 8 ++++---- tools/deploy/deploy.bzl | 33 ++++++++++++++++++--------------- tools/deploy/setup_roborio.sh | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/BUILD b/src/BUILD index 59eceb5..91bd01c 100644 --- a/src/BUILD +++ b/src/BUILD @@ -14,12 +14,11 @@ cc_binary( ], ) - # waiting for https://github.com/bazelbuild/bazel/issues/3780 to be resolved robot_deploy( name = "main_deploy", - start_srcs=[":main"], srcs = [], - deploy_location="roborio-5419-frc.local", + deploy_location = "roborio-5419-frc.local", + start_srcs = [":main"], # restricted_to=["//platforms:roborio"] ) diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD index 97e374e..931703c 100644 --- a/tools/deploy/BUILD +++ b/tools/deploy/BUILD @@ -4,13 +4,13 @@ filegroup( ) py_binary( - name="deployer", - srcs=[ - "deployer.py" + name = "deployer", + srcs = [ + "deployer.py", ], + visibility = ["//visibility:public"], deps = [ ], - visibility = ["//visibility:public"], ) sh_binary( diff --git a/tools/deploy/deploy.bzl b/tools/deploy/deploy.bzl index 3d48cee..a902ab1 100644 --- a/tools/deploy/deploy.bzl +++ b/tools/deploy/deploy.bzl @@ -54,27 +54,30 @@ _robot_deploy_attr = { def _robot_deploy_impl(ctx): all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist] ctx.actions.write( - output=ctx.outputs.executable, - is_executable=True, + output = ctx.outputs.executable, + is_executable = True, # im not sure what the code actually does here, well figure it out - content = '\n'.join([ - '#!/bin/bash', - 'set -e', - 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, + content = "\n".join([ + "#!/bin/bash", + "set -e", + 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, ] + ['%s %s --dirs %s -- %s "$@"' % ( - ctx.executable._downloader.short_path, - ' '.join([src.short_path for src in d.downloader_srcs]), - d.downloader_dir, - ctx.attr.deploy_location) for d in ctx.attr.dirs] + [ - 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, - ' '.join([src.short_path for src in all_files]), - ctx.attr.deploy_location), + ctx.executable._downloader.short_path, + " ".join([src.short_path for src in d.downloader_srcs]), + d.downloader_dir, + ctx.attr.deploy_location, + ) for d in ctx.attr.dirs] + [ + 'exec %s %s -- %s "$@"' % ( + ctx.executable._downloader.short_path, + " ".join([src.short_path for src in all_files]), + ctx.attr.deploy_location, + ), ]), ) ctx.actions.write( output = ctx.outputs._startlist, - content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n', + content = "\n".join([f.basename for f in ctx.files.start_srcs]) + "\n", ) to_download = [ctx.outputs._startlist] to_download += all_files @@ -97,5 +100,5 @@ robot_deploy = rule( outputs = { "_startlist": "%{name}.start_list.dir/start_list.txt", }, - executable = True + executable = True, ) diff --git a/tools/deploy/setup_roborio.sh b/tools/deploy/setup_roborio.sh index 917d278..2a03f78 100755 --- a/tools/deploy/setup_roborio.sh +++ b/tools/deploy/setup_roborio.sh @@ -20,4 +20,4 @@ readonly ROBOT_HOSTNAME="$1" ssh "admin@${ROBOT_HOSTNAME}" 'PATH="${PATH}":/usr/local/natinst/bin/ /usr/local/frc/bin/frcKillRobot.sh -r -t' || true echo "Deploying robotCommand startup script" -scp aos/config/robotCommand "admin@${ROBOT_HOSTNAME}:/home/lvuser/" \ No newline at end of file +scp tools/deploy/robotCommand "admin@${ROBOT_HOSTNAME}:/home/lvuser/" \ No newline at end of file From 87c6ff761c6692eb192a64a60be3dadd2b28b2c3 Mon Sep 17 00:00:00 2001 From: Benjamin Scholar Date: Wed, 26 Feb 2020 13:26:34 -0500 Subject: [PATCH 18/18] got rid of deps for py_binary --- tools/deploy/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/deploy/BUILD b/tools/deploy/BUILD index 931703c..b7cd641 100644 --- a/tools/deploy/BUILD +++ b/tools/deploy/BUILD @@ -9,8 +9,6 @@ py_binary( "deployer.py", ], visibility = ["//visibility:public"], - deps = [ - ], ) sh_binary(