Skip to content

Commit

Permalink
macho: almost update to latest zig changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 6, 2024
1 parent ada3065 commit bf5dc67
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
36 changes: 18 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const tests = @import("test/test.zig");

const Allocator = std.mem.Allocator;

pub fn build(b: *std.Build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});

Expand All @@ -27,12 +27,12 @@ pub fn build(b: *std.Build.Builder) void {
.target = target,
.optimize = mode,
});
exe.addModule("yaml", yaml.module("yaml"));
exe.addModule("dis_x86_64", dis_x86_64.module("dis_x86_64"));
exe.root_module.addImport("yaml", yaml.module("yaml"));
exe.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
exe.linkLibC();

const exe_opts = b.addOptions();
exe.addOptions("build_options", exe_opts);
exe.root_module.addOptions("build_options", exe_opts);
exe_opts.addOption(bool, "enable_logging", enable_logging);
exe_opts.addOption(bool, "enable_tracy", enable_tracy != null);

Expand All @@ -43,17 +43,17 @@ pub fn build(b: *std.Build.Builder) void {
) catch unreachable;

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludePath(.{ .cwd_relative = tracy_path });
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
exe.linkSystemLibraryName("c++");
exe.strip = false;
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
exe.root_module.strip = false;

if (target.isWindows()) {
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("dbghelp");
exe.linkSystemLibrary("ws2_32");
}
Expand All @@ -78,11 +78,11 @@ pub fn build(b: *std.Build.Builder) void {
.optimize = mode,
});
const unit_tests_opts = b.addOptions();
unit_tests.addOptions("build_options", unit_tests_opts);
unit_tests.root_module.addOptions("build_options", unit_tests_opts);
unit_tests_opts.addOption(bool, "enable_logging", enable_logging);
unit_tests_opts.addOption(bool, "enable_tracy", enable_tracy != null);
unit_tests.addModule("yaml", yaml.module("yaml"));
unit_tests.addModule("dis_x86_64", dis_x86_64.module("dis_x86_64"));
unit_tests.root_module.addImport("yaml", yaml.module("yaml"));
unit_tests.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
unit_tests.linkLibC();

const test_step = b.step("test", "Run tests");
Expand All @@ -96,8 +96,8 @@ pub fn build(b: *std.Build.Builder) void {
}

