MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at type-hints-typescript 78 lines 2.6 kB view raw
1const std = @import("std"); 2 3fn getEnv(key: []const u8) ?[]const u8 { 4 return std.process.getEnvVarOwned(std.heap.page_allocator, key) catch null; 5} 6 7fn darwinMinVersion(os_tag: ?std.Target.Os.Tag) ?std.Target.Query.OsVersion { 8 const tag = os_tag orelse return null; 9 if (tag != .macos) return null; 10 return .{ .semver = .{ .major = 15, .minor = 0, .patch = 0 } }; 11} 12 13pub fn build(b: *std.Build) void { 14 const resolved_target = blk: { 15 const target_str = getEnv("PKG_TARGET") orelse break :blk b.standardTargetOptions(.{}); 16 defer std.heap.page_allocator.free(target_str); 17 var it = std.mem.splitScalar(u8, target_str, '-'); 18 19 const cpu_arch = if (it.next()) |a| 20 std.meta.stringToEnum(std.Target.Cpu.Arch, a) else null; 21 22 const os_tag = if (it.next()) |o| blk2: { 23 if (std.mem.eql(u8, o, "darwin")) break :blk2 std.Target.Os.Tag.macos; 24 break :blk2 std.meta.stringToEnum(std.Target.Os.Tag, o); 25 } else null; 26 27 std.debug.print("[zig.build] cpu_arch: {?}\n", .{cpu_arch}); 28 std.debug.print("[zig.build] os_tag: {?}\n", .{os_tag}); 29 30 break :blk b.resolveTargetQuery(.{ 31 .cpu_arch = cpu_arch, 32 .os_tag = os_tag, 33 .os_version_min = darwinMinVersion(os_tag), 34 .cpu_model = .baseline, 35 }); 36 }; 37 38 const lmdb_include = getEnv("LMDB_INCLUDE"); 39 const zlib_include = getEnv("ZLIB_INCLUDE"); 40 const libuv_include = getEnv("LIBUV_INCLUDE"); 41 const yyjson_include = getEnv("YYJSON_INCLUDE"); 42 43 const lib = b.addLibrary(.{ 44 .name = "pkg", 45 .root_module = b.createModule(.{ 46 .root_source_file = b.path("root.zig"), 47 .target = resolved_target, 48 .optimize = .ReleaseFast, 49 .link_libc = true, 50 .link_libcpp = true, 51 .omit_frame_pointer = true, 52 .unwind_tables = .none, 53 .strip = true, 54 }), 55 }); 56 57 lib.use_llvm = true; 58 if (!resolved_target.result.os.tag.isDarwin()) lib.use_lld = true; 59 60 lib.addCSourceFile(.{ 61 .file = b.path("metadata.c"), 62 .flags = &.{ "-O3", "-DNDEBUG" }, 63 }); 64 65 const version = getEnv("ANT_VERSION") orelse "unknown"; 66 const options = b.addOptions(); 67 options.addOption([]const u8, "version", version); 68 69 lib.root_module.addOptions("config", options); 70 lib.root_module.addCMacro("NDEBUG", "1"); 71 72 if (lmdb_include) |p| lib.root_module.addIncludePath(.{ .cwd_relative = p }); 73 if (zlib_include) |p| lib.root_module.addIncludePath(.{ .cwd_relative = p }); 74 if (libuv_include) |p| lib.root_module.addIncludePath(.{ .cwd_relative = p }); 75 if (yyjson_include) |p| lib.root_module.addIncludePath(.{ .cwd_relative = p }); 76 77 b.installArtifact(lib); 78}