Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cli/cli_args.zig
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pub const BuildArgs = struct {
target: ?[]const u8 = null, // the target to compile for (e.g., x64musl, x64glibc)
output: ?[]const u8 = null, // the path where the output binary should be created
debug: bool = false, // include debug information in the output binary
keep_temp: bool = false, // do not delete temporary directories created during build
allow_errors: bool = false, // allow building even if there are type errors
verbose: bool = false, // enable verbose output including cache statistics
timings: bool = false, // always show the per-phase timing breakdown
Expand Down Expand Up @@ -407,6 +408,7 @@ fn parseBuild(args: []const []const u8) CliArgs {
var target: ?[]const u8 = null;
var output: ?[]const u8 = null;
var debug: bool = false;
var keep_temp: bool = false;
var allow_errors: bool = false;
var verbose: bool = false;
var timings: bool = false;
Expand All @@ -432,6 +434,7 @@ fn parseBuild(args: []const []const u8) CliArgs {
\\ --opt=<opt> Build mode: speed (default LLVM optimized), size (LLVM optimized for binary size), dev (native dev backend), or interpreter (embedded interpreter backend)
\\ --target=<target> Target to compile for (e.g., x64musl, x64glibc, arm64musl). Defaults to native target with musl for static linking
\\ --debug Include debug information in the output binary
\\ --keep-temp Keep all temporary directories created during build
\\ --allow-errors Allow building even if there are type errors (warnings are always allowed)
\\ --verbose Enable verbose output including cache statistics
\\ --timings Show how long each compilation phase took (shown automatically when a build is slow)
Expand Down Expand Up @@ -472,6 +475,8 @@ fn parseBuild(args: []const []const u8) CliArgs {
}
} else if (mem.eql(u8, arg, "--debug")) {
debug = true;
} else if (mem.eql(u8, arg, "--keep-temp")) {
keep_temp = true;
} else if (mem.eql(u8, arg, "--allow-errors")) {
allow_errors = true;
} else if (mem.startsWith(u8, arg, "--wasm-memory")) {
Expand Down Expand Up @@ -529,7 +534,7 @@ fn parseBuild(args: []const []const u8) CliArgs {
path = arg;
}
}
return CliArgs{ .build = BuildArgs{ .path = path orelse "main.roc", .opt = opt, .target = target, .output = output, .debug = debug, .allow_errors = allow_errors, .verbose = verbose, .timings = timings, .no_cache = no_cache, .watch = watch, .watch_inputs_file = watch_inputs_file, .max_threads = max_threads, .wasm_memory = wasm_memory, .wasm_stack_size = wasm_stack_size, .resolve_limits = resolve_limits } };
return CliArgs{ .build = BuildArgs{ .path = path orelse "main.roc", .opt = opt, .target = target, .output = output, .debug = debug, .keep_temp = keep_temp, .allow_errors = allow_errors, .verbose = verbose, .timings = timings, .no_cache = no_cache, .watch = watch, .watch_inputs_file = watch_inputs_file, .max_threads = max_threads, .wasm_memory = wasm_memory, .wasm_stack_size = wasm_stack_size, .resolve_limits = resolve_limits } };
}

fn parseBundle(alloc: mem.Allocator, args: []const []const u8) std.mem.Allocator.Error!CliArgs {
Expand Down
22 changes: 20 additions & 2 deletions src/cli/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6719,7 +6719,16 @@ fn rocBuildDefaultApp(ctx: *CliCtx, args: cli_args.BuildArgs, original_source: [
const temp_dir = createUniqueTempDir(ctx) catch |err| {
return ctx.fail(.{ .temp_dir_failed = .{ .err = err } });
};
defer std.Io.Dir.cwd().deleteTree(ctx.io.std_io, temp_dir) catch {};

if (args.keep_temp) {
const palette = reporting.ColorUtils.getPaletteForConfig(reporting.ReportingConfig.initColorTerminal());
const config = reporting.ReportingConfig.initColorTerminal();
const headline = try std.fmt.allocPrint(ctx.arena, "Kept temporary directory: {s}.", .{temp_dir});
var report = try reporting.Report.init(ctx.arena, "Kept Temporary Directory", headline, .warning);
defer report.deinit();
reporting.renderReportToTerminal(&report, ctx.io.stderr(), palette, config) catch {};
}
defer if (!args.keep_temp) std.Io.Dir.cwd().deleteTree(ctx.io.std_io, temp_dir) catch {};

const platform_dir = try std.fs.path.join(ctx.arena, &.{ temp_dir, ".roc_echo_platform" });
try std.Io.Dir.cwd().createDirPath(ctx.io.std_io, platform_dir);
Expand Down Expand Up @@ -8285,7 +8294,16 @@ fn rocBuildLlvm(ctx: *CliCtx, args: cli_args.BuildArgs) CliMainError!void {
enable_default_platform_runtime,
args.synthetic_default_platform,
);
defer std.Io.Dir.cwd().deleteTree(ctx.io.std_io, app_object.artifact_dir) catch {};

if (args.keep_temp) {
const palette = reporting.ColorUtils.getPaletteForConfig(reporting.ReportingConfig.initColorTerminal());
const config = reporting.ReportingConfig.initColorTerminal();
const headline = try std.fmt.allocPrint(ctx.arena, "Kept temporary directory: {s}.", .{app_object.artifact_dir});
var report = try reporting.Report.init(ctx.arena, "Kept Temporary Directory", headline, .warning);
defer report.deinit();
reporting.renderReportToTerminal(&report, ctx.io.stderr(), palette, config) catch {};
}
defer if (!args.keep_temp) std.Io.Dir.cwd().deleteTree(ctx.io.std_io, app_object.artifact_dir) catch {};

var static_data_obj_path: ?[]const u8 = null;
if (static_data_exports.len > 0) {
Expand Down