defmodule Mix.Tasks.Torchvision.Build do @moduledoc """ Build libtorchvision.so from source. Downloads the torchvision source code matching your libtorch version and builds it via CMake. The resulting library is placed in priv/ and loaded at runtime by `ExTorch.Vision.setup!/0`. ## Requirements * cmake (>= 3.18) * A C++17 compiler (gcc >= 7 or clang >= 5) * libtorch (already installed by ExTorch) * CUDA toolkit (optional, for GPU support) ## Usage mix torchvision.build ## Options * `--force` - Rebuild even if libtorchvision.so already exists """ use Mix.Task @shortdoc "Build libtorchvision.so from source" @impl Mix.Task def run(args) do {opts, _, _} = OptionParser.parse(args, switches: [force: :boolean]) if opts[:force] do lib = ExTorch.Vision.Build.lib_path() File.rm(lib) IO.puts("Removed existing #{lib}") end # Ensure extorch is compiled first (downloads libtorch if needed) Mix.Task.run("compile", []) ExTorch.Vision.Build.ensure_built!() IO.puts("Done.") end end