Skip to content

Conversation

rjkroege
Copy link

@rjkroege rjkroege commented May 5, 2025

This PR contains a number of changes with two primary goals:

  • Support macos build hosts for macos and linux targets.
  • Compile Go libraries and use them for Zig linkage

Example of Library

Fragment from the build.zig

    // Create a Zig executable that calls Go code.
    const driver_exe = b.addExecutable(.{
        .name = "zigcallsgo",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    // Build the Go library from package in `go-lib`.
    const go_lib = go.addLibrary(b, .{
        .name = "libhtmlescaper.a",
        .target = target,
        .optimize = optimize,
        .package_path = b.path("go-lib"),
    });

    driver_exe.addIncludePath(go_lib.getIncludePath());
    driver_exe.addObjectFile(go_lib.getEmittedBin());
    // NB: Go runtime requires arm-linux-gnueabihf to not crash on arm target.
    driver_exe.linkLibC();

Changes

  • Changes to build for 0.14
  • Sufficient for building a simple Go program
  • Changes for CGO support on MacOS
  • Support building Go libraries
  • Restore static linking support
  • Fixed a typo

0.14 needs enum names. Add this.
Mac's requirement for the native resolver adds some complexity.
Support Mac CGO builds by using the native platforn on Mac. Remove
some unnecessary code.
Add the necessary code to build libraries in Go lang and an accessor
for the include path.
I'd deleted static linking support in error. Restore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants