Module: Toy::FFIManifest
- Defined in:
- lib/toy/ffi_manifest.rb
Constant Summary collapse
- BACKENDS =
Per-backend link recipe. Order matters (matches what tinynn.rb / _cuda / _metal ship today).
{ cpu: { ffi_file: "tinynn.rb", # Relative paths from toy's repo root that get absolutized: ld_paths: [ ".", # toy root (libtinynn_ggml.a is in tinynn/ — kept for legacy compat) "tinynn", # libtinynn_ggml.a "vendor/ggml/build/src", # libggml.a, libggml-base.a, libggml-cpu.a ], # Trailing flags that go after the -L paths. tail: "-Wno-int-conversion", }, cuda: { ffi_file: "tinynn_cuda.rb", ld_paths: [ ".", "tinynn", "vendor/ggml/build-cuda/src", "vendor/ggml/build-cuda/src/ggml-cuda", ], # CUDA libdir is system-absolute, NOT relative to TOY_SRC. # Default is the common /usr/local/cuda location; consumers can # override via CUDA_DIR. tail: "-Wno-int-conversion", extra_ld_paths_abs: ["/usr/local/cuda/lib64"], extra_ld_paths_env: "CUDA_DIR_LIB", }, metal: { ffi_file: "tinynn_metal.rb", ld_paths: [ ".", "tinynn", "vendor/ggml/build-metal/src", "vendor/ggml/build-metal/src/ggml-cpu", "vendor/ggml/build-metal/src/ggml-metal", ], tail: "-Wno-int-conversion -framework Foundation -framework Metal -framework MetalKit", }, }.freeze
Class Method Summary collapse
-
.absolute_cflags(backend_key, toy_src) ⇒ Object
Build the absolute ffi_cflags string for ‘backend_key` against a caller-supplied TOY_SRC directory.
Class Method Details
.absolute_cflags(backend_key, toy_src) ⇒ Object
Build the absolute ffi_cflags string for ‘backend_key` against a caller-supplied TOY_SRC directory. Honors any per-backend env overrides (e.g. CUDA_DIR_LIB).
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/toy/ffi_manifest.rb', line 73 def self.absolute_cflags(backend_key, toy_src) cfg = BACKENDS.fetch(backend_key) parts = cfg[:ld_paths].map { |rel| "-L#{File.join(toy_src, rel)}" } if cfg[:extra_ld_paths_abs] abs_extra = cfg[:extra_ld_paths_env] ? ENV[cfg[:extra_ld_paths_env]] : nil parts.concat(abs_extra ? [abs_extra].map { |p| "-L#{p}" } : cfg[:extra_ld_paths_abs].map { |p| "-L#{p}" }) end parts << cfg[:tail] parts.join(" ") end |