#system library static linking

1 messages · Page 1 of 1 (latest)

lyric haven
#

Is it safe to statically link x11 like this if I only use it for input handling (these libs that I link before x11 are dependencies that are needed to compile it statically) ? I also want it to be distro agnostic.

const std = @import("std");

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

    const some_mod = b.addModule("somelib", .{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    some_mod.linkSystemLibrary("c", .{});
    some_mod.linkSystemLibrary("Xdmcp", .{ .preferred_link_mode = .static });
    some_mod.linkSystemLibrary("Xau", .{ .preferred_link_mode = .static });
    some_mod.linkSystemLibrary("xcb", .{ .preferred_link_mode = .static });
    some_mod.linkSystemLibrary("X11", .{ .preferred_link_mode = .static });
    const options = b.addOptions();
    const options_mod = options.createModule();
    some_mod.addImport("build_options", options_mod);

    const example = b.addExecutable(.{
        .name = "example",
        .root_source_file = b.path("example/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    example.root_module.addImport("somelib", some_mod);
    const example_run = b.addRunArtifact(example);
    const example_step = b.step("example", "Run example");
    example_step.dependOn(&example_run.step);

    const lib_unit_tests = b.addTest(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_lib_unit_tests.step);
}
still torrent
#

X11 is okay to static link afaik