feat: hide json serialization behind compiler flag -Djson

This commit is contained in:
Fernando Araoz 2025-01-22 19:42:44 -05:00
parent 32aa8b1de7
commit e584ecd8a2
2 changed files with 14 additions and 5 deletions

View File

@ -5,10 +5,13 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
// Create options module for tracing // Create options module for conditional compilation
const executionTracing = b.option(bool, "tracing", "enable execution tracing") orelse false; const executionTracing = b.option(bool, "tracing", "enable execution tracing") orelse false;
const json_serialization = b.option(bool, "json", "enable JSON serialization of the compiler outputs") orelse false;
const options = b.addOptions(); const options = b.addOptions();
options.addOption(bool, "tracing", executionTracing); options.addOption(bool, "tracing", executionTracing);
options.addOption(bool, "json", json_serialization);
// Create the options module that will be shared // Create the options module that will be shared
const options_module = options.createModule(); const options_module = options.createModule();

View File

@ -5,7 +5,9 @@ const errors = @import("errors");
const cli = @import("cli.zig"); const cli = @import("cli.zig");
const tracing = @import("config").tracing; const config = @import("config");
const tracing = config.tracing;
const json = config.json;
const thp_version: []const u8 = "0.0.1"; const thp_version: []const u8 = "0.0.1";
@ -18,12 +20,16 @@ fn repl() !void {
var args = std.process.args(); var args = std.process.args();
defer args.deinit(); defer args.deinit();
// If compiling for JSON serialization, enable the binary `lex` command
// ignore executable // ignore executable
_ = args.next(); _ = args.next();
if (args.next()) |arg| { if (args.next()) |arg| {
if (std.mem.eql(u8, "lex", arg)) { if (json) {
try cli.tokenize_to_json(); if (std.mem.eql(u8, "lex", arg)) {
return; try cli.tokenize_to_json();
return;
}
} }
} }