This commit is contained in:
agra
2026-03-02 09:49:43 +02:00
parent f763765ea2
commit ba9c4d69ce
6 changed files with 460 additions and 103 deletions

View File

@@ -23,6 +23,7 @@ pub fn main(init: std.process.Init) !void {
var input_path: ?[]const u8 = null;
var target_config = sx.target.TargetConfig{};
var lib_paths = std.ArrayList([]const u8).empty;
var link_flags = std.ArrayList([]const u8).empty;
var show_timing: bool = false;
var explicit_opt: bool = false;
var enable_cache: bool = false;
@@ -70,6 +71,10 @@ pub fn main(init: std.process.Init) !void {
if (i >= args.len) { std.debug.print("error: -L requires a value\n", .{}); return; }
try lib_paths.append(allocator, args[i]);
}
} else if (std.mem.eql(u8, arg, "--lflags")) {
i += 1;
if (i >= args.len) { std.debug.print("error: --lflags requires a value\n", .{}); return; }
try link_flags.append(allocator, args[i]);
} else if (!std.mem.startsWith(u8, arg, "-")) {
input_path = arg;
} else {
@@ -79,6 +84,7 @@ pub fn main(init: std.process.Init) !void {
}
target_config.lib_paths = try lib_paths.toOwnedSlice(allocator);
target_config.extra_link_flags = try link_flags.toOwnedSlice(allocator);
const path = input_path orelse {
printUsage();
@@ -86,7 +92,13 @@ pub fn main(init: std.process.Init) !void {
};
if (std.mem.eql(u8, command, "build")) {
const output_name = target_config.output_path orelse deriveOutputName(path);
const output_name = target_config.output_path orelse blk: {
const base = deriveOutputName(path);
if (target_config.isEmscripten()) {
break :blk try std.fmt.allocPrint(allocator, "{s}.html", .{base});
}
break :blk base;
};
compile(allocator, io, path, output_name, target_config, show_timing, enable_cache) catch return;
std.debug.print("compiled: {s}\n", .{output_name});
} else if (std.mem.eql(u8, command, "ir")) {
@@ -96,6 +108,10 @@ pub fn main(init: std.process.Init) !void {
} else if (std.mem.eql(u8, command, "asm")) {
emitAsm(allocator, io, path, target_config) catch return;
} else if (std.mem.eql(u8, command, "run")) {
if (target_config.isWasm()) {
std.debug.print("error: 'run' is not supported for wasm targets. Use 'build' instead.\n", .{});
return;
}
// Default to -O0 for run (faster compile) unless user explicitly set --opt
if (!explicit_opt) target_config.opt_level = .none;
var timer = Timing.init(show_timing);
@@ -238,6 +254,7 @@ fn printUsage() void {
\\ -L <path> Library search path (repeatable)
\\ --linker <cmd> Linker command (default: cc)
\\ --sysroot <path> Sysroot for cross-compilation
\\ --lflags <flag> Extra linker flag (repeatable, e.g. --lflags -sUSE_SDL=2)
\\ --cache Enable build caching
\\ --time Show compilation timing breakdown
\\