diff options
author | Nguyễn Gia Phong <cnx@loang.net> | 2024-03-01 06:40:51 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <cnx@loang.net> | 2024-03-01 06:40:51 +0900 |
commit | 474ede369ba155f12a7b2c3b157c11fd4d58baca (patch) | |
tree | 01275f6f34e8f39d2ffc920fb4fe8d7ee46287c5 | |
parent | 63ac01380080200d38f16795a64b62a4f2cd680a (diff) | |
download | roux-474ede369ba155f12a7b2c3b157c11fd4d58baca.tar.gz |
Support macOS
-rw-r--r-- | build.zig | 6 | ||||
-rw-r--r-- | src/cimport.zig | 6 | ||||
-rw-r--r-- | src/main.zig | 29 |
3 files changed, 21 insertions, 20 deletions
diff --git a/build.zig b/build.zig index 0ac29d5..f869257 100644 --- a/build.zig +++ b/build.zig @@ -48,8 +48,10 @@ pub fn build(b: *Build) !void { run_tests.addArgs(&.{ "-z", b.zig_exe }); run_tests.addArgs(&.{ "-t", try target.zigTriple(b.allocator) }); switch (getExternalExecutor(tests.target_info, bin.target_info, .{})) { - .qemu => |emulator| run_tests.addArgs(&.{ "-e", emulator }), - else => {}, + .native => {}, + .qemu, .darling => |emulator| run_tests.addArgs(&.{ "-e", emulator }), + .bad_os_or_cpu => return error.BadOsOrCpu, + else => unreachable, } if (b.args) |args| run_tests.addArgs(args); diff --git a/src/cimport.zig b/src/cimport.zig index 65666b2..19416af 100644 --- a/src/cimport.zig +++ b/src/cimport.zig @@ -1,8 +1,4 @@ -pub const FILE = stdio.FILE; -pub const fclose = stdio.fclose; -pub const fopen = stdio.fopen; -pub const fputs = stdio.fputs; -pub const stdio = @cImport(@cInclude("stdio.h")); +pub const FILE = @import("std").c.FILE; pub const bits = u64; diff --git a/src/main.zig b/src/main.zig index fbbb8b1..993c0a1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,6 +9,8 @@ const c = @import("cimport.zig"); const cWriter = std.io.cWriter; const eql = std.mem.eql; const exit = std.os.exit; +const fclose = std.c.fclose; +const fopen = std.c.fopen; const getStdErr = std.io.getStdErr; const getStdOut = std.io.getStdOut; const isAlphabetic = std.ascii.isAlphabetic; @@ -159,8 +161,8 @@ const Parser = struct { c.T = default_target.*; var args = try argsWithAllocator(allocator); var dbg = false; - var out: *c.FILE = c.stdio.stdout.?; - errdefer _ = c.fclose(out); + var out = fopen("/dev/stdout", "w").?; + errdefer _ = fclose(out); const prog = args.next().?; while (args.next()) |arg| { @@ -181,8 +183,8 @@ const Parser = struct { } }, 'o' => { - _ = c.fclose(out); - out = c.fopen(value, "w") // TODO: explicit OpenError + _ = fclose(out); + out = fopen(value, "w") // TODO: explicit OpenError orelse try die("cannot open '{s}'\n", .{ value }, 1); }, 't' => { @@ -200,16 +202,18 @@ const Parser = struct { } } - if (dbg) - _ = c.fclose(out); - return .{ .dbg = dbg, .out = if (dbg) c.stdio.stderr.? else out }; + if (dbg) { + _ = fclose(out); + out = fopen("/dev/stdout", "w").?; + } + return .{ .dbg = dbg, .out = out }; } /// Finish writing to output file. pub fn deinit(self: Parser) void { if (!self.dbg) c.T.emitfin(self.out); - _ = c.fclose(self.out); + _ = fclose(self.out); } /// Skip emitting data in debug mode. @@ -233,6 +237,7 @@ pub fn main() !void { var read_stdin = true; var args = try argsWithAllocator(allocator); _ = args.next().?; + const stdin = fopen("/dev/stdin", "r").?; while (args.next()) |arg| { if (arg[0] == '-' and arg.len > 1) { // must be -d, -o or -t @@ -241,13 +246,11 @@ pub fn main() !void { continue; } read_stdin = false; - const in_file = if (eql(u8, arg, "-")) - c.stdio.stdin.? - else c.fopen(arg, "r") // TODO: explicit OpenError + const in_file = if (eql(u8, arg, "-")) stdin else fopen(arg, "r") orelse try die("cannot open '{s}'\n", .{ arg }, 1); - defer _ = c.fclose(in_file); + defer _ = fclose(in_file); parser.parse(in_file, arg.ptr); } if (read_stdin) - parser.parse(c.stdio.stdin.?, "-"); + parser.parse(stdin, "-"); } |