fn addSymlinks(
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
names: []const []const u8,
) *CreateSymlinksStep {
const step = CreateSymlinksStep.create(builder, install, names);
Expand All @@ -109,13 +109,13 @@ const CreateSymlinksStep = struct {
pub const base_id = .custom;

step: std.Build.Step,
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
targets: []const []const u8,

pub fn create(
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
targets: []const []const u8,
) *CreateSymlinksStep {
const self = builder.allocator.create(CreateSymlinksStep) catch unreachable;
Expand All @@ -135,7 +135,7 @@ const CreateSymlinksStep = struct {

fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void {
const self = @fieldParentPtr(CreateSymlinksStep, "step", step);
const install_path = self.install.artifact.getOutputSource().getPath(self.builder);
const install_path = self.install.artifact.getEmittedBin().getPath(self.builder);
const rel_source = fs.path.basename(install_path);

var node = prog_node.start("creating symlinks", self.targets.len);
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

.dependencies = .{
.@"zig-yaml" = .{
.url = "https://github.com/kubkon/zig-yaml/archive/1ed4925bed911b73a189526a6ad82bd8c5c2079a.tar.gz",
.hash = "1220f56d186377820d7ad62ee03987acdd53bc24da83e8f6dff571bc7343f789f69a",
.url = "https://github.com/kubkon/zig-yaml/archive/953bf8e9a10386eb3756d3fc722df634d0d634a9.tar.gz",
.hash = "1220b174728272a3e4b38c27a37bd76e9749fad1668c24538cd8110353e87306360b",
},
.@"zig-dis-x86_64" = .{
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/a9155631990aa6d56fa06fddef304cabb94a0681.tar.gz",
.hash = "1220a4d63ba372f6b5a0fc262f863572dc119727b469f6ccf527ad91790e353bb0f0",
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/752655a8feca210880abb8f1be5acad8e7f4961a.tar.gz",
.hash = "1220591498890a10351d6cadc52cf07a594baeabd7eef7fe3e7a7f43960a3398edea",
},
},

Expand Down
6 changes: 3 additions & 3 deletions test/macho.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub fn addMachOTests(b: *Build, options: common.Options) *Step {
};
opts.macos_sdk = std.zig.system.darwin.getSdk(b.allocator, builtin.target) orelse @panic("no macOS SDK found");
opts.ios_sdk = blk: {
const target_info = std.zig.system.NativeTargetInfo.detect(.{
const target = std.zig.system.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .ios,
}) catch break :blk null;
break :blk std.zig.system.darwin.getSdk(b.allocator, target_info.target);
break :blk std.zig.system.darwin.getSdk(b.allocator, target);
};

macho_step.dependOn(testAllLoad(b, opts));
Expand Down Expand Up @@ -3325,7 +3325,7 @@ fn lipo(b: *Build) SysCmd {

fn ld(b: *Build, opts: Options) SysCmd {
const cmd = Run.create(b, "ld");
cmd.addFileSourceArg(opts.zld.file);
cmd.addFileArg(opts.zld.file);
cmd.addArg("-dynamic");
cmd.addArg("-o");
const out = cmd.addOutputFileArg("a.out");
Expand Down
32 changes: 16 additions & 16 deletions test/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn addTests(b: *Build, comp: *Compile, build_opts: struct {
error.OutOfMemory => @panic("OOM"),
};

const zld = FileSourceWithDir.fromFileSource(b, comp.getOutputSource(), "ld");
const zld = FileSourceWithDir.fromFileSource(b, comp.getEmittedBin(), "ld");

const opts: Options = .{
.zld = zld,
Expand Down Expand Up @@ -51,10 +51,10 @@ pub const Options = struct {
};

/// A system command that tracks the command itself via `cmd` Step.Run and output file
/// via `out` FileSource.
/// via `out` LazyPath.
pub const SysCmd = struct {
cmd: *Run,
out: FileSource,
out: LazyPath,

pub fn addArg(sys_cmd: SysCmd, arg: []const u8) void {
sys_cmd.cmd.addArg(arg);
Expand All @@ -64,19 +64,19 @@ pub const SysCmd = struct {
sys_cmd.cmd.addArgs(args);
}

pub fn addFileSource(sys_cmd: SysCmd, file: FileSource) void {
sys_cmd.cmd.addFileSourceArg(file);
pub fn addFileSource(sys_cmd: SysCmd, file: LazyPath) void {
sys_cmd.cmd.addFileArg(file);
}

pub fn addPrefixedFileSource(sys_cmd: SysCmd, prefix: []const u8, file: FileSource) void {
pub fn addPrefixedFileSource(sys_cmd: SysCmd, prefix: []const u8, file: LazyPath) void {
sys_cmd.cmd.addPrefixedFileSourceArg(prefix, file);
}

pub fn addDirectorySource(sys_cmd: SysCmd, dir: FileSource) void {
pub fn addDirectorySource(sys_cmd: SysCmd, dir: LazyPath) void {
sys_cmd.cmd.addDirectorySourceArg(dir);
}

pub fn addPrefixedDirectorySource(sys_cmd: SysCmd, prefix: []const u8, dir: FileSource) void {
pub fn addPrefixedDirectorySource(sys_cmd: SysCmd, prefix: []const u8, dir: LazyPath) void {
sys_cmd.cmd.addPrefixedDirectorySourceArg(prefix, dir);
}

Expand Down Expand Up @@ -118,7 +118,7 @@ pub const SysCmd = struct {
.zig => "a.zig",
.objc => "a.m",
}, bytes);
sys_cmd.cmd.addFileSourceArg(file);
sys_cmd.cmd.addFileArg(file);
}

pub inline fn addEmptyMain(sys_cmd: SysCmd) void {
Expand Down Expand Up @@ -153,7 +153,7 @@ pub const SysCmd = struct {
pub fn run(sys_cmd: SysCmd) RunSysCmd {
const b = sys_cmd.cmd.step.owner;
const r = Run.create(b, "exec");
r.addFileSourceArg(sys_cmd.out);
r.addFileArg(sys_cmd.out);
r.step.dependOn(&sys_cmd.cmd.step);
return .{ .run = r };
}
Expand Down Expand Up @@ -186,19 +186,19 @@ pub const RunSysCmd = struct {
/// This abstraction tie the full path of a file with its immediate directory to make
/// the above scenario possible.
pub const FileSourceWithDir = struct {
dir: FileSource,
file: FileSource,
dir: LazyPath,
file: LazyPath,

pub fn fromFileSource(b: *Build, in_file: FileSource, basename: []const u8) FileSourceWithDir {
pub fn fromFileSource(b: *Build, in_file: LazyPath, basename: []const u8) FileSourceWithDir {
const wf = WriteFile.create(b);
const dir = wf.getDirectorySource();
const dir = wf.getDirectory();
const file = wf.addCopyFile(in_file, basename);
return .{ .dir = dir, .file = file };
}

pub fn fromBytes(b: *Build, bytes: []const u8, basename: []const u8) FileSourceWithDir {
const wf = WriteFile.create(b);
const dir = wf.getDirectorySource();
const dir = wf.getDirectory();
const file = wf.add(basename, bytes);
return .{ .dir = dir, .file = file };
}
Expand Down Expand Up @@ -245,7 +245,7 @@ const macho = @import("macho.zig");
const Build = std.Build;
const CheckObject = Step.CheckObject;
const Compile = Step.Compile;
const FileSource = Build.FileSource;
const LazyPath = Build.LazyPath;
const Run = Step.Run;
const Step = Build.Step;
const WriteFile = Step.WriteFile;

0 comments on commit bf5dc67

Please sign in to comment.