build.zig 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const std = @import("std");
  2. // Zig Version: 0.11.0-dev.3379+629f0d23b
  3. pub fn build(b: *std.build.Builder) void {
  4. const target = b.standardTargetOptions(.{});
  5. const optimize = b.standardOptimizeOption(.{});
  6. const lib = b.addStaticLibrary(.{
  7. .name = "llama",
  8. .target = target,
  9. .optimize = optimize,
  10. });
  11. lib.linkLibC();
  12. lib.linkLibCpp();
  13. lib.addIncludePath(".");
  14. lib.addIncludePath("./examples");
  15. lib.addCSourceFiles(&.{
  16. "ggml.c",
  17. }, &.{"-std=c11"});
  18. lib.addCSourceFiles(&.{
  19. "llama.cpp",
  20. }, &.{"-std=c++11"});
  21. b.installArtifact(lib);
  22. const examples = .{
  23. "main",
  24. "baby-llama",
  25. "embedding",
  26. // "metal",
  27. "perplexity",
  28. "quantize",
  29. "quantize-stats",
  30. "save-load-state",
  31. // "server",
  32. "simple",
  33. "train-text-from-scratch",
  34. };
  35. inline for (examples) |example_name| {
  36. const exe = b.addExecutable(.{
  37. .name = example_name,
  38. .target = target,
  39. .optimize = optimize,
  40. });
  41. exe.addIncludePath(".");
  42. exe.addIncludePath("./examples");
  43. exe.addCSourceFiles(&.{
  44. std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{example_name, example_name}),
  45. "examples/common.cpp",
  46. }, &.{"-std=c++11"});
  47. exe.linkLibrary(lib);
  48. b.installArtifact(exe);
  49. const run_cmd = b.addRunArtifact(exe);
  50. run_cmd.step.dependOn(b.getInstallStep());
  51. if (b.args) |args| run_cmd.addArgs(args);
  52. const run_step = b.step("run_" ++ example_name, "Run the app");
  53. run_step.dependOn(&run_cmd.step);
  54. }
  55. }