Skip to content

Conversation

@RokasPuzonas
Copy link
Contributor

Resolves #7

Here is an example for how the build.zig needs to look if you are using -fno-sys=mbedtls:

const mbedtls_dependency = b.dependency("mbedtls", .{
    .target = target,
    .optimize = optimize,
});

const libssh2_dependency = b.dependency("libssh2", .{
    .target = target,
    .optimize = optimize,
    .strip = optimize != .Debug,
    .@"crypto-backend" = .mbedtls,
});
const libssh2_artifact = libssh2_dependency.artifact("ssh2");
 
// This line is very important, it's important to link mbedtls with libssh2. Not with root_module.
// This is a very easy mistake to make.
libssh2_artifact.linkLibrary(mbedtls_dependency.artifact("mbedtls"));

root_module.linkLibrary(libssh2_artifact);

const exe = b.addExecutable(.{
    .name = "resource_tracker",
    .root_module = root_module
});

@RokasPuzonas
Copy link
Contributor Author

Sorry for coming back to this after so long. After playing around with these, I changed my mind. I don't think using the system integration API in a library is a good idea.

Reasons:

  1. A user of this library can't specify if they prefer using a system library or not in build.zig (i.e. in the arguments for b.dependency). It's a CLI only option.
  2. Because it's a CLI only option, this made using the library a bit clunky, I couldn't just run zig build and it would build my application according to my preferences, I was forced to use zig build -fno-sys=mbedtls.
  3. If a library uses the system integration API, it pollutes the build options for everybody downstream that uses the library. The user won't be able to have their own "mbedtls" system integration option.

Solution: Provide an option for skipping the .linkSystemLibrary calls like .link-system-crypto-backend which would be a true/false value. Then the user of the library can decide if they want to use b.systemIntegrationOption.

This solution was inspired by the sokol-zig and how it handles integrating with imgui using the .with_sokol_imgui where you need to "Bring your own cimgui".

@RokasPuzonas RokasPuzonas changed the title Use system integration options API Add option to skip linking against system libraries Jan 10, 2026
Copy link
Contributor

@hamptokr hamptokr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Agreed this seems like a better approach!

@hamptokr hamptokr merged commit 65a7697 into allyourcodebase:main Jan 15, 2026
4 checks passed
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.

Allow not linking against crypto system libraries

2 participants