Skip to content

Commit

Permalink
Update formulae for static builds, add canon formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Otterverse committed Apr 13, 2023
1 parent 2e95834 commit f99ddab
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/bump-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- name: Bump orb-slam3-module
run: ./bump-version.sh orb-slam3-module

- name: Bump canon
run: ./bump-version.sh canon

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
18 changes: 18 additions & 0 deletions Formula/canon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Canon < Formula
desc "CLI utility for managing docker-based, canonical development environments"
homepage "https://github.com/viamrobotics/canon"
url "https://github.com/viamrobotics/canon/archive/refs/tags/v0.1.6.tar.gz"
sha256 "dda2cdf2fd6bae273d9ae9928bafcd3aec793f6ef7c74d3fadad012296f17fe0"
head "https://github.com/viamrobotics/canon.git", branch: "main"

depends_on "go" => :build

def install
system "go", "build", "-o", "canon", "./"
bin.install "canon"
end

test do
system "#{bin}/canon", "config"
end
end
50 changes: 50 additions & 0 deletions Formula/nlopt-static.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class NloptStatic < Formula
desc "Free/open-source library for nonlinear optimization"
homepage "https://nlopt.readthedocs.io/"
url "https://github.com/stevengj/nlopt/archive/v2.7.1.tar.gz"
sha256 "db88232fa5cef0ff6e39943fc63ab6074208831dc0031cf1545f6ecd31ae2a1a"
license "LGPL-2.1"
head "https://github.com/stevengj/nlopt.git", branch: "master"

depends_on "cmake" => [:build, :test]
conflicts_with "nlopt", because: "nlopt-static provides dynamic and static libraries"

def install
args = *std_cmake_args + %w[
-DNLOPT_GUILE=OFF
-DNLOPT_MATLAB=OFF
-DNLOPT_OCTAVE=OFF
-DNLOPT_PYTHON=OFF
-DNLOPT_SWIG=OFF
-DNLOPT_TESTS=OFF
]

mkdir "build" do
system "cmake", *args, ".."
system "make"
system "make", "install"
end

args = *args + %w[-DBUILD_SHARED_LIBS=OFF]
mkdir "build_static" do
system "cmake", *args, ".."
system "make"
system "make", "install"
end

pkgshare.install "test/box.c"
end

