build.zig 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const std = @import("std");
  2. const Builder = std.build.Builder;
  3. const Pkg = std.build.Pkg;
  4. fn checkPackage(indexFile: []const u8, url: []const u8, ) void {
  5. std.fs.cwd().access(indexFile, std.fs.File.OpenFlags { .read = true }) catch |err| {
  6. std.debug.warn("Error: library index file '{}' does not exist\n", .{indexFile});
  7. std.debug.warn(" Run the following to clone it:\n", .{});
  8. std.debug.warn(" git clone {} {}\n", .{url, std.fs.path.dirname(indexFile)});
  9. std.os.exit(1);
  10. };
  11. }
  12. pub fn build(b: *Builder) void {
  13. const zigetRepo = "../ziget";
  14. //
  15. // TODO: figure out how to use ziget's build.zig file
  16. //
  17. const zigetIndexFile = zigetRepo ++ "/ziget.zig";
  18. const sslIndexFile = zigetRepo ++ "/openssl/ssl.zig";
  19. //const sslIndexFile = zigetRepo ++ "/nossl/ssl.zig";
  20. checkPackage(zigetIndexFile, "https://github.com/marler8997/ziget");
  21. // Standard target options allows the person running `zig build` to choose
  22. // what target to build for. Here we do not override the defaults, which
  23. // means any target is allowed, and the default is native. Other options
  24. // for restricting supported target set are available.
  25. const target = b.standardTargetOptions(.{});
  26. // Standard release options allow the person running `zig build` to select
  27. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
  28. const mode = b.standardReleaseOptions();
  29. const sslPkg = Pkg { .name = "ssl", .path = sslIndexFile };
  30. const zigetPkg = Pkg {
  31. .name = "ziget",
  32. .path = zigetIndexFile,
  33. .dependencies = &[_]Pkg {sslPkg},
  34. };
  35. const exe = b.addExecutable("zigup", "zigup.zig");
  36. exe.setTarget(target);
  37. exe.setBuildMode(mode);
  38. exe.addPackage(zigetPkg);
  39. // these libraries are required for openssl
  40. exe.linkSystemLibrary("c");
  41. exe.linkSystemLibrary("ssl");
  42. exe.linkSystemLibrary("crypto");
  43. exe.install();
  44. const run_cmd = exe.run();
  45. run_cmd.step.dependOn(b.getInstallStep());
  46. const run_step = b.step("run", "Run the app");
  47. run_step.dependOn(&run_cmd.step);
  48. }