| 1 | const builtin = @import("builtin"); |
| 2 | |
| 3 | const std = @import("std"); |
| 4 | const Io = std.Io; |
| 5 | const Allocator = std.mem.Allocator; |
| 6 | const EnvVar = std.zig.EnvVar; |
| 7 | const fatal = std.process.fatal; |
| 8 | |
| 9 | const build_options = @import("build_options"); |
| 10 | const Compilation = @import("Compilation.zig"); |
| 11 | |
| 12 | pub fn cmdEnv( |
| 13 | arena: Allocator, |
| 14 | out: *std.Io.Writer, |
| 15 | host: *const std.Target, |
| 16 | environ_map: *std.process.Environ.Map, |
| 17 | dirs: *const std.zig.Directories, |
| 18 | self_exe_path: []const u8, |
| 19 | ) !void { |
| 20 | const zig_lib_dir = dirs.zig_lib.path orelse ""; |
| 21 | const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"}); |
| 22 | const global_cache_dir = dirs.global_cache.path orelse ""; |
| 23 | const triple = try host.zigTriple(arena); |
| 24 | |
| 25 | var serializer: std.zon.Serializer = .{ .writer = out }; |
| 26 | var root = try serializer.beginStruct(.{}); |
| 27 | |
| 28 | try root.field("zig_exe", self_exe_path, .{}); |
| 29 | try root.field("lib_dir", zig_lib_dir, .{}); |
| 30 | try root.field("std_dir", zig_std_dir, .{}); |
| 31 | try root.field("global_cache_dir", global_cache_dir, .{}); |
| 32 | try root.field("version", build_options.version, .{}); |
| 33 | try root.field("target", triple, .{}); |
| 34 | var env = try root.beginStructField("env", .{}); |
| 35 | inline for (@typeInfo(EnvVar).@"enum".field_names) |field_name| { |
| 36 | try env.field(field_name, @field(EnvVar, field_name).get(environ_map), .{}); |
| 37 | } |
| 38 | try env.end(); |
| 39 | try root.end(); |
| 40 | |
| 41 | try out.writeByte('\n'); |
| 42 | } |