Skip to content

Commit

Permalink
Merge pull request #95 from kubkon/macho-relocatable
Browse files Browse the repository at this point in the history
macho: implement -r mode
  • Loading branch information
kubkon authored Jan 6, 2024
2 parents 3e692d9 + 832770e commit 193fcbf
Show file tree
Hide file tree
Showing 14 changed files with 1,441 additions and 322 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
Loading

0 comments on commit 193fcbf

Please sign in to comment.