test do
(testpath/"CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION 3.0)
project(box C)
find_package(NLopt REQUIRED)
add_executable(box "#{pkgshare}/box.c")
target_link_libraries(box NLopt::nlopt)
EOS
system "cmake", "."
system "make"
assert_match "found", shell_output("./box")
end
end
111 changes: 102 additions & 9 deletions Formula/tensorflowlite.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,121 @@
class Tensorflowlite < Formula
desc "Tensorflow Lite"
desc "Open Source Machine Learning Framework for Everyone"
homepage "https://tensorflow.org"
url "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.9.1.tar.gz"
sha256 "6eaf86ead73e23988fe192da1db68f4d3828bcdd0f3a9dc195935e339c95dbdc"
license "APACHE-2.0"
url "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.12.0.tar.gz"
sha256 "c030cb1905bff1d2446615992aad8d8d85cbe90c4fb625cee458c63bf466bc8e"
license "Apache-2.0"
head "https://github.com/tensorflow/tensorflow.git", branch: "master"

depends_on "cmake" => :build

patch :p1, <<~EOP
--- a/tensorflow/lite/core/interpreter.cc
+++ b/tensorflow/lite/core/interpreter.cc
@@ -445,8 +445,10 @@
}
TfLiteStatus Interpreter::ReportTelemetrySettings(const char* setting_name) {
+#ifdef TF_LITE_TENSORFLOW_PROFILER
telemetry::TelemetryReportSettings(context_, setting_name,
telemetry_data_.get());
+#endif //TFLITE_TENSORFLOW_PROFILER
return kTfLiteOk;
}
--- a/tensorflow/lite/core/subgraph.cc
+++ b/tensorflow/lite/core/subgraph.cc
@@ -1382,7 +1382,9 @@
TfLiteStatus Subgraph::Invoke() {
auto status = InvokeImpl();
+#ifdef TF_LITE_TENSORFLOW_PROFILER
telemetry::TelemetryReportEvent(&context_, "Invoke", status);
+#endif //TFLITE_TENSORFLOW_PROFILER
return status;
}
TfLiteStatus Subgraph::InvokeImpl() {
@@ -1966,7 +1968,9 @@
TfLiteStatus Subgraph::ModifyGraphWithDelegate(TfLiteDelegate* delegate) {
auto status = ModifyGraphWithDelegateImpl(delegate);
+#ifdef TF_LITE_TENSORFLOW_PROFILER
telemetry::TelemetryReportEvent(&context_, "ModifyGraphWithDelegate", status);
+#endif //TFLITE_TENSORFLOW_PROFILER
return status;
}
EOP

def install
inreplace "tensorflow/lite/c/CMakeLists.txt", /common\.c$/, "common.cc"
mkdir "builddir"
if OS.linux?
# Utility needed for static repack
(buildpath/"flatten-archives.sh").write <<~EOQ
#!/usr/bin/env bash
if [[ $# -lt 2 ]]; then
echo "Usage: $0 out.a in1.a in2.a ... inN.a"
exit 1
fi
system "cmake", "-Bbuilddir", "-Stensorflow/lite/c"
system "cmake", "--build", "builddir", "-j16"
out_file="$1"
shift
lib.install Dir["builddir/libtensorflowlite_c.*"]
if ! [[ "$out_file" =~ \.a$ ]]; then
echo "$out_file must be an archive (.a) file"
exit 1
fi
mkdir -p `dirname "$out_file"`
for src in "$@"; do
if ! [[ "$src" =~ \.a$ ]]; then
echo "input $src is not an archive (.a) file"
exit 1
fi
declare -A members
for member in `ar t $src`; do
((members[$member]++))
ar xN ${members[$member]} "$src" "$member"
ar q "$out_file" "$member"
rm "$member"
done
unset members
done
ranlib $out_file
EOQ

chmod 0755, "flatten-archives.sh"

# static build
mkdir "builddir_static"
system "cmake", "-DTFLITE_C_BUILD_SHARED_LIBS=OFF", "-Bbuilddir_static", "-Stensorflow/lite/c"
system "cmake", "--build", "builddir_static", "-j8"

# repack static build into complete archive
system "bash", "-c",
"find builddir_static/ -name '*.a' -print0 | xargs -0 ./flatten-archives.sh libtensorflowlite_c.a"
lib.install "libtensorflowlite_c.a"
end
# end linux-only static build

# dynamic build
mkdir "builddir_dynamic"
system "cmake", "-Bbuilddir_dynamic", "-Stensorflow/lite/c"
system "cmake", "--build", "builddir_dynamic", "-j8"
lib.install Dir["builddir_dynamic/libtensorflowlite_c.*"]

mkdir_p include/"tensorflow/lite/c"
mkdir_p include/"tensorflow/lite/core/c"

include.install "tensorflow/lite/builtin_ops.h" => "tensorflow/lite/builtin_ops.h"
include.install "tensorflow/lite/c/c_api.h" => "tensorflow/lite/c/c_api.h"
include.install "tensorflow/lite/c/c_api_experimental.h" => "tensorflow/lite/c/c_api_experimental.h"
include.install "tensorflow/lite/c/c_api_for_testing.h" => "tensorflow/lite/c/c_api_for_testing.h"
include.install "tensorflow/lite/c/c_api_types.h" => "tensorflow/lite/c/c_api_types.h"
include.install "tensorflow/lite/c/common.h" => "tensorflow/lite/c/common.h"
include.install "tensorflow/lite/core/c/c_api.h" => "tensorflow/lite/core/c/c_api.h"
include.install "tensorflow/lite/core/c/c_api_types.h" => "tensorflow/lite/core/c/c_api_types.h"
include.install "tensorflow/lite/core/c/c_api_experimental.h" => "tensorflow/lite/core/c/c_api_experimental.h"
include.install "tensorflow/lite/core/c/common.h" => "tensorflow/lite/core/c/common.h"
end
end
2 changes: 1 addition & 1 deletion Formula/viam-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ViamServer < Formula
depends_on "pkg-config" => :build
depends_on "node@18" => :build
depends_on "ffmpeg"
depends_on "nlopt"
depends_on "nlopt-static"
depends_on "opus"
depends_on "tensorflowlite"
depends_on "x264"
Expand Down

0 comments on commit f99ddab

Please sign in to comment.