Class: Toy::Core::CLI::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/toy/core/cli/install.rb

Constant Summary collapse

FORMAT =
"toy/install-v1"
GGML_A =

CPU artifacts — built on every platform.

"vendor/ggml/build/src/libggml.a"
TINYNN_A =
"tinynn/libtinynn_ggml.a"
GGML_METAL_A =

Metal artifacts — built on Darwin only. The Metal libggml.a is a side-effect of ‘make setup` on Darwin; the Metal tinynn shim is a separate target that install must request explicitly, else example_inference_metal can’t link on a fresh Mac build.

"vendor/ggml/build-metal/src/libggml.a"
TINYNN_METAL_A =
"tinynn/libtinynn_ggml_metal.a"
DARWIN =
!!(RbConfig::CONFIG["host_os"] =~ /darwin/i)

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Install

Returns a new instance of Install.



59
60
61
62
# File 'lib/toy/core/cli/install.rb', line 59

def initialize(argv)
  @argv = argv
  @json = false
end

Instance Method Details

#runObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/toy/core/cli/install.rb', line 64

def run
  return EXIT_BAD_INPUT unless parse_args

  root = locate_root
  unless root
    return fail_out(
      "could not locate toy's install root. Set TOY_HOME to a toy " \
      "checkout (one with a Makefile + tinynn/tinynn_ggml.c), or run " \
      "install from inside the toy source tree. A gem-installed toy " \
      "does not yet ship a buildable backend (see packaging note)."
    )
  end

  artifacts = expected_artifacts(root)
  missing = artifacts.reject { |a| usable?(a[:path]) }

  if missing.empty?
    return report_ready(root, artifacts, built: false)
  end

  # Not prebuilt. Can we build here?
  unless buildable?(root)
    names = missing.map { |a| a[:relpath] }.join(", ")
    return fail_out(
      "no usable backend at #{root}: missing #{names}, and no " \
      "Makefile + tinynn/tinynn_ggml.c to build from. This is the " \
      "gem-install gap — point TOY_HOME at a dev checkout."
    )
  end

  build_result = build(root)
  return build_result if build_result.is_a?(Integer)

  still_missing = artifacts.reject { |a| usable?(a[:path]) }
  if still_missing.empty?
    report_ready(root, artifacts, built: true)
  else
    names = still_missing.map { |a| a[:relpath] }.join(", ")
    fail_out("build completed but backend artifacts are still missing at #{root}: #{names}")
  end